Support image is None
Browse files- 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 |
-
|
323 |
-
|
324 |
-
images, final_placeholder = self.get_slice_image_placeholder(
|
325 |
-
image, tokenizer
|
326 |
-
)
|
327 |
-
content = final_placeholder + "\n" + content
|
328 |
else:
|
329 |
-
|
330 |
-
|
331 |
-
|
332 |
-
|
333 |
-
|
334 |
-
+ "\n"
|
335 |
-
|
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>"
|