Skip to content

Commit

Permalink
Fix cache position update
Browse files Browse the repository at this point in the history
  • Loading branch information
nurlanov-zh committed May 7, 2024
1 parent 043df8b commit e1b1c10
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/transformers/generation/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -667,7 +667,11 @@ def _update_model_kwargs_for_generation(
dim=-1,
)

if "cache_position" in model_kwargs and model_kwargs["cache_position"] is not None:
if (
model_kwargs.get("use_cache", True)
and "cache_position" in model_kwargs
and model_kwargs["cache_position"] is not None
):
model_kwargs["cache_position"] = model_kwargs["cache_position"][-1:] + num_new_tokens

return model_kwargs
Expand Down

0 comments on commit e1b1c10

Please sign in to comment.