Repository navigation
feat: read the int8 MLA latent inside the fused Metal decode kernel - #3173
Merged
Merged
Conversation
#3155 decodes an affine int8 latent on a composed quantized_matmul path, so a quantized cache lost the fused kernel's short-context speed. The kernel's partial pass is now assembled from shared fragments with two window reads: the dense one, whose assembled Metal source is character-identical to before, and a quantized one that reads the packed codes as bytes and factors each group's scale and bias out of the score and the value sum, so the window is never dequantized. mla::decode::fused_absorbed_decode_quantized gates it (8-bit only with a bits dispatch that refuses 4, group size 64, power-of-two rank, unmasked single query) and quantized_absorbed_attention tries it before the composed path. MLXCEL_MLA_FUSED_DECODE=0 turns off both variants. The window limit is FUSED_DECODE_QUANTIZED_MAX_KEYS = 2048, not the fp16 kernel's 8192: on an M3 Ultra, V2-Lite int8 decode on the kernel against the composed path measured +6.5% behind 512 tokens, +0.4% behind 2048 and -4.6% behind 3840. On the shipped build int8 decode is 148.4 against 140.2 tok/s behind 512 and unchanged from 2048 on. Validated with parity tests against the composed quantized path (f32 5e-7, fp16 5.6e-4, bf16 6.25e-3 relative, bounds stated per dtype), a teacher-forced trace behind 1024 and 1920 tokens with 0 decided disagreements and top-1 flips only at gaps up to 0.109, and byte-identical fp16 traces against a build of 43f1c8d. cargo test -p mlxcel-core --lib mla:: (79 passed), clippy on mlxcel-core, fmt, verify-kernel-dtype-keys and verify-kernel-port-dispatch pass. CUDA and ROCm have no port and were not measured. Refs #3156
5 tasks done
Member
Author
Implementation Review SummaryIntent
Findings AddressedNone needed: no CRITICAL, HIGH, MEDIUM or LOW findings. Deviations judged
Verification
|
…sed-int8-latent-decode # Conflicts: # docs/mla-absorbed-decode.md
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
--kv-cache-mode int8on DeepSeek V2 decoded on the composedquantized_matmulpath only (#3155). This adds a quantized variant of the fused absorbed-decode kernel that reads the packed latent in-kernel, and routes unmasked single-query steps on a quantized window to it first.What changed
mla_absorbed_decode_fused_quantized{,_available};mla::decode::fused_absorbed_decode_quantizedwith the eligibility rules (8-bit only, abitsdispatch that refuses 4, group size 64, power-of-two rank, one query, no mask).quantized_absorbed_attentiontries it and falls back to the composed path onNone.MLXCEL_MLA_FUSED_DECODE=0disables both variants.FUSED_DECODE_QUANTIZED_MAX_KEYS = 2048, lower than the fp16 kernel's 8192. In-model on an M3 Ultra the kernel against the composed path read +6.5% behind 512 tokens, +0.4% behind 2048 and -4.6% behind 3840, so longer windows keep the composed path.docs/benchmark_results/mla-fused-quantized-decode-m3ultra-2026-11-19.md. On the shipped build int8 decode is 148.4 against 140.2 tok/s behind 512 (+5.9%), +1.5% behind 1792, and unchanged behind 2048 and 16384.Deviations from the issue
mla/fused_quant_decode_tests.rsto keepfused_decode_tests.rsunder the file size limit. Parity at 8192 keys calls the kernel through the bridge, since the decode path no longer gives it that window.MLXCEL_MLA_FUSED_DECODE=0 --kv-cache-mode int8alone recordsdecompressed, because DeepSeek V2 defaults to the decompressed layout on Metal without the kernel (perf(mla): make absorbed decode the DeepSeek V2 default and validate Kimi-VL on the fused kernel #3131). WithMLXCEL_MLA_ABSORBED=1it recordsabsorbed_composed.Test plan
cargo test --profile test-fast --features metal,accelerate -p mlxcel-core --lib mla:: -- --test-threads=1: 79 passed. Fused quantized against composed quantized at 1, 255, 2048 and 8192 keys: 5e-7 (f32), 5.6e-4 (fp16), 6.25e-3 (bf16) relative, the last two being one unit in the last place of the output dtype.43f1c8d4.cargo clippy -p mlxcel-core --lib --tests -- -D warnings,cargo fmt --check,make verify-kernel-dtype-keys verify-kernel-port-dispatch verify-env-var-docs.make verifyand workspace clippy were not run locally (deferred to CI at merge time). CUDA and ROCm were not measured; no port there.Closes #3156