Repository navigation
[Triton/Gluon] [GFX12] Gluon a8w8 Sparse MLA - #6116
Conversation
…ng nothing
Renames so every DeepSeek-V4 op in the mxfp8 quant module carries the same
prefix, with each kernel beside its launcher:
fused_deepseek_v4_qnorm_rope_kv_rope_quant_insert_aligned
-> fused_deepseek_v4_qnorm_rope_kv_rope_quant_insert
quantize_and_insert_k_cache
-> fused_deepseek_v4_quantize_and_insert_k_cache
compress_norm_rope_store_triton
-> fused_deepseek_v4_compress_norm_rope_store
compress_norm_rope_store_two_stage_triton
-> fused_deepseek_v4_compress_norm_rope_store_two_stage
The paged-K reader moves in from the module it arrived in, which retires:
dsv4_dequant_gather_k_cache.dequantize_and_gather_k_cache
-> fused_mxfp8_quant.fused_deepseek_v4_dequantize_and_gather_k_cache
_dsv4_dequant_gather_k_cache_kernel
-> _fused_deepseek_v4_dequant_gather_k_cache_kernel
It brought a second copy of _rec_geometry with it. The two differed only in
testing len(shape) rather than .dim(); the surviving copy keeps len(shape),
because vLLM's warmup hands it a TritonWarmupTensor, which carries a shape
and is not a torch.Tensor.
Tests
-----
The writer/reader pair had none, and the 640-byte aligned record -- the only
one production uses -- had no coverage below the end-to-end level:
- round-trip on both layouts against a torch decode of the stored bytes,
with the writer's quantization error bounded separately, so a layout bug
cannot hide inside the tolerance that the quantization needs
- the two layouts must decode bit-identically, at zero tolerance
- the single-pass and two-stage compressors must write the same cache
The last one matters because aiter's two compressor kernels each carry ~33
lines of full-width GPT-J RoPE with no counterpart in vLLM, so nothing
compared them against anything.
bench_fused_kv_compress_sparse_attn measured nothing
----------------------------------------------------
It built positions=0, and a token only emits when
(position + 1) % compress_ratio == 0, so every program took the early exit
and not one byte of the KV cache was written. Confirmed directly before the
fix: zero bytes changed by a launch. Every figure it has printed was launch
overhead.
Three things were wrong, all of which only mattered once tokens ran:
positions now cycle the emitting values, bounded so the gather stays
inside the block table
block_table was all zeros, so every token re-read row 0 and the whole
gather came from cache; now spread over the state cache
counted_bytes counted one state row per token, but an emitting token
reads (1 + overlap) * compress_ratio rows twice, once for
scores and once for values -- understating the read side by
~256x at cr128
With that fixed the split's gate is measured rather than assumed:
cr128 tokens=1024 single 218.1us two-stage 43.6us 5.00x
cr4 tokens=256 single 3.8us two-stage 5.5us 0.70x
which is why the caller restricts the two-stage path to cr >= 128.
New benchmarks
--------------
bench_fused_deepseek_v4_k_cache
writer and reader, both record layouts. Aligned writes ~43% faster than
packed (1022 vs 716 GB/s at seq 1024).
bench_fused_deepseek_v4_qnorm_rope_kv_insert
the producer with and without the fused Q pack, against the standalone
pack as a second kernel. Fusing is 1.23-1.88x, which is the question the
caller's pack-fusion switch exists to answer.
Noted, not fixed: the writer's use_fnuz guard reads `if not True:`, a port
slip from vLLM's current_platform.is_fp8_fnuz(), so it never fires.
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
One backend per PR: PR title tags & labels: |
There was a problem hiding this comment.
Remaining comments which cannot be posted as a review comment to avoid GitHub Rate Limit
ruff
Unnecessary dict() call (rewrite as a literal)
Unnecessary dict() call (rewrite as a literal)
Unnecessary dict() call (rewrite as a literal)
aiter/op_tests/op_benchmarks/triton/bench_fused_kv_compress_sparse_attn.py
Lines 106 to 137 in 5173003
Use format specifiers instead of percent format
aiter/op_tests/op_benchmarks/triton/bench_fused_kv_compress_sparse_attn.py
Lines 206 to 207 in 5173003
Use format specifiers instead of percent format
Function definition does not bind loop variable kwargs
Function definition does not bind loop variable kwargs
Function definition does not bind loop variable scratch
Use format specifiers instead of percent format
Unnecessary dict() call (rewrite as a literal)
Unnecessary dict() call (rewrite as a literal)
Unnecessary dict() call (rewrite as a literal)
aiter/op_tests/triton_tests/quant/test_quant_mxfp8.py
Lines 938 to 943 in 5173003
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
API compatibility, concurrency safety, unsupported compressor modes, and benchmark correctness issues remain unresolved.
Review effort: Balanced
Findings: 9
Open (32)
Process-global cache causes unsafe concurrent buffer reuse · New Cache dtype, device, and dimensionality are not validated · New Cache buffer dtype and layout are not validated · New RoPE output buffer dtype, device, and layout are unchecked · New FNUZ bytes are mislabeled as OCP FP8 · New Invalid 3-D cache record sizes are silently accepted · New Placeholder platform check allows unsupported FNUZ usage · New FP4 cache option always dispatches the FP8 kernel · New Unsupported two-stage configurations are not rejected · New Adding parameter breaks existing positional arguments · New GFX1250 tile and warp tuning is hardcoded · New RoPE input dtype is not validated as bfloat16 · New Warp tuning is hardcoded instead of loaded from config · New Producer warp tuning is hardcoded in the wrapper · New Compressor warp tuning is hardcoded in Python · New Split heuristic always uses device zero's CU count · New No-write-q split comparison quantizes uninitialized output · New cr4 benchmark times unsupported two-stage computation · New Benchmark never exercises pooled-stride cache layouts · New Pool mode is missing from benchmark memoization key · New
And 12 more that still need to be addressed.
What changed in this PR
Adds gfx1250 DeepSeek-V4 a8w8 sparse MLA with ATOM-compatible and aligned vLLM KV-cache formats.
Changes:
- Adds Q/KV quantization, compression, cache insertion, and gathering kernels.
- Extends sparse paged decode for packed FP8 Q/KV and dual cache streams.
- Adds correctness tests and performance benchmarks.
| File | Description |
|---|---|
aiter/ops/triton/attention/pa_decode_sparse.py |
Adds gfx1250 packed-FP8 decode dispatch. |
aiter/ops/triton/quant/fused_mxfp8_quant.py |
Adds public DSv4 producer and cache APIs. |
aiter/ops/triton/_triton_kernels/attention/pa_decode_sparse.py |
Extends split-K reduction metadata. |
aiter/ops/triton/_triton_kernels/quant/fused_mxfp8_quant.py |
Implements DSv4 quantization and compression kernels. |
op_tests/triton_tests/attention/test_pa_decode_sparse.py |
Tests packed, aligned, and dual-cache decode. |
op_tests/triton_tests/quant/test_quant_mxfp8.py |
Tests producer and cache formats. |
op_tests/op_benchmarks/triton/bench_pa_decode_sparse.py |
Benchmarks sparse decode providers. |
op_tests/op_benchmarks/triton/bench_fused_kv_compress_sparse_attn.py |
Benchmarks KV compression paths. |
op_tests/op_benchmarks/triton/bench_fused_deepseek_v4_qnorm_rope_kv_insert.py |
Benchmarks fused Q/KV production. |
op_tests/op_benchmarks/triton/bench_fused_deepseek_v4_k_cache.py |
Benchmarks K-cache read/write. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
|
Clude generated review: My take: Private wrapper name (_pa_decode_sparse_v4_2buff can be modified to be consistent with the other private wrappers. Naming it _pa_decode_sparse_gfx1250 would be more consistent. Correctness1. NaN when a tile has no valid keys (Gluon v4 kernel, ~L2135–2148) m_safe = gl.where(m_new == float("-inf"), 0.0, m_new)
p = gl.exp2(scores - m_safe[:, None])The non-exp2 epilogue (~L2275) has the same gap. It can't trigger today because 2. BLOCK_H=16 workaround doesn't cover every H (wrapper ~L1337–1359) 3. Gather kernel uses 4. int32 overflow in Q addressing (fused producer kernel ~L511–563, q-pack kernel L314) Should fix5. Empty token with 6. Silently ignored arguments on gfx1250 (wrapper ~L286–311, L1282) 7. Extra stream is read with the main stream's row strides (kernel ~L1291–1341, wrapper L1531–1532) 8. 9. FNUZ 10. Tests
Nits
|
…la-640 Conflicts (both sides added code at the same place): - fused_mxfp8_quant.py (kernel + wrapper), sparse_mla.py: keep main's DeepSeek-V4 / gfx950 fp8 additions and the fp8_k3_mla_640 helpers side by side. - pa_decode_sparse.py segment count: take main's (extra-stream aware); with no extra stream it equals the old cdiv(kv_len, KV_SPLITS * BLOCK_K). Follow-ups for main's pa_decode_sparse changes (#6116 and later): - The reduce kernel is base-2 only (USE_EXP2 removed): the HAS_LSE epilogue now always converts m with LN2, and _forward_k3_640 no longer passes USE_EXP2. - The reduce takes extra_indptr and HAS_EXTRA: _forward_k3_640 passes kv_indptr as a placeholder with HAS_EXTRA=False (no extra key stream). - ruff/black: sorted imports in sparse_mla.py, dict literals in the K3.1 test.



This PR adds a8w8 sparse MLA for gfx1250 with vLLM-compatible kv_cache related kernels with the ATOM-style kv_cache format support [448B + 72B + 50B padding + 642B]
Notice on the API change:
removed use_exp2
removed kv_scales