finalf0 commited on
Commit
3d0e971
1 Parent(s): b996e5b

Support image is None

Browse files
Files changed (1) hide show
  1. modeling_minicpmv.py +17 -14
modeling_minicpmv.py CHANGED
@@ -319,21 +319,24 @@ class MiniCPMV(MiniCPMVPreTrainedModel):
319
  content = msg["content"]
320
  assert role in ["user", "assistant"]
321
  if i == 0:
322
- assert role == "user", "The role of first msg should be user"
323
- if self.config.slice_mode:
324
- images, final_placeholder = self.get_slice_image_placeholder(
325
- image, tokenizer
326
- )
327
- content = final_placeholder + "\n" + content
328
  else:
329
- images = [image]
330
- content = (
331
- tokenizer.im_start
332
- + tokenizer.unk_token * self.config.query_num
333
- + tokenizer.im_end
334
- + "\n"
335
- + content
336
- )
 
 
 
 
 
 
 
337
  prompt += "<用户>" if role == "user" else "<AI>"
338
  prompt += content
339
  prompt += "<AI>"
 
319
  content = msg["content"]
320
  assert role in ["user", "assistant"]
321
  if i == 0:
322
+ if image is None:
323
+ images = []
 
 
 
 
324
  else:
325
+ assert role == "user", "The role of first msg should be user"
326
+ if self.config.slice_mode:
327
+ images, final_placeholder = self.get_slice_image_placeholder(
328
+ image, tokenizer
329
+ )
330
+ content = final_placeholder + "\n" + content
331
+ else:
332
+ images = [image]
333
+ content = (
334
+ tokenizer.im_start
335
+ + tokenizer.unk_token * self.config.query_num
336
+ + tokenizer.im_end
337
+ + "\n"
338
+ + content
339
+ )
340
  prompt += "<用户>" if role == "user" else "<AI>"
341
  prompt += content
342
  prompt += "<AI>"