Repository navigation
feat: store a quantized MLA latent in the DeepSeekV3Attention families - #3172
Merged
Merged
Conversation
The eight model types that run DeepSeekV3Attention (deepseek_v3, kimi_k2, joyai_llm_flash, kimi_vl, kimi_k25, youtu, youtu_llm, youtu_vl) cached their latent pair through KVCache::update_and_fetch directly, so rule 1 substituted every quantized request with fp16. They now write the pair through MlaLatentCache, and --kv-cache-mode int8 / --kv-bits 8 keep the #3155 affine group-64 latent (672 against 1152 bytes per token per layer at rank 512). - mla::latent_pair adds QUANTIZED_LATENT_FAMILIES and latent_pair_supports_mode; rule 1 calls it and its warning names int8 for these families. Turbo modes still resolve to fp16; the other latent-pair families keep fp16. - DeepSeekV3Attention and the shared batched helper store each step through store_latent_step. A quantized one-query step runs the composed quantized decode; multi-token steps dequantize once; fp16 caches take the unchanged path. A key selector over a quantized row panics naming the family. - kv_arch, the advisor, inspect, the serve kv-bits gate and the generate banner use the quantized rate and mode. M3 Ultra, Moonlight-16B-A3B and Kimi-VL-A3B-Thinking: 0 decided disagreements behind 1024 and 4096 (one flip per checkpoint behind 1024 at 0.117 and 0.180, outside the 0.11 near-tie bar), fp16 trace byte-identical to 43f1c8d, decode 15 to 17% slower than the fp16 latent at 512 and 2048 and 36% at 16384. Closes #3160
5 of 6 tasks
Member
Author
Implementation Review SummaryIntent
Findings AddressedNone needed a fix (no CRITICAL or HIGH findings). Remaining Items
Verification
|
Member
Author
Security and performance reviewNo CRITICAL or HIGH findings, so no fixes were committed. Checked:
Remaining items (not fixed, below the auto-fix threshold):
|
…llers store_latent_step and mla_latent_decode_rows chose the latent view from the cache mode alone, so glm4_moe_lite, kimi_linear, kimi_k3 and deepseek_v32 would have taken the quantized latent under an int8 cache although they are outside mla::QUANTIZED_LATENT_FAMILIES. Both helpers now take an explicit quantized_latent flag; only DeepSeekV3Attention passes true, and the other callers keep the per-token path. fp16 caches never reach the view, so their behavior is unchanged. A new test checks that an int8 cache gets a dense window without the flag and a quantized one with it. The warn-once guard for a declined latent view is now per family instead of process-wide. The registry kv_modes for deepseek_v3, kimi_vl, kimi_k25, youtu_llm and youtu_vlm now list fp16 and int8 to match the runtime, with a test that pins the list against QUANTIZED_LATENT_FAMILIES. The results doc, turbo-kv-cache.md, supported-models.md and the CHANGELOG now state that the 0.117 and 0.180 top-1 flips behind 1024 tokens are outside the 0.11 near-tie bar and remain open; no measured number changed. Validation: cargo test -p mlxcel --lib models::deepseek_v3:: (26 passed), models::registry (21), models::mla_batched (2), execution::kv_arch (47), cargo test -p mlxcel-core --lib mla::latent_pair (4), all serial under the GPU lock; cargo clippy -p mlxcel -p mlxcel-core --lib --tests -D warnings and cargo fmt --check clean. Refs #3160
…-quantized-latent
…-quantized-latent # Conflicts: # CHANGELOG.md # docs/environment-variables.md
#3156 merged into this branch, so an unmasked int8 decode step on the DeepSeekV3Attention families now runs the fused kernel's quantized variant up to 2048 keys instead of the composed path. The #3160 rows were measured before that. - Results doc: add an "After #3156 merged" section with the trace behind 1024 and decode at 512 and 2048 on Moonlight and Kimi-VL, re-measured on 9af1ce4, with path counters; keep the original rows as the pre-#3156 record. Behind 1024 every int8 step is absorbed_fused, decided disagreements stay 0, Moonlight has flips at 0.117 and 0.328 above the near-tie bar and Kimi-VL none. int8 decode is about 10% below fp16 at 512 (was about 17%) and unchanged at 2048, which stays composed. - turbo-kv-cache.md, environment-variables.md, the #3160 CHANGELOG entry, the advisor text and comments in deepseek_v3.rs, mla_batched.rs and mla/decode.rs no longer say these families skip the fused kernel. The fp16 trace behind 1024 is byte-identical to the recorded one on both checkpoints. Refs #3160, #3156
inureyes
marked this pull request as ready for review
November 19, 2026 11:15
This was referenced Nov 19, 2026
inureyes
added a commit
that referenced
this pull request
Nov 19, 2026
…3181) #3172 made deepseek_v3 keep int8 KV as a quantized MLA latent, so the load-profile test that expected int8 to be refused on a deepseek_v3 checkpoint failed: the profile no longer sees a substitution. The two refusal assertions now use turbo4-asym, which DeepSeek V3 still substitutes with fp16, and a new assertion pins that an int8 profile is accepted and keeps KVCacheMode::Int8. Validated on ROCm gfx1151: cargo test --features rocm --lib server::webui::load_profile passes (4 tests). Closes #3180
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
The eight
DeepSeekV3Attentionmodel types (deepseek_v3,kimi_k2,joyai_llm_flash,kimi_vl,kimi_k25,youtu,youtu_llm,youtu_vl) now write their MLA latent throughMlaLatentCache, so--kv-cache-mode int8and--kv-bits 8keep the #3155 affine int8 latent (672 against 1152 bytes per token per layer) instead of being substituted with fp16. int8 only: 4-bit failed the #3155 gate.mla::latent_pair:QUANTIZED_LATENT_FAMILIESandlatent_pair_supports_mode, called by rule 1; the warning names int8 for these families. Turbo modes still resolve to fp16, andglm4_moe_liteand the other latent-pair families keep fp16. The list lives in a new file besidemla/cache.rsto keep that file under 500 lines.mla_latent_decode_rowsstore throughstore_latent_step. A quantized one-query step runsquantized_absorbed_attention(now public); multi-token steps dequantize once; fp16 caches take the unchangedKVCache::update_and_fetch. A selector over a quantized row panics naming the family. The batched helper now takes the family, the geometry and an explicitquantized_latentopt-in: onlyDeepSeekV3Attentionpassestrue, sodeepseek_v32,kimi_linear,glm4_moe_liteandkimi_k3keep the per-token path even if an int8 cache reached them. The declined-view warning fires once per family.kv_arch, inspect, preflights, prompt-cache budget), the advisor (int8 at medium/long), the serve--kv-bitsgate and the generate banner follow.kv_modesforDeepSeekV3,KimiVL,KimiK25,YoutuLLMandYoutuVLMnow report fp16 and int8 (newKV_INT8), pinned by a test againststores_quantized_latent_pair;docs/supported-models.mdupdated to match.Results (M3 Ultra, Moonlight-16B-A3B and Kimi-VL-A3B-Thinking)
Since #3156 merged into this branch, a one-query int8 step over a window of up to 2048 keys runs on the fused quantized kernel and longer windows run the composed path. Measured on the merged tree:
absorbed_fused. The fp16 trace is byte-identical to the recorded one.nbytesequal the inspect rate under both flags.Details:
docs/benchmark_results/mla-quantized-latent-v3-m3ultra-2026-11-19.md.Test plan
cargo test -p mlxcel --libon models::deepseek_v3, mla_batched, youtu_vl_lm, glm4_moe_lite, kimi_linear, kimi_k3, deepseek_v32, cli::turbo_args, execution::, server::prompt_cache, server::cli_input, vision::encoders::kimi_vl (766 passed)cargo test -p mlxcel-core --libon mla::, cache::turbo::allowlist, cache::latent_quant (101 passed)cargo fmt --check,cargo clippy -p mlxcel-core/-p mlxcel --lib --tests -D warningsmake verify-clippy, mlxcel-coremla::(90), mlxcel deepseek_v3, mla_batched, registry, kv_arch, kv_cache_advisor (139); trace behind 1024 and decode at 512 / 2048 re-run on both checkpointsCloses #3160