Skip to content

Commit

Permalink
fix qwen multi picture testing
Browse files Browse the repository at this point in the history
  • Loading branch information
void-b583x2-NULL committed Feb 2, 2024
1 parent cf5c3eb commit be0b857
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 15 deletions.
8 changes: 4 additions & 4 deletions eval/model_tester.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def parse_args():
}]

testcases_for_chinese_puretext = testcases_for_chinese[:3]
testcases_for_chinese_pic_descrip = testcases_for_chinese[-5:-1]
testcases_for_chinese_pic_descrip = testcases_for_chinese[-5:]

from eval import get_evaluator

Expand All @@ -126,9 +126,9 @@ def parse_args():
# if test_args.input_type == 0:
# testcases = testcases_for_chinese
# else:
testcases = testcases_for_chinese
# testcases = testcases_for_chinese_pic_descrip[-1:]
testcases = testcases_for_chinese[-1:]
# testcases = testcases_for_chinese
testcases = testcases_for_chinese_pic_descrip
# testcases = testcases_for_chinese[-1:]

testcases = dict(zip(range(len(testcases)), testcases))
for i in testcases:
Expand Down
20 changes: 15 additions & 5 deletions eval/models/qwen_hf.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,29 @@ def __init__(self, model_dir="Qwen/Qwen-VL-Chat-Int4", # "Qwen/Qwen-VL-Chat"
def prepare_inputs(self, content, image_list=None, image_path=None):
if image_list:
match = re.findall("<img_[0-9]+>", content)
content_prefix = ""
if len(match) > 0:
for img_sub, image_path in zip(match, image_list):
content = content.replace(img_sub, "")
content = f"<img>{image_path}</img>\n" + content
if len(image_list) == 1:
content = content.replace(match[0], "")
content_prefix += f"<img>{image_list[0]}</img>\n" # align with previous setting
else:
for i, (img_sub, image_path) in enumerate(zip(match, image_list)):
content = content.replace(img_sub, f"[IMAGE_{i+1}]")
content_prefix += f"Picture {i+1}: <img>{image_path}</img>\n"
elif len(image_list) > 0:
# This is the universal setting of parsing one-round dialogue questions.
# in `get_prompt` we cleared all img tokens in the question. However that's critically fatal in one-image question
# We need to add the image paths back!
for image_path in image_list:
content = f"<img>{image_path}</img>\n" + content
if len(image_list) == 1:
content_prefix += f"<img>{image_list[0]}</img>\n" # align with our previous setting
else:
for i, image_path in enumerate(image_list):
content_prefix += f"Picture {i+1}: <img>{image_path}</img>\n"
content = content_prefix + content
elif image_path:
# The reason it literally works is that in multi-round dialogue questions we parse `image_path` and the information doesn't get lost!
content = f"<img>{image_path}</img>\n" + content # The surprising bug says that qwen read the images at the head of text inputs.
# print(content) # debug only
return content

def generate_response(self, input):
Expand Down
22 changes: 16 additions & 6 deletions eval/models/qwen_ms.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,21 +38,31 @@ def __init__(self, model_path="Qwen/Qwen-VL-Chat-Int4", # "Qwen/Qwen-VL-Chat"
def prepare_inputs(self, content, image_list=None, image_path=None):
if image_list:
match = re.findall("<img_[0-9]+>", content)
content_prefix = ""
if len(match) > 0:
for img_sub, image_path in zip(match, image_list):
content = content.replace(img_sub, "")
content = f"<img>{image_path}</img>" + content
if len(image_list) == 1:
content = content.replace(match[0], "")
content_prefix += f"<img>{image_list[0]}</img>\n" # align with previous setting
else:
for i, (img_sub, image_path) in enumerate(zip(match, image_list)):
content = content.replace(img_sub, f"[IMAGE_{i+1}]")
content_prefix += f"Picture {i+1}: <img>{image_path}</img>\n"
elif len(image_list) > 0:
# This is the universal setting of parsing one-round dialogue questions.
# in `get_prompt` we cleared all img tokens in the question. However that's critically fatal in one-image question
# We need to add the image paths back!
for image_path in image_list:
content = f"<img>{image_path}</img>" + content
if len(image_list) == 1:
content_prefix += f"<img>{image_list[0]}</img>\n" # align with our previous setting
else:
for i, image_path in enumerate(image_list):
content_prefix += f"Picture {i+1}: <img>{image_path}</img>\n"
content = content_prefix + content
elif image_path:
# The reason it literally works is that in multi-round dialogue questions we parse `image_path` and the information doesn't get lost!
content = f"<img>{image_path}</img>" + content # The surprising bug says that qwen read the images at the head of text inputs.
content = f"<img>{image_path}</img>\n" + content # The surprising bug says that qwen read the images at the head of text inputs.
return content


def generate_response(self, input):
if isinstance(input, dict):
question = input
Expand Down
Empty file removed models/.gitkeep
Empty file.

0 comments on commit be0b857

Please sign in to comment.