Repository navigation
Fix DynamicCacheWithRepeat AttributeError on transformers Cache refactor - #216
Open
Amir Fathi (AmirF194) wants to merge 1 commit into
Conversation
DynamicCacheWithRepeat.__init__ calls super().__init__() and relies on the parent DynamicCache to set self.key_cache/self.value_cache/self._seen_tokens, but update() and get_seq_length() read those three attributes directly and never touch DynamicCache's own storage. Current transformers no longer sets them (Cache moved to a self.layers list), so both methods raise AttributeError. Self-initialize the three attributes in __init__, matching the pattern BaseKVCache already uses a few classes above in the same file. Fixes microsoft#207 Fixes microsoft#195
Author
|
This has been open a week with no review yet. Let me know if the approach needs adjusting before you look closer. |
This branch has not been deployed
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?
DynamicCacheWithRepeat.__init__callssuper().__init__()and counts onDynamicCacheto set
self.key_cache/self.value_cache/self._seen_tokens, butupdate()andget_seq_length()read those three directly and never touchDynamicCache's own storage.Current transformers moved that storage to a
self.layerslist, so both methods raiseAttributeErrorthe momentgenerate()callsget_seq_length().BaseKVCache, a fewclasses above in the same file, already self-initializes the same three attributes instead
of relying on the parent, for the same reason; this gives
DynamicCacheWithRepeatthe samepattern.
Fixes #207
Fixes #195 (same traceback, same file and line, hit through
run_infinitebench.pyinsteadof
pipeline(), on transformers 4.57.1 rather than 5.17.0, five months apart)Before submitting
Added
tests/test_dynamic_cache_with_repeat.py, unittest-style liketest_e2e.py. It failson main with transformers 5.17.0 (both methods raise
AttributeError) and passes on thisbranch; also ran it against transformers 4.48.0 (the version
mtraining/requirements.txtpins) to check the fix doesn't change behavior where
key_cachealready existed, and itpasses there too, before and after.
One thing worth flagging: constructing
DynamicCacheWithRepeatthrough the normalminferenceimport needs vllm and the CUDA build, so the new test importsminference.modules.kvcompressiondirectly rather than through the package, sidesteppingthat and an unrelated existing issue where
kivi.py/retr_attn.pymisread_is_package_available's return value. No GPU here, so I couldn't runtest_e2e.pyor theoriginal repro's actual
pipeline().generate()call; the two isolated methods are what Iverified.