-
Notifications
You must be signed in to change notification settings - Fork 30k
Add serialization function for StaticCache #38879
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
Conversation
cc @gante! |
I think #38917 would be possible with this |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.export
being used or not. For instance,from transformers import AutoModelForCausalLM
will 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.
@@ -9,7 +9,7 @@ | |||
import torch | |||
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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)
Replaced by #39931. |
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.