Repository navigation
fix(memory): size the DeepSeek V2 KV cache the way the runtime lays it out - #3137
Merged
Merged
Conversation
…t out Since #3131 DeepSeek V2 caches the MLA latent by default where the fused Metal kernel runs, but kv_arch still sized every deepseek_v2 config as the decompressed per-head cache (10240 against 1152 bytes per token per layer on V2-Lite, 8.9x). kv_arch now follows the loader's decision: latent when absorbed decode is selected and the KV cache is FP16, decompressed otherwise. The always-latent MLA families are sized as the latent too, and the KV cache advisor no longer advises int8 for an absorbing V2, since int8 turns absorption off. The CHANGELOG Known Issues entry that still called the decompressed cache the V2 default now covers CUDA and ROCm only. execution:: and server::prompt_cache:: lib tests pass on Metal; mlxcel inspect on the V2-Lite config at 32K tokens drops from 8.44 GiB to 972.0 MiB of KV. Refs #3133
This was referenced Nov 16, 2026
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
Since #3131 and #3136, DeepSeek V2 caches the MLA latent by default wherever the fused Metal kernel runs, but
kv_archstill sized everydeepseek_v2config as the decompressed per-head cache: 10240 bytes per token per layer on DeepSeek-V2-Lite against the 1152 actually cached (8.9x). The figure feeds the prompt-cache snapshot budget,mlxcel inspect/--estimate-memoryand the KV cache advisor. This is the sizing item of #3133, done before the release so the new default and its estimates ship together.kv_archresolves thedeepseek_v2layout with the loader's own decision: latent whenmla::absorbed_enabled()holds and the KV cache is FP16 (deepseek_v2_latent_layout), decompressed underMLXCEL_MLA_ABSORBED=0, on a backend without the fused kernel, or with an int8 cache (latent_layout_supports_moderefuses it at runtime). The paged-cache decline cannot reachdeepseek_v2, which does not opt into the paged decode backend.MLA_LATENT_CACHE_FAMILIES(GLM-4.7-Flash, Kimi Linear, Kimi K2, ...) were also sized per head; they now size the latent.Validation
execution::andserver::prompt_cache::lib tests pass on Metal (406), including new tests for the latent and decompressed sizes, the int8 decline, the layout rule, the process-level decision, the latent-pair families and the advisor rule. The oldmla_v2_uses_decompressed_per_headbecomesmla_v2_uses_decompressed_per_head_without_absorption. clippy--lib --tests -D warningsand fmt pass.mlxcel inspecton the published DeepSeek-V2-Lite-Chat-4bit-mlxconfig.jsonat 32768 tokens: KV cache 8.44 GiB before, 972.0 MiB after (M3 Ultra, absorbed by default; 31104 instead of 276480 bytes per token), 8.44 GiB withMLXCEL_MLA_ABSORBED=0, 4.22 GiB (decompressed) with an int8 cache.Not done here: the CUDA/ROCm measurements in #3133, which decide whether the default (and with it the sizing) changes on those backends.
Refs #3133