Skip to content

Commit

Permalink
Merge pull request #275 from hannahyklee/mllm-eval-hl
Browse files Browse the repository at this point in the history
fix for none past_key_values, getting supported tasks
  • Loading branch information
anas-awadalla authored Nov 29, 2023
2 parents aa995e3 + 5d10063 commit 427d974
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
4 changes: 2 additions & 2 deletions open_flamingo/eval/eval_models/eval_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ def supported_tasks(self):
Parsed by checking whether the model has a method called `get_{task}_prompt`.
"""
return [
task.split("_")[1]
"_".join(task.split("_")[1:-1])
for task in dir(self)
if task.startswith("get_") and task.endswith("_prompt")
]
Expand All @@ -207,4 +207,4 @@ def _validate_text(self, batch_text):
if any([x.endswith(" ") for x in batch_text]):
print(
"Warning: trailing whitespace detected in text. This can cause unexpected behavior."
)
)
4 changes: 2 additions & 2 deletions open_flamingo/eval/evaluate.py
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ def main():
if args.eval_coco:
eval_dataset(
args,
dataset_name="flickr30",
dataset_name="coco",
eval_model=eval_model,
results=results,
eval_fn=evaluate_captioning,
Expand Down Expand Up @@ -1302,4 +1302,4 @@ def evaluate_classification(


if __name__ == "__main__":
main()
main()
15 changes: 8 additions & 7 deletions open_flamingo/src/vlm.py
Original file line number Diff line number Diff line change
Expand Up @@ -415,13 +415,14 @@ def _prepare_inputs_for_forward(
past_vision_tokens=past_vision_tokens,
num_beams=num_beams,
)
past_key_values = [
(
k.repeat_interleave(num_beams, dim=0),
v.repeat_interleave(num_beams, dim=0)
)
for k, v in past_key_values
] if past_key_values is not None else None
if past_key_values is not None:
past_key_values = [
(
k.repeat_interleave(num_beams, dim=0),
v.repeat_interleave(num_beams, dim=0)
)
for k, v in past_key_values

return {
"input_ids": lang_x,
"attention_mask": attention_mask,
Expand Down

0 comments on commit 427d974

Please sign in to comment.