Repository navigation
[Feat] [AMD] minimax: gfx950 sparse attention, NVFP4 KV and DSpark verify kernels - #46690
Merged
Merged
Conversation
…rify kernels Kernels for MiniMax-M3.1-Flash on MI350X / MI355X with no callers yet: the NVFP4 sparse decode and Gluon prefill, the verify top-k indexer, QK-norm + RoPE, the NVFP4 KV and HiCache page-row paths, and the DSpark draft / accept kernels. Co-Authored-By: Claude Opus 5.5 <[email protected]>
… kernels - gluon_prefill: `_get_scratch` always allocates the scratch at bf16 width and only views it as fp8, so "256 MiB at fp8" and the grow step's "at bf16" misstated the footprint; the grow-step line is back to main's. - dspark kernel parity test: the HIP-only case list holds the TP-shard argmax as well as the step bias, so the comment names both. - verify_mla: the 13-26% speedup is a benchmark result for the PR body; the line only needs where num_stages=2 was measured. - index_topk_gfx950: reflow a three-line comment whose last line was a single word. Co-Authored-By: Claude Opus 5.5 <[email protected]>
"as in the Triton kernel" read as if a Triton NVFP4 decode kernel existed; the attention has only the Gluon kernel, and what it matches up to fp32 rounding is the bf16 Triton decode kernel run on the dequantized cache, the comparison test_minimax_nvfp4_sparse_decode makes. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ke it `verify_topk_idx` and `_use_fused_index_topk` both branch on `isinstance(k_cache, Nvfp4Cache)`, but their signatures still said `torch.Tensor`; the sibling `_use_fused_verify_topk` already spells `torch.Tensor | Nvfp4Cache`. Annotation only. Co-Authored-By: Claude Opus 5.5 <[email protected]>
`scale_cast_to_cache` and `cache_inv_scale` are used only inside minimax_m3_qk_norm_rope.py (here and in every later branch of the series), and every other helper the fused cache kernel calls is `_`-prefixed; the public names suggested an API other modules import. Co-Authored-By: Claude Opus 5.5 <[email protected]>
`_gluon_sparse_prefill_group` ran `isinstance(k_cache, Nvfp4Cache)` for the KV-scale tensors and again three lines later for the scratch dtype; bind it once before both. `k_cache` is only rebound after the gather, below either use, so the two checks always agreed. Co-Authored-By: Claude Opus 5.5 <[email protected]>
- accept_greedy_target_predict looped over method-name strings and resolved them with getattr; iterate over `AcceptGreedy.torch` / `AcceptGreedy.triton` themselves, as the module docstring says every case does. - markov_step_bias imported `MarkovStepBias` midway through the case and re-bound it as `cls`; import it first, like the TP-shard argmax case, and drop the alias. Same inputs, same seeds, same assertions. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ason test/README.md requires a file registered on CUDA plus another accelerator to carry a `backend-specific:` comment above the extra registration naming what only that backend catches. Here that is the gfx950-only step-bias and TP-shard argmax cases, which `_CASES` gates on `torch.version.hip`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
kevin-mii
requested review from
BBuf,
DarkSharpness,
HaiShaw,
HydraQYH,
celve and
yuan-luo
as code owners
October 27, 2026 00:28
This was referenced Oct 27, 2026
Merged
Collaborator
Author
|
/tag-and-rerun-ci |
…bits At the M3.1 draft's full 200,064-row vocab, MarkovStepBias is not bitwise equal to the embedding + F.linear step bias it replaced (about 0.01% of elements differ at 1 and 8 tokens), and it saved only 27-45 us of a decode step. HIP now runs the same VanillaMarkov path as CUDA. Co-Authored-By: Claude Opus 5.5 <[email protected]>
`nvfp4_kv_quantize` has no production caller: the pool quantizes through the fused qk-norm kernel, and only the gfx950 kernel tests use the Triton quantizer to build their packed caches. It moves from `kernels/ops/quantization/nvfp4_kv_triton.py` to `sglang/test/kernels/nvfp4_kv.py`, beside the other test-only kernels, and takes `nvfp4_quantize_rows`, its only user, out of `common/nvfp4.py`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The gfx950 NVFP4 kernel tests only need a packed cache to feed the kernels; they check each kernel against another run on the same bytes or against their own dequantization, never the quantizer. Main's NVFP4 quantizers are FlashInfer's, so the tests carried a Triton kernel; a dozen lines of torch do the same job. It writes the same bytes (checked against the Triton kernel on random, tiny, large, zero and e2m1-boundary inputs at two global scales), saturating an out-of-range block scale at 448 as the hardware conversion does instead of torch's NaN. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…store Their only callers, the gfx950 deferred verify-logits gather and the stacked DSpark context-K/V writer, left the integration PR: measured on and off at TP4 neither moved decode TPOT past run-to-run noise outside simulated-acceptance benchmarks. dspark_accept's precomputed target_predict goes with the argmax. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ferences sglang/test/quant_ref_utils.py already holds the hand-written NVFP4 references the parity tests check srt against (independent of srt, e2m1 and E4M3 constants included), so the torch NVFP4 KV quantizer moves there from its own sglang/test/kernels/nvfp4_kv.py and reuses FLOAT4_E2M1_MAX and FLOAT8_E4M3_MAX. Same bytes. Co-Authored-By: Claude Opus 5.5 <[email protected]>
… like its siblings The kernel imports the CDNA4 buffer and MFMA ops, so it runs on gfx950 only, as do index_topk_gfx950, verify_topk_gfx950 and nvfp4_decode_gfx950 next to it; the package names such kernels with the arch (kda_fused_decode_gfx950, mla_v4_decode_gfx950). gluon_prefill_pair.py becomes gluon_prefill_pair_gfx950.py. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…dexer cannot import The fused index top-k imports Gluon's CDNA4 module; on a gfx950 image whose Triton lacks it, main's prefill indexer raised instead of keeping the Triton kernel. The guard matches the verify indexer's and the NVFP4 decode's. Co-Authored-By: Claude Opus 5.5 <[email protected]>
flash_decode_with_gqa_share_sparse, flash_prefill_with_topk_index and the Gluon prefill's gather, gate and group take an Nvfp4Cache since this series but were still annotated torch.Tensor. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The verify merge writes a caller's out as flat rows through stride(1), so a multi-head out with a padded head stride landed rows in the wrong head; it now asserts the shape, dtype and row layout as select_decode_topk does. The prefill indexer's gate now requires unit-stride q columns, which its loads assume. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ANG_USE_AITER fp8_utils binds aiter_per1x128_quant only when SGLANG_USE_AITER=1, so the pair-prefill fp8 epilogue test failed to import under plain pytest. Co-Authored-By: Claude Opus 5.5 <[email protected]>
kevin-mii
requested review from
Fridge003,
Qiaolin-Yu,
hebiao064,
ispobock and
merrymercy
as code owners
October 28, 2026 05:59
Collaborator
Author
|
CI at
|
The module held the NVFP4 verify scorer and a wrapper around the gfx950 decode kernel, so its name said decode while most of it was the indexer. The scorer now sits beside its fp8 counterpart in verify_topk_idx.py, and topk_sparse.py's Nvfp4Cache branch gates and calls the Gluon kernel itself. No behavior changes: the same kernels run with the same arguments, and a tensor cache, which is all CUDA passes, never reaches the branch. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…show Drop the bandwidth numbers from measured-on notes, split multi-line docstring summaries into a summary line and one paragraph, use double backticks in docstrings, and make each file's comments one sentence style. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ndow.py The windowed combine kernel, its tile table and row choice, and the stage-1 pipelining it needs now live in WindowedVerifyMLA, a VerifyMLA subclass. The shared module keeps only what the window needs from it: the stage-1 prefix mask (a constexpr, compiled out without a window), the caller's opt-in in can_handle, and the class hooks (block_config, prefix_num_stages) the subclass sets. Outputs are bitwise equal to the single-module version for the M3.1 window at 1-64 requests and for the Qwen3.5 and Kimi-K3 verify shapes. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ot show The module docstring says why one pass suffices (every draft key sits inside the window), the class docstring names the non-causal constraint can_handle enforces, and the comments share one style. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Collaborator
Author
|
CI at
|
Picks up sgl-project#47127, which fixes main's test_gdn_prefill_graph that pr-test-finish fails on. Co-Authored-By: Claude Opus 5.5 <[email protected]>
hnyls2002
approved these changes
Nov 1, 2026
Merged
5 tasks done
4 of 5 tasks
This was referenced Nov 17, 2026
Merged
1 task done
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
minimax_sparse/common/nvfp4.pyreads the packed rows for the Triton kernels andnvfp4_gfx950.pydequantizes them in Gluon. The kernel tests build their packed caches with a torch quantizer inNVFP4KVQuantizeUtil's layout (nvfp4_kv_quantizeinsglang/test/quant_ref_utils.py).decode/nvfp4_decode_gfx950.pyruns sparse decode over the packed NVFP4 K/V in Gluon (one program per row, top-k chunk and KV head; per-warp online softmax).topk_sparse.pydispatches anNvfp4Cacheto it, and the NVFP4 verify scorer sits beside the bf16 one indecode/verify_topk_idx.py.decode/verify_topk_idx.pyscores a linear draft chain against one shared prefix;decode/verify_topk_gfx950.pyfuses the per-block max score with a streaming top-k on MFMA tiles.prefill/index_topk_gfx950.pyis the fused prefill indexer;prefill/gluon_prefill_pair_gfx950.pyruns two queries per program over the union of their top-k blocks;prefill/nvfp4_prefill.pygathers the NVFP4 cache into the Gluon prefill's paged layout;prefill/gluon_prefill.pyandprefill/flash_with_topk_idx.pytake the new cache.common/out_quant_gfx950.pyis shared by the Gluon decode and pair prefill: they can write O directly as the fp8 o_proj input, with the same bytes and scales as aiter's separate per-token or 1x128 quant.minimax_m3_qk_norm_rope.pyadds the gfx950 fused Gemma Q/K RMSNorm + partial RoPE + KV-cache write.verify_mla_window.pylets the gfx950 grouped-head split-KV verify serve the DSpark draft's sliding window (its non-causal draft block, window 4095) with a one-pass combine, as aVerifyMLAsubclass;num_stages=2was 13-26% faster for that window. The sharedverify_mla.pyonly gains the stage-1 window mask (a constexpr, compiled out without a window), the caller's opt-in incan_handle, and the two class hooks the subclass sets; Qwen3.5 and Kimi-K3 verify outputs are bitwise unchanged.o_proj, windowed draft verify) are in the integration PR.Serving gain of each kernel
Measured in the integration PR at TP4 on MI350X (NVFP4 KV, DSpark acceptance simulated at 3 tokens per step, 32K-token contexts), each change turned off alone; the share decode TPOT or prefill latency grows without it, mean of two GPU sets:
verify_mla_window): decode TPOT +20.6% at 1 request, +8.2-9.6% at 8-64.gluon_prefill_pair_gfx950): 32K-token prefill +10.3%, decode +4.2-5.4% at 8-64.SGLANG_MINIMAX_M3_AMD_KV_FORMAT=fp8): prefill +11.7% (32K tokens) and +12.4% (eight 8K requests).Changes to existing kernels
On CUDA nothing changes:
topk_sparseonly dispatches the newNvfp4Cachetype, the decode top-k only moves intoselect_decode_topk, and the page-row quota stays 2.On gfx950, main's MiniMax-M3 layers switch kernels when this merges, with no new call site:
sparse_qk_index_gemma_rmsnorm_rope_cache) runs the tiled kernel for M3's 128-wide head with 64-dim neox RoPE; its bf16 outputs equal the per-head kernel's bit for bit.minimax_sparse_prefillnow passes on; before, an fp8 pool stayed on Triton. Both match the Triton kernel up to bf16 rounding.On other ROCm GPUs, the per-head QK-norm kernel, which serves them (and gfx950 heads other than M3's), no longer writes main K/V to slot 0, the reserved CUDA-graph padding slot. The unfused
store_cachealready skips it, and no real token is stored there.Verification
rocm/sgl-dev:v0.5.20-rocm720-mi35x-20260926, AITERacf8fdf93,SGLANG_USE_AITER=1), this branch alone onmain:test_minimax_gfx950_prefill35 passed,test_minimax_m3_qk_norm_rope55,test_minimax_nvfp4_sparse_decode13,test_minimax_verify_topk_idx68 (the kernel cases; the integration PR adds 8 more),test_verify_shared_kv10. pre-commit clean; main's callers of every modified kernel module import.🤖 Generated with Claude Code
CI States
Latest PR Test (Base): ✅ Run #40902705557
Latest PR Test (Extra): ❌ Run #40902705801
Latest PR Test (AMD ROCm 10): ❌ Run #40902705369