andrewqian123 commited on
Commit
9451981
·
verified ·
1 Parent(s): 7531a10

Update modeling_minicpmv.py

Browse files
Files changed (1) hide show
  1. modeling_minicpmv.py +10 -1
modeling_minicpmv.py CHANGED
@@ -272,7 +272,16 @@ class MiniCPMV(MiniCPMVPreTrainedModel):
272
  counter += 1
273
  batch.append(input_embeds)
274
 
275
- batch = torch.cat(batch, dim=0)
 
 
 
 
 
 
 
 
 
276
  # output_ids = self._decode(input_embeds, tokenizer, **kwargs)
277
  if stream:
278
  kwargs.pop("decode_text")
 
272
  counter += 1
273
  batch.append(input_embeds)
274
 
275
+ # batch = torch.cat(batch, dim=0)
276
+ # pad_sequence(embeddings_list, batch_first=True, padding_value=0.0)
277
+ max_length = max(tensor.shape[1] for tensor in batch)
278
+
279
+ # Step 2: Automatically pad each tensor to have the same length (L) in the last dimension
280
+ padded_tensors = [torch.nn.functional.pad(tensor, (0, max_length - tensor.shape[1])) for tensor in batch]
281
+
282
+ # Step 3: Stack the padded tensors into a single batch
283
+ batch = torch.cat(padded_tensors, dim=0)
284
+
285
  # output_ids = self._decode(input_embeds, tokenizer, **kwargs)
286
  if stream:
287
  kwargs.pop("decode_text")