Guard MLA caches from KV quantization#1323
Open
xxxkkw wants to merge 1 commit into
Open
Conversation
Keep DeepSeek MLA latent caches on the normal cache path so kv_bits does not convert the rope side channel into a quantized tuple and break decode.
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.
Summary
MLACachemarker for DeepSeek-style latent MLA caches.CacheListas MLA-specific.kv_bitsconversion for caches that do not support generic KV quantization, while keeping ordinary KV cache quantization unchanged.Reproduction
Before this change, a tiny DeepSeek V3 config with
kv_bits=4,kv_group_size=32, prompt length 3, andprefill_step_size=2fails on the second step with:The failure happens because generic
KVCache.to_quantized()turns the MLA rope side channel into a quantized tuple, but the DeepSeek V3 MLA attention path still needs an array fork_pe.swapaxes(...).After this change, the same repro generates successfully and the cache remains
MLACache.Environment
Test plan
python -m unittest discover -s tests -p test_models.py -k mla_models_make_mla_cachespython -m unittest discover -s tests -p test_models.py -k deepseek_v3_kv_bits_skips_mla_cachepython -m unittest discover -s tests -p test_models.py -k deepseek_v3python -m unittest discover -s tests -p test_models.py -k quantizedpython -m unittest discover -s tests -p test_prompt_cache.py -k cache_with_generateMLACacheNo throughput speedup is claimed here; this is a correctness guard for an invalid quantization path. Generic quantized KV cache coverage continues to pass.