Add serialization function for StaticCache#38879
Closed
xadupre wants to merge 6 commits intohuggingface:mainfrom
Closed
Add serialization function for StaticCache#38879xadupre wants to merge 6 commits intohuggingface:mainfrom
xadupre wants to merge 6 commits intohuggingface:mainfrom
Conversation
Member
|
cc @gante! |
Contributor
|
I think #38917 would be possible with this |
gante
reviewed
Jun 24, 2025
Contributor
gante
left a comment
There was a problem hiding this comment.
In general LGTM, as it enables a relevant feature.
However, I have two minor grudges :D It would be great if we could solve them, for long-term scalability of the library:
- This is
torch.export-related code that runs on basic imports, regardless oftorch.exportbeing used or not. For instance,from transformers import AutoModelForCausalLMwill run these lines, which seems wasteful. Is there some way to enable lazy execution? Ideally, these would only be run at export time. - This
torch.export-related code lives alongside the cache definition, which hurts readability for all other users. Ideally, this code would live intransformers/integrations/export.py(ortorch_export.py), but we would have to careful with circular imports.
| from packaging import version | ||
|
|
||
| from transformers.pytorch_utils import is_torch_greater_or_equal_than_2_6 | ||
| from transformers.pytorch_utils import is_torch_greater_or_equal_than_2_6, is_torch_greater_or_equal_than_2_7 |
Contributor
There was a problem hiding this comment.
We're moving all these flags to is_torch_greater_or_equal, which is already imported here
e.g. is_torch_greater_or_equal("2.7.0"), or is_torch_greater_or_equal("2.7.0", accept_dev=True) if you also want to accept dev versions of 2.7
Contributor
Author
There was a problem hiding this comment.
I saw this snippet of code. Do you want me to remove the flag I inserted and use is_torch_greater_or_equal("2.7", accept_dev=True) directly in the code?
is_torch_greater_or_equal_than_2_7 = is_torch_greater_or_equal("2.7", accept_dev=True) # the line I added
is_torch_greater_or_equal_than_2_6 = is_torch_greater_or_equal("2.6", accept_dev=True)
Contributor
Contributor
Author
|
Replaced by #39931. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Implements serialization functions for StaticCache similar to the one implemented for DynamicCache. Fixes pytorch/pytorch#155862.
Before submitting
Pull Request section?
to it if that's the case.
documentation guidelines, and
here are tips on formatting docstrings.
Who can review?
Anyone in the community is free to review the PR once the tests have passed. Feel free to tag
members/contributors who may be interested in your PR.