myownskyW7 commited on
Commit
4d85c7e
1 Parent(s): d0ae44d

Update modeling_internlm_xcomposer2.py

Browse files

raise value error for invalid <ImageHere> prompt format

Files changed (1) hide show
  1. modeling_internlm_xcomposer2.py +4 -0
modeling_internlm_xcomposer2.py CHANGED
@@ -156,6 +156,7 @@ class InternLMXComposer2ForCausalLM(InternLM2PreTrainedModel):
156
  return_tensors='pt',
157
  padding='longest',
158
  truncation=True,
 
159
  add_special_tokens=add_special).to(self.device)
160
 
161
  targets = self.mask_human_targets(to_regress_tokens.input_ids)
@@ -175,6 +176,9 @@ class InternLMXComposer2ForCausalLM(InternLM2PreTrainedModel):
175
  parts = prompt.split('<ImageHere>')
176
  wrap_embeds, wrap_im_mask = [], []
177
  temp_len = 0
 
 
 
178
 
179
  for idx, part in enumerate(parts):
180
  if len(part) > 0:
 
156
  return_tensors='pt',
157
  padding='longest',
158
  truncation=True,
159
+ max_length=self.max_length,
160
  add_special_tokens=add_special).to(self.device)
161
 
162
  targets = self.mask_human_targets(to_regress_tokens.input_ids)
 
176
  parts = prompt.split('<ImageHere>')
177
  wrap_embeds, wrap_im_mask = [], []
178
  temp_len = 0
179
+
180
+ if len(parts) != image_nums + 1:
181
+ raise ValueError('Invalid <ImageHere> prompt format.')
182
 
183
  for idx, part in enumerate(parts):
184
  if len(part) > 0: