Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix for none past_key_values, getting supported tasks #275

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading