Skip to content

Commit d8a3a99

Browse files
authored
Merge pull request #61 from tupini07/patch-1
Fix typo in Qwen-VL that was causing "reference before assignment"
2 parents 3dcd015 + ed17129 commit d8a3a99

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

Diff for: lmms_eval/models/qwen_vl.py

+10-6
Original file line numberDiff line numberDiff line change
@@ -228,21 +228,25 @@ def _collate(x):
228228
until = [until]
229229
elif not isinstance(until, list):
230230
raise ValueError(f"Expected `gen_kwargs['until']` to be of type Union[str,list] but got {type(until)}")
231+
232+
if isinstance(contexts, tuple):
233+
contexts = list(contexts)
234+
231235
for i in range(len(contexts)):
232236
if "<image>" in contexts[i]:
233-
context[i] = contexts[i].replace("<image>", "")
234-
questions = [self.prompt.format(visual_path, context) for visual_path, context in zip(visual_paths, contexts)]
237+
contexts[i] = contexts[i].replace("<image>", "")
235238

236239
# Similar to llava, is visual paths has len 0
237240
# Then nothing will be executed
238241
query = []
239-
for visual_path, context in zip(visual_paths, contexts):
240-
query.append({"image": visual_path})
241-
query.append({"text": context})
242-
243242
if len(visual_paths) == 0:
244243
for context in contexts:
245244
query.append({"text": context})
245+
else:
246+
for visual_path, context in zip(visual_paths, contexts):
247+
query.append({"image": visual_path})
248+
query.append({"text": context})
249+
246250

247251
questions = self.tokenizer.from_list_format(query)
248252
input_ids = self.tokenizer(questions, return_tensors="pt", padding="longest")

0 commit comments

Comments
 (0)