Repository navigation
[Feat] [NVIDIA] attention: Support DSA dense prefill on SM120 - #51473
Conversation
|
@Fridge003 could you take a look at this PR when you have a chance? This adds SM120 support for DSA dense one-shot prefill by routing the SM12x path to the existing FA4 varlen implementation, while leaving the existing SM100 and SM90 paths unchanged. I validated the path on an RTX 5090 with the capability test, DSA integration test, and the SM120 FA4 kernel contract test. Could you help trigger CI and review it? Thanks! |
|
[BBuf Review Agent] Thanks for the PR. Before it goes into review, could you add these to the description?
|
BBuf
left a comment
There was a problem hiding this comment.
[BBuf Review Agent] A few things to fix before this can go in.
|
Thanks for the detailed review. I have seen all three comments and am working through them. I will update the implementation to handle the return-indexer capture path correctly and to keep prefill on the sparse path when I am also preparing an SM120 setup with a public real DSA checkpoint. I will add base/head prefill results at 512, 1024, and 2048 tokens, plus a prompt above the dense threshold, and run the requested end-to-end accuracy and FP8 KV-cache validation on the same checkpoint. This may take a little time because of the model size and GPU requirements, but I am actively working on it and will update the PR with both the fixes and the results. Thanks! |
94bb88e to
589ea59
Compare
|
[BBuf Review Agent] The only numbers I need are base/head prefill times at 512, 1024 and 2048 tokens on SM120 with BF16 and FP8 KV, since every DSA prefill up to the 2048 threshold now switches to dense FA4. Layer-level attention timings at the real DSA shapes are fine if a full checkpoint doesn't fit; longer prompts don't change path, so skip them. |
|
@BBuf Thanks for the clarification. I have completed the requested layer-level base/head measurements on an RTX 5090 (SM120) at the public GLM-5 DSA shapes, covering 512, 1024, and 2048 tokens with both BF16 and FP8 KV pools. I ran the benchmark twice and obtained consistent results; dense FA4 was faster than the runnable sparse baseline in every case. The methodology, environment, results, and BF16 backend caveat are now included in the PR description. The requested code-path fixes are already present in the current PR head. |
|
[BBuf Review Agent] @lingxling The 5090 table covers the BF16 and FP8 KV comparisons I asked for, and the numbers look good. I also checked both sparse-path guards at |
Thanks for confirming the measurements and both sparse-path guards. All review threads are now addressed and resolved. Could you please help move the PR forward and trigger CI when convenient? @BBuf |
|
[BBuf Review Agent] @lingxling The 5090 test |
|
Fixed in |
|
[BBuf Review Agent] @lingxling Checked |
BBuf
left a comment
There was a problem hiding this comment.
[BBuf Review Agent] LGTM. Let's wait for CI.
|
/tag-and-rerun-ci |
|
[sglang-bot Review Agent] Could you merge the latest main into this branch? CI's maintenance gate won't run the tests until it does. |
|
/tag-and-rerun-ci |
|
No commit was approved for CI: lingxling has neither write access nor can_tag_run_ci_label in .github/CI_PERMISSIONS.json. |
|
⛔ CI skipped its tests, so nothing was re-run. To run them, have a maintainer approve this commit ( |
|
/rerun-failed-ci |
|
⛔ CI skipped its tests, so nothing was re-run. To run them, have a maintainer approve this commit ( |
|
/rerun-failed-ci |
|
⛔ CI skipped its tests, so nothing was re-run. To run them, have a maintainer approve this commit ( |
|
Hi @sglang-bot, thanks for reviewing the latest commit. I tried Could you please run |
|
[sglang-bot Review Agent] @lingxling I’m good with running CI on |
sglang-bot
left a comment
There was a problem hiding this comment.
[sglang-bot Review Agent] LGTM. Let's wait for CI.
|
/tag-and-rerun-ci |
|
[sglang-bot Review Agent] Could you rebase this onto the latest main? It conflicts with main now. |
d99a7dc to
6b58a14
Compare
|
Rebased onto the latest main ( |
|
[sglang-bot Review Agent] @lingxling Confirmed |
|
/rerun-failed-ci |
|
⛔ CI skipped its tests, so nothing was re-run. To run them, have a maintainer approve this commit ( |
sglang-bot
left a comment
There was a problem hiding this comment.
[sglang-bot Review Agent] LGTM. Let's wait for CI.
|
/tag-and-rerun-ci |
|
/rerun-failed-ci |
|
@sglang-bot I’ve merged the latest main into this branch as requested. The new head is Could you please approve the new head for CI and trigger |
|
/tag-and-rerun-ci |
|
/rerun-failed-ci |
|
[sglang-bot Review Agent] @lingxling these still fail after a rerun, and I can't tell from the logs whether it's this PR. Could you take a look?
|
|
/tag-and-rerun-ci |
Motivation
Fixes #51472.
SGLANG_DSA_PREFILL_DENSE_ATTN_KV_LEN_THRESHOLDcontrols when an eligible DSA prefill batch uses dense one-shot attention instead of sparse attention. SM120 is currently excluded from that selection, so setting the threshold on an RTX 5090 has no effect.The existing CUDA dispatch cannot be enabled by changing only the architecture gate:
_forward_standard_mha()sends every CUDA architecture with major version 10 or newer toflashinfer.prefill.trtllm_ragged_attention_deepseek, whoseTllmGenFmhaRunnerrejects SM120 withUnsupported architecture.SGLang already ships an architecture-owned SM120 FA4 varlen implementation. Fixed-random-input validation on an RTX 5090 shows that it supports the packed ragged BF16 attention contract consumed by DSA dense one-shot prefill, including causal attention and asymmetric Q/K/V dimensions. This change wires that existing implementation into DSA dense one-shot prefill without changing the SM100-family or SM90 kernel paths.
Modifications
MHA_ONE_SHOTselection on CUDA SM120 when the existing length, dtype, chunk-capacity, CP, and HiSparse conditions are satisfied.sglang.kernels.ops.attention.flash_attention_v4_sm120.flash_attn_varlen_funcbefore the existing TRT-LLM branch.--enable-return-indexer-topkis active, because dense MHA does not run the indexer and therefore cannot populate its capture buffer.SGLANG_SKIP_SOFTMAX_PREFILL_THRESHOLD_SCALE_FACTORis set, because the dense FA4 path does not consume that sparse FlashInfer option.MHA_ONE_SHOTselection instead of silently skipping, exercises ragged requests with non-empty prefixes, and compares the result with an independent PyTorch attention reference.The existing SM120 FA4 kernel tests provide additional coverage for packed ragged BF16 attention and asymmetric Q/K/V dimensions against a PyTorch reference.
Accuracy Tests
python3 test/registered/unit/layers/attention/test_dsa_dense_one_shot_support.py -v CUDA_VISIBLE_DEVICES=0 python3 \ test/registered/attention/unittests/dsa/test_dsa_sm120_dense.py -v CUDA_VISIBLE_DEVICES=0 python3 -m pytest -q \ 'test/registered/kernels/ops/attention/test_flash_attention_4_sm120.py::test_sm120_varlen_feature_matrix_matches_reference[bf16-gqa-hd192-hdv128-causal-local-splitkv]'The CPU tests cover the architecture gate and the two sparse-only runtime options. The integration test forces
MHA_ONE_SHOTselection and compares the result with an independent PyTorch reference; the existing FA4 test additionally covers asymmetric Q/K/V dimensions.Speed Tests and Profiling
The layer-level comparison was run twice on one RTX 5090 at the public GLM-5 DSA dimensions (64 heads, QK 256, V 256, KV LoRA rank 512, top-k 2048). Each result is the median of 100 iterations after 10 warmups for a batch-one, prefix-free causal prefill. The measured kernel sources match PR head
ff3117691dbyte-for-byte.The FP8 baseline is the current GLM/SM120
flashinfer_sparse_mlaroute. Because FlashMLA BF16 sparse prefill rejects SM120, the runnabletriton_sparse_mlabackend is used for the BF16 baseline. Prefix-free dense one-shot consumes fresh BF16 K/V in both KV-pool modes. Cache packing is outside the timed attention region. A second run was consistent with the table, and every output had the expected shape with finite values.Environment: RTX 5090 (SM120), driver 595.71.05, CUDA 13.0, PyTorch 2.14.1+cu130, FlashInfer 0.7.4, Triton 3.8.0, and nvidia-cutlass-dsl 4.8.0.
The SM90, SM100-family, ROCm, and normal sparse-prefill paths are unchanged.
Checklist
Review and Merge Process
/tag-and-rerun-ci,/tag-run-ci-label,/rerun-failed-ciCI States
Latest PR Test (Base): ✅ Run #46248876197⚠️ Run #46248879353
Latest PR Test (Extra): ⊘ Skipped -- add the
run-ci-nv-extralabel to opt in.Latest PR Test (AMD ROCm 10):
Tip
Base CI only covers the core cases, and its workload may not exercise your change. Use
/rerun-testto run the tests your change touches, or copy this prompt for an agent: