FIX: DynamicCache max_cache_len attribute error#2735
Merged
BenjaminBossan merged 8 commits intohuggingface:mainfrom Aug 21, 2025
Merged
FIX: DynamicCache max_cache_len attribute error#2735BenjaminBossan merged 8 commits intohuggingface:mainfrom
BenjaminBossan merged 8 commits intohuggingface:mainfrom
Conversation
Resolves current CI errors with prefix tuning. Due to some recent changes in transformers (surfaced by huggingface/transformers#39797), checking hasattr(cache, max_cache_len) results in an error: >>> cache = DynamicCache() >>> hasattr(cache, "max_cache_len") Traceback (most recent call last): File "/home/name/work/forks/transformers/foo.py", line 9, in <module> hasattr(cache, "max_cache_len") ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/name/work/forks/transformers/src/transformers/cache_utils.py", line 916, in max_cache_len return max(values) ^^^^^^^^^^^ ValueError: max() iterable argument is empty This has been reported and will be fixed in transformers. On the PEFT side, it is safeest check the cache type and avoid accessing this attribute in the first place, which is what this PR does. Morever, that PR also changed the argument order to initialize HybridCache (will probably also be reverted in transformers), which is also taken into account in this PR by only using keyword arguments.
|
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. |
Cyrilvallez
approved these changes
Aug 12, 2025
Member
Cyrilvallez
left a comment
There was a problem hiding this comment.
Yup, should do the charm!
Cyrilvallez
approved these changes
Aug 18, 2025
Member
Cyrilvallez
left a comment
There was a problem hiding this comment.
Yes, LGTM! Would maybe change from lower_equal_4_55 to lower_4_56 just in case, but either way should be fine, we don't have any other patches planned for 4.55 (at least at this moment)
githubnemo
reviewed
Aug 20, 2025
Comment on lines
+752
to
+755
| # TODO: remove this logic once transformers < 4.56 is dropped | ||
| transformers_le_4_55 = packaging.version.parse(transformers.__version__) <= packaging.version.parse( | ||
| "4.55.2" | ||
| ) |
Collaborator
There was a problem hiding this comment.
I agree it would make more sense to make it lt_4_60 except I'm overlooking something.
Member
Author
There was a problem hiding this comment.
Changed to transformers_lt_4_56.
It will be deprecated and later removed, so move the import inside a version guard.
githubnemo
approved these changes
Aug 21, 2025
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.
Resolves current CI errors with prefix tuning.
Due to some recent changes in transformers (surfaced by huggingface/transformers#39797), checking
hasattr(cache, "max_cache_len")results in an error:This has been reported and will be fixed in transformers. On the PEFT side, it is safest check the cache type and avoid accessing this attribute in the first place, which is what this PR does.
Moreover, that PR also changed the argument order to initialize
HybridCache, which is also taken into account in this PR by only using keyword arguments.Update: This PR also takes care of a recent change in transformers that changed the cache type for Gemma to
DynamicCachefromHybridCache.Since the PR CI uses the transformers release, it won't show the error, but I tested locally and the failing tests pass.