bokesyo commited on
Commit
3e25657
1 Parent(s): 1fe5c53

Update modeling_minicpmv.py

Browse files
Files changed (1) hide show
  1. modeling_minicpmv.py +4 -3
modeling_minicpmv.py CHANGED
@@ -186,7 +186,7 @@ class MiniCPMV(MiniCPMVPreTrainedModel):
186
  return model_input
187
 
188
  def _process_list( # pad input tensors
189
- self, tokenizer, data_list: List[str], max_inp_length: Optional[int] = None, padding_side: str = "left"
190
  ):
191
  # pad_keys = ["input_ids"]
192
  input_tensors = []
@@ -241,7 +241,7 @@ class MiniCPMV(MiniCPMVPreTrainedModel):
241
 
242
 
243
 
244
- def pad(orig_items, max_length=None, padding_value=0, padding_side="left"):
245
  """
246
  Args:
247
  orig_items: a list of input_ids, each input_ids should be [1, length_i]
@@ -266,6 +266,7 @@ def pad(orig_items, max_length=None, padding_value=0, padding_side="left"):
266
  for i, item in enumerate(items):
267
  length = item.shape[0]
268
  if padding_side == "left":
 
269
  tensor[i, -length:] = item
270
  attention_mask[i, -length:] = 1
271
  else:
@@ -445,7 +446,7 @@ class MiniCPMVEmbedding(MiniCPMV): # MiniCPMVEmbedding -> MiniCPMV -> Ultimatel
445
  img_list = [[] for i in range(bs)]
446
  assert bs == len(img_list)
447
 
448
- model_inputs = self._process_list(tokenizer, data_list, max_inp_length, padding_side="left")
449
 
450
  if vision_hidden_states is None:
451
  pixel_values = transform_image_mp(img_list, self.transform, self.device, max_workers=8)
 
186
  return model_input
187
 
188
  def _process_list( # pad input tensors
189
+ self, tokenizer, data_list: List[str], max_inp_length: Optional[int] = None, padding_side: str = "right"
190
  ):
191
  # pad_keys = ["input_ids"]
192
  input_tensors = []
 
241
 
242
 
243
 
244
+ def pad(orig_items, max_length=None, padding_value=0, padding_side="right"):
245
  """
246
  Args:
247
  orig_items: a list of input_ids, each input_ids should be [1, length_i]
 
266
  for i, item in enumerate(items):
267
  length = item.shape[0]
268
  if padding_side == "left":
269
+ raise NotImplementedError("left padding can cause model performance degrade, see `https://huggingface.co/openbmb/MiniCPM-Llama3-V-2_5/discussions/26`")
270
  tensor[i, -length:] = item
271
  attention_mask[i, -length:] = 1
272
  else:
 
446
  img_list = [[] for i in range(bs)]
447
  assert bs == len(img_list)
448
 
449
+ model_inputs = self._process_list(tokenizer, data_list, max_inp_length, padding_side="right")
450
 
451
  if vision_hidden_states is None:
452
  pixel_values = transform_image_mp(img_list, self.transform, self.device, max_workers=8)