Repository navigation
Fix DecodingPress(AdaKVPress) rescoring the fake keys of masked tokens 🤖🤖🤖 - #341
Open
siddhant-rajhans wants to merge 1 commit into
Open
siddhant-rajhans wants to merge 1 commit into
siddhant-rajhans wants to merge 1 commit into
Conversation
…s 🤖🤖🤖 attention_patch wrote the fake keys of masked tokens into the cache, so DecodingPress(AdaKVPress(...)) scored those fake keys when it compressed again (NaN scores with ExpectedAttentionPress in float16), and tokens it unmasked attended with fake keys. Write them into a copy of the keys instead. DecodingPress and CAMPress also reset masked_key_indices when their compression shortens the cache: masks set earlier, e.g. by an AdaKV prefilling press, index the cache as it was before pruning and made the next step fail with an IndexError. Fixes NVIDIA#339 Signed-off-by: Siddhant Rajhans <51508945+siddhant-rajhans@users.noreply.github.com>
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.
PR description
Fixes #339.
attention_patchwrites the fake keys of masked tokens into a copy of the keys (key.index_put(...)) instead of into the cache. The cache keeps the tokens' own keys, soDecodingPress(AdaKVPress(...))scores real keys when it compresses again, and a token it unmasks attends with its own key. The cost is one copy of the layer's keys per decoding step while masks exist. If that matters for long contexts, the write could stay in place for presses that never compress again; I kept the simpler version.DecodingPressandCAMPressresetmasked_key_indiceswhen their compression shortens the cache. Masks set earlier, e.g. by an AdaKV prefilling press inPrefillDecodingPress, index the cache as it was before pruning, and the next step failed withIndexError. The decoding press's selection replaces them.The regression tests cover the two cases @NathanBenDev listed in the issue.
Validation (CPU)
PrefillDecodingPressrepro now decodes without error, withDecodingPressand withCAMPress.tests/test_decoding_compression.py, all failing on main:test_decoding_adakv_press_rescores_the_tokens_keys: three compressions per layer with finite scores, and the first layer's cached keys equal those of a run without a press.test_decoding_press_drops_prefill_masks_when_it_prunes_the_cache(DecodingPressandCAMPress): decodes 16 tokens after an AdaKV prefill.test_attention_patch.py,test_decoding_compression.pyandtest_presses.py) on CPU: 587 passed, 7 skipped (flash-attn, Quanto and HQQ are not installed, plus one FinchPress case the test skips).make stylepasses.Checklist
Before submitting a PR, please make sure:
make test)make style, on errors try fix withmake format)git commit -s🤖🤖🤖