Skip to content

[TRITON][GLUON] Add DSv4 sparse MLA prefill Triton and unified with MLA Gluon kernel on GFX950 - #3833

Merged
Dewei-Wang-sh merged 12 commits into
ROCm:mainfrom
leonling-ll:liyang/dsv4_sparse_attn_prefill
Jul 5, 2026
Merged

[TRITON][GLUON] Add DSv4 sparse MLA prefill Triton and unified with MLA Gluon kernel on GFX950#3833
Dewei-Wang-sh merged 12 commits into
ROCm:mainfrom
leonling-ll:liyang/dsv4_sparse_attn_prefill

Conversation

@leonling-ll

@leonling-ll leonling-ll commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

This PR aims to add sparse attention prefill kernel (triton + gluon gfx950).

The triton kernels are adapted from vLLM mla_sparse_dsv4 with enabling triton autotune.

It reuses mla_decode_gluon and unifies as mla_gluon kernel for both mla decode and sparse prefill.

The prefill performance status:

Q H Kv topk triton ms triton TFLOPS gluon ms gluon TFLOPS speedup
4096 128 4096 512 1.788 192.035 0.8562 400.964 2.09x
4096 128 4096 1024 3.260 209.629 1.313 520.291 2.48x
8192 128 8192 512 3.572 191.414 1.663 411.194 2.15x
8192 128 8192 1024 6.490 212.226 2.669 516.077 2.43x

This table can be reproduce with:

python bench_sparse_attention_dsv4.py --shapes prefill

This PR is split from #3456 as the first part.

@leonling-ll
leonling-ll requested review from a team, Dewei-Wang-sh and Copilot June 22, 2026 02:55
@github-actions

Copy link
Copy Markdown
Contributor

🏷️ CI Guide

Runs automatically on every PR:

  • ✅ Pre-checks (submodule verification, code formatting)
  • ✅ Aiter op tests (gfx942 + gfx950)
  • ✅ Triton tests on MI35X (only when aiter/ops/triton/** or related paths are changed)

Extended tests (opt-in via labels):

Label Tests
ci:triton-300x Run an additional Triton test job on MI300X in PRs; main branch always runs both MI35X and MI300X
ci:sglang SGLang integration tests: DeepSeek-R1-MXFP4 accuracy, Qwen 3.5 accuracy
ci:atom ATOM benchmark: DeepSeek-R1-0528, GPT-OSS-120B
ci:atom_full ATOM accuracy suite for PR and main models from ATOM models_accuracy.json
ci:vllm vLLM benchmark: GPT-OSS-120B, DeepSeek-R1-0528, Kimi-K2.5
ci:all All standard extended tests (excludes ci:atom_full)

Only add ci:atom_full for FlyDSL or Triton upgrades.
Add labels via the sidebar or gh pr edit 3833 --add-label <label>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds DeepSeek V4 sparse MLA prefill support to AITer, including a Triton implementation (with autotune) and an optimized Gluon (CDNA4/gfx950) kernel, plus wrappers/tests/benchmarks to validate and measure performance.

Changes:

  • Introduces Triton sparse-attention prefill kernel + ragged-index preparation kernels and autotune configs.
  • Adds a gfx950 Gluon sparse-attention prefill kernel and a wrapper that selects Gluon when available.
  • Adds an accuracy/perf test and a benchmark driver, and documents the new Gluon kernel.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
op_tests/test_sparse_attention_dsv4.py Adds a torch reference + correctness/perf test harness for sparse prefill.
op_tests/op_benchmarks/triton/bench_sparse_attention_dsv4.py Adds a Triton vs Gluon benchmark runner and reporting.
aiter/ops/triton/gluon/sparse_attention_dsv4.py Implements the gfx950 Gluon sparse MLA prefill kernel + host launcher.
aiter/ops/triton/gluon/README.md Documents the new Gluon sparse-attention kernel and how to run tests/benchmarks.
aiter/ops/triton/attention/sparse_attention_dsv4.py Adds the public wrapper API, dense→CSR packing helpers, and Gluon gating logic.
aiter/ops/triton/_triton_kernels/attention/sparse_attention_dsv4.py Adds Triton kernels for index packing and sparse prefill (autotuned).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread aiter/ops/triton/attention/sparse_attention_dsv4.py Outdated
Comment thread aiter/ops/triton/attention/sparse_attention_dsv4.py Outdated
Comment thread aiter/ops/triton/_triton_kernels/attention/sparse_attention_dsv4.py
Comment thread aiter/ops/triton/gluon/README.md Outdated
Comment thread aiter/ops/triton/gluon/README.md Outdated
Comment thread aiter/ops/triton/gluon/README.md Outdated
Comment thread aiter/ops/triton/_triton_kernels/attention/sparse_attention_dsv4.py
Comment thread aiter/ops/triton/gluon/README.md Outdated
@leonling-ll
leonling-ll force-pushed the liyang/dsv4_sparse_attn_prefill branch from d605eb9 to 3e79696 Compare June 22, 2026 05:31

@Dewei-Wang-sh Dewei-Wang-sh left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reuse the mla_decode_gluon to relieve maintain burden.

@leonling-ll
leonling-ll force-pushed the liyang/dsv4_sparse_attn_prefill branch 3 times, most recently from 356fd58 to 7813e7a Compare June 24, 2026 05:58
Prefill-only slice of the DSV4 compressed sparse attention work: bf16 KV
flat-buffer prefill kernel (Triton + persistent Gluon), the ragged-index
builders + host launcher, and the prefill test/benchmark. Decode (fp8_ds_mla
paged cache) is intentionally excluded from this branch.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

Resolve the code style check failure

Address Comments
Fix format

Unify dsv4 sparse attn and mla_decode
@leonling-ll
leonling-ll force-pushed the liyang/dsv4_sparse_attn_prefill branch from 7813e7a to e31de73 Compare June 24, 2026 07:48
@leonling-ll leonling-ll changed the title [TRITON][GLUON] Add DSv4 sparse MLA prefill kernel Triton + Gluon for gfx950 [TRITON][GLUON] Add DSv4 sparse MLA prefill Triton and unify MLA Gluon kernel for decode on GFX950 Jun 24, 2026
@leonling-ll leonling-ll changed the title [TRITON][GLUON] Add DSv4 sparse MLA prefill Triton and unify MLA Gluon kernel for decode on GFX950 [TRITON][GLUON] Add DSv4 sparse MLA prefill Triton and unified with MLA Gluon kernel on GFX950 Jun 24, 2026
@zufayu
zufayu requested review from yzhou103 and removed request for yzhou103 June 26, 2026 06:14
Comment thread aiter/ops/triton/gluon/mla_gluon.py Outdated
Comment thread aiter/ops/triton/gluon/mla_gluon.py Outdated
Comment thread aiter/ops/triton/gluon/mla_gluon.py Outdated
Comment thread aiter/ops/triton/gluon/mla_gluon.py Outdated
Comment thread aiter/ops/triton/gluon/mla_gluon.py Outdated
Comment thread aiter/ops/triton/gluon/mla_gluon.py Outdated
Comment thread aiter/ops/triton/gluon/mla_gluon.py Outdated
@Dewei-Wang-sh

Copy link
Copy Markdown
Contributor

overall, we should keep it additive and add comments about env/change, keep it concise and clear.

@leonling-ll
leonling-ll force-pushed the liyang/dsv4_sparse_attn_prefill branch from a4a6e7a to a89a80b Compare June 30, 2026 16:21
Comment thread aiter/ops/triton/gluon/mla_gluon.py Outdated
Comment thread aiter/ops/triton/gluon/mla_gluon.py Outdated
Comment thread aiter/ops/triton/gluon/mla_gluon.py Outdated
Comment thread aiter/ops/triton/gluon/mla_gluon.py Outdated
Comment thread aiter/ops/triton/gluon/mla_gluon.py Outdated
@leonling-ll
leonling-ll force-pushed the liyang/dsv4_sparse_attn_prefill branch 3 times, most recently from 5e7ba56 to 708895d Compare July 2, 2026 08:53
Address review comments

Minimize changes

The dev branch selected DeepSeek V4 sparse prefill via a `mode="decode" |
"dsv4-prefill"` string that drove a separate wrapper branch duplicating the
whole bh64 decode setup. Replace it with a `has_pe=True` flag (HAS_PE=False =>
prefill) and collapse the duplicated branch back onto main's single-path
decode wrapper, adding prefill support as minimal inline guards:

- q_pe may be None (fixed head_dim_kpe=64), small `if not has_pe` block aliases
  the unused q_pe/k_pe placeholders and forces kv_pe_offset=0 / use_2d_view=False
- bh64 regime: has_pe keeps the split auto-pick + asserts; else NUM_KV_SPLITS=1
  with a batch % 64 guard
- unified bh64 grid (cdiv(batch, NUM_XCDS) * NUM_KV_SPLITS) covers both paths

Callers (sparse_attention_dsv4, bench_sparse_attention_dsv4) pass has_pe=False.

Verified on gfx950: test_mla decode (bh64/bh16bn64/bh16bn128, +lse/varlen) and
test_sparse_attention_dsv4 prefill (+sink) all pass; benchmark shows prefill is
performance-neutral vs the pre-refactor version (within +-1%).
@leonling-ll
leonling-ll force-pushed the liyang/dsv4_sparse_attn_prefill branch from 708895d to 0f4d2e2 Compare July 2, 2026 09:00
Comment thread aiter/ops/triton/gluon/mla_gluon.py
Comment thread aiter/ops/triton/gluon/mla_gluon.py Outdated
Comment thread aiter/ops/triton/gluon/mla_gluon.py
@leonling-ll
leonling-ll requested a review from Dewei-Wang-sh July 2, 2026 09:05
Comment thread aiter/ops/triton/gluon/mla_gluon.py Outdated
Comment thread aiter/ops/triton/gluon/mla_gluon.py Outdated
@leonling-ll
leonling-ll force-pushed the liyang/dsv4_sparse_attn_prefill branch 2 times, most recently from cd2912a to bdbd317 Compare July 3, 2026 04:32
@leonling-ll
leonling-ll force-pushed the liyang/dsv4_sparse_attn_prefill branch from bdbd317 to 87e062c Compare July 3, 2026 04:55

@Dewei-Wang-sh Dewei-Wang-sh left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@Dewei-Wang-sh
Dewei-Wang-sh merged commit b50066a into ROCm:main Jul 5, 2026
56 checks passed
@leonling-ll
leonling-ll deleted the liyang/dsv4_sparse_attn_prefill branch July 6, 2026 02:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants