Skip to content

Conversation

@BenjaminBossan
Copy link
Member

@BenjaminBossan BenjaminBossan commented Aug 12, 2025

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 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 DynamicCache from HybridCache.

Since the PR CI uses the transformers release, it won't show the error, but I tested locally and the failing tests pass.

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.
@HuggingFaceDocBuilderDev

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.

Copy link
Member

@Cyrilvallez Cyrilvallez left a comment

Choose a reason for hiding this comment

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

Yup, should do the charm!

Copy link
Member

@Cyrilvallez Cyrilvallez left a comment

Choose a reason for hiding this comment

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

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)

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"
)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I agree it would make more sense to make it lt_4_60 except I'm overlooking something.

Copy link
Member Author

Choose a reason for hiding this comment

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

Changed to transformers_lt_4_56.

It will be deprecated and later removed, so move the import inside a
version guard.
@BenjaminBossan BenjaminBossan merged commit 41c07f0 into huggingface:main Aug 21, 2025
14 checks passed
@BenjaminBossan BenjaminBossan deleted the fix-dynamiccache-attribute-error branch August 21, 2025 14:24
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.

4 participants