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 EncoderDecoder cache candidate edge case #33926

Closed
Closed
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
11 changes: 3 additions & 8 deletions src/transformers/generation/candidate_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -398,15 +398,10 @@ def _crop_past_key_values(model, past_key_values, max_length):
past_key_values.crop(max_length)
elif past_key_values is not None:
for idx in range(len(past_key_values)):
if past_key_values[idx] != ([], []):
new_past.append(
(
past_key_values[idx][0][:, :, :max_length, :],
past_key_values[idx][1][:, :, :max_length, :],
)
)
if past_key_values[idx] != ([],) * len(past_key_values[idx]):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mmm speedwise some stuff might break compile but not sure candidate generator was supported. Also sorry again for this break, introduced in Mllama 😢 will be in patch.

new_past.append(tuple(past_key_value[:, :, :max_length, :] for past_key_value in past_key_values[idx]))
else:
new_past.append((past_key_values[idx][0], past_key_values[idx][1]))
new_past.append(past_key_values[idx])
past_key_values = tuple(new_past)
return past_key_values

Expand Down
Loading