Skip to content

🚨🚨 Rename past_key_values/cache_params to cache - #50585

Merged
Cyrilvallez merged 41 commits into
mainfrom
rename-cache
Nov 13, 2026
Merged

Cyrilvallez merged 41 commits into
mainfrom
rename-cache

Conversation

@Cyrilvallez

@Cyrilvallez Cyrilvallez commented Nov 10, 2026 •

Copy link
Copy Markdown
Member

🤗 Transformers CI

What does this PR do?

As per the title. We finally can have a single and meaningful name for the cache!
I made sure that all the following hold:

  • full transformers BC compatibility
    • planned until at least v6 for big entry points, i.e. generate and model outputs classes (such as CausalLMOutputWithPast,...)
    • planned until v5.40 for all modeling code classes which had a past_key_values/cache_params in their signature
  • fully compatible with our continuous batching (CB) implem, thanks to adding the kwargs=kwargs in the update() method of the Cache. This means that CB know updates its cache the exact same way as the standard Cache do inside the Attention classes instead of forcing it inside the attn_implementation function, which is much more elegant
  • fully compatible with vllm: it does not forward any specific cache object inside the kwargs, so fully safe
  • fully compatible with sglang: the cache here is forwarded through the kwargs, but not under the same name so fully safe
  • trl: all good
  • peft: needs some local change directly in the peft codebase, as they sometimes check "past_key_values" in inspect.signature(forward), and we cannot easily trick the inspection of signature of course. However, the only peft integration test failing is test_prefix_tuning_trainer_load_best_model_at_end_error, so the blast radius is probably quite small
  • remote code: as always, we unfortunately cannot guarantee anything on remote code, and this PR is likely to break quite a few. They will either have to perform the name change (very easy), or pin a Transformers version earlier than the released one with this change
🤖 mlinter review state

@HuggingFaceDocBuilderDev

Copy link
Copy Markdown

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

Pages changed in this PR:

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Model linter — first pass

transformers-mlinter found 18 item(s) in the model files this PR touches. These are structural conventions a maintainer would otherwise flag by hand.

This is automated and advisory — it does not block merging.

rule count what it checks
TRF057 18 Public model, config, output and processor classes and their public methods must carry @auto_docstring.
2 item(s) outside this diff
  • src/transformers/models/embedding_gemma2/modular_embedding_gemma2.py:477 TRF057 — TRF057: EmbeddingGemma2TextModel.forward in modeling_embedding_gemma2.py has no @auto_docstring. No parent method it could inherit the decorator from declares it. Add @auto_docstring as the innermost decorator here.
  • src/transformers/models/flint/modular_flint.py:249 TRF057 — TRF057: FlintForCausalLM.forward in modeling_flint.py has no @auto_docstring. No parent method it could inherit the decorator from declares it. Add @auto_docstring as the innermost decorator here.

@qgallouedec qgallouedec left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks, checked it against TRL: nothing there uses the old names, but two things break though:

  • Continuous batching fails with 'PagedAttentionCache' object has no attribute 'get_query_offset'.
  • The BC handling covers outputs["past_key_values"] but not outputs.past_key_values, so liger-kernel 0.8.1's patched forwards (use_liger_kernel=True) fail with AttributeError: 'BaseModelOutputWithPast' object has no attribute 'past_key_values'. A __getattr__ alias like the __getitem__ one would keep them working.

@Cyrilvallez

Copy link
Copy Markdown
Member Author

Indeed @qgallouedec, it's still a work in progress but thanks for the early review! For the __getattr__ I'm aware of the issue and experimented with it in 6a07fdf, but unfortunately dynamo does not seem to accept any class that overrides __getattribute__, so fullgraph compilation would fail at the very end of the model, when casting outputs inside the output class (return CausalLMOutput(logits=logits, ...). This is definitely something that we need to both be present for BC, and to be working with compilation, so I still have to find a solution for it but don't worry it'll be taken care of!

@Cyrilvallez

Copy link
Copy Markdown
Member Author

Ok, we have a lot of offline discussion on this with @vasqu and @ArthurZucker, and eventually agreed on it! Especially with the last commit, remote code should almost not experience any disruption at all (but once again we cannot predict everything, and they tend to have very ingenious ways to break 🙃).
So merging!

@Cyrilvallez
Cyrilvallez merged commit 6a9193d into main Nov 13, 2026
122 of 124 checks passed
@Cyrilvallez
Cyrilvallez deleted the rename-cache branch November 13, 2026 13:19
@ValeGian ValeGian mentioned this pull request Nov 16, 2026
@ebezzam ebezzam mentioned this pull request Nov 19, 2026
3 tasks done
Hakureirm pushed a commit to Hakureirm/transformers-rwkv that referenced this pull request Nov 22, 2026
The model is new, so it has no old cache name to keep: skip test_bc_cache_name_forward, like Dory.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants