From 859823eb23776b610ae632d10e889b8242581aa5 Mon Sep 17 00:00:00 2001 From: hiyouga <467089858@qq.com> Date: Mon, 2 Sep 2024 01:31:36 +0800 Subject: [PATCH] add image num check Former-commit-id: ce8c5a264742161101da2094d0fc31c7fa7fb641 --- src/llamafactory/data/mm_plugin.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/llamafactory/data/mm_plugin.py b/src/llamafactory/data/mm_plugin.py index a3636737..47682732 100644 --- a/src/llamafactory/data/mm_plugin.py +++ b/src/llamafactory/data/mm_plugin.py @@ -210,12 +210,17 @@ class Qwen2vlPlugin(BasePlugin): merge_length: int = getattr(image_processor, "merge_size") ** 2 if len(images) > 0: image_grid_thw = _get_mm_inputs(images, processor)["image_grid_thw"] + else: + image_grid_thw = [] num_images = 0 messages = deepcopy(messages) for message in messages: content = message["content"] while IMAGE_PLACEHOLDER in content: + if num_images >= len(image_grid_thw): + raise ValueError("`len(images)` is less than the number of {} tokens.".format(IMAGE_PLACEHOLDER)) + content = content.replace( IMAGE_PLACEHOLDER, "<|vision_start|>{}<|vision_end|>".format(