Skip to content

Fix DecodingPress(AdaKVPress) rescoring the fake keys of masked tokens 🤖🤖🤖 - #341

Open
siddhant-rajhans wants to merge 1 commit into
NVIDIA:mainfrom
siddhant-rajhans:fix-decoding-adakv-fake-keys
Open

siddhant-rajhans wants to merge 1 commit into
NVIDIA:mainfrom
siddhant-rajhans:fix-decoding-adakv-fake-keys

Conversation

@siddhant-rajhans

Copy link
Copy Markdown

PR description

Fixes #339.

  • attention_patch writes 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, so DecodingPress(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.
  • DecodingPress and CAMPress reset masked_key_indices when their compression shortens the cache. Masks set earlier, e.g. by an AdaKV prefilling press in PrefillDecodingPress, index the cache as it was before pruning, and the next step failed with IndexError. The decoding press's selection replaces them.

The regression tests cover the two cases @NathanBenDev listed in the issue.

Validation (CPU)

  • The repro from DecodingPress(AdaKVPress(...)) re-scores the fake keys that attention_patch writes into the cache 🤖🤖🤖 #339: after each of the three compressions the scores are finite and 0 of the 96 visible keys differ from the token's key, in float16 and float32. On main the scores are NaN from the second compression in float16, and 32 to 60 of the 96 visible keys are fake. The PrefillDecodingPress repro now decodes without error, with DecodingPress and with CAMPress.
  • New tests in 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 (DecodingPress and CAMPress): decodes 16 tokens after an AdaKV prefill.
  • Existing tests that cover masks and decoding presses (12 files, including test_attention_patch.py, test_decoding_compression.py and test_presses.py) on CPU: 587 passed, 7 skipped (flash-attn, Quanto and HQQ are not installed, plus one FinchPress case the test skips). make style passes.

Checklist

Before submitting a PR, please make sure:

  • Tests are working (make test)
  • Code is formatted correctly (make style, on errors try fix with make format)
  • Copyright header is included
  • All commits are signed-off using git commit -s

🤖🤖🤖

…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>
@copy-pr-bot

copy-pr-bot Bot commented Nov 10, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@SimJeg SimJeg self-assigned this Nov 23, 2026
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.

DecodingPress(AdaKVPress(...)) re-scores the fake keys that attention_patch writes into the cache 🤖🤖🤖

2 participants