Skip to content

[Triton/Gluon] Route short sliding-window queries to the gfx950 split grid - #6594

Merged
azaidy merged 4 commits into
ROCm:mainfrom
hongxiayang:muse-dspark-short-query-3d
Oct 29, 2026
Merged

azaidy merged 4 commits into
ROCm:mainfrom
hongxiayang:muse-dspark-short-query-3d

Conversation

@hongxiayang

@hongxiayang hongxiayang commented Oct 15, 2026 •

Copy link
Copy Markdown
Collaborator

Motivation

Muse Spark Open's DSpark speculative decoding verifies 8 tokens per request (7 drafts + 1) on layers with a 2,048-token sliding window. On Day 0, the vLLM image's aiter build sped these batches up behind AITER_UNIFIED_ATTN_SHORT_QUERY_3D=1 (blog). This PR covers the sliding-window case, so Muse gets the Day 0 gain from upstream aiter without using a flag.

attn_2d config entries plus one new matcher axis

co-authors: @giuseppegrossi @cagrikymk

Technical Details

  • unified_attention_utils.py: new numeric axis P, the 2D grid's programs per CU: next_power_of_2(cdiv(num_2d_prgms, num_sms)). It is part of the lookup's cache key and of explain(). Rounding to a power of 2 keeps the cache small, so P bounds must be powers of 2.
  • gfx950 gluon DEFAULT.json: the attn_2d schema becomes ["D", "Q", "P", "SW", "SKLT", "DT"], with four new entries. No existing entry mentions Q or P, so every other lookup is unchanged.
Entry BLOCK_M num_warps
D_LEQ_64.Q_LEQ_2.P_LEQ_8.SW.DT_bf16_bf16 16 1
D_LEQ_64.Q_LEQ_4.P_LEQ_8.SW.DT_bf16_bf16 32 2
D_LEQ_64.Q_LEQ_8.P_LEQ_8.SW.DT_bf16_bf16 64 4
D_LEQ_64.Q_LEQ_16.P_LEQ_8.SW.DT_bf16_bf16 128 8

All four use MFMA 16, waves_per_eu 1, 2 buffers and a 64 tile.

  • Why P_LEQ_8: decode-style settings win while CUs are idle and lose once the grid fills the GPU. P_LEQ_8 (at most 2,048 programs on 256 CUs) is where they stop winning. Without it, Muse drops to 0.61–0.80x of main at batch 256–512.
  • Same launch as Day 0: at 8 query heads per KV head (Muse), the q <= 8 entry gives the launch the Day 0 flag picks on sliding-window layers: BLOCK_M 64, 4 warps, MFMA 16, waves_per_eu 1.
  • Scope: head size <= 64, bf16 query and KV, sliding window. fp8 keeps main's entries. The DT_bf16_bf16 tag is required: fp8 with MFMA 16 uses the 16x16x128 instruction, which needs a tile of at least 128. fp8 and larger head sizes can get their own entries later.
  • unified_attention.py: identical to main.
  • Tests: test_triton_unified_attn_3d gains spec-decode cases ([(2, 8704), (7, 8704)], [(8, 8704)] * 32) and sliding_window=2048.

Test Plan

On one MI355X node in rocm/pytorch:rocm7.2.4_ubuntu24.04_py3.12_pytorch_release_2.10.0:

  • op_tests/triton_tests/attention/test_unified_attention.py, split over 8 GPUs.
  • Kernel-level timing of unified_attention(..., backend="gluon") against main on 4,212 shapes:
    • Main grid: head size 64/128/256; bf16 and fp8; 16/2 and 64/8 heads; window 128/512/1024/2048 plus full attention; q 2/8/16; batch 1–512; KV 1k/4k/16k; 64-token pages.
    • Edge grid: 8/8 and 16/8 heads, q up to 128.
    • Warm (CUDA graph replay) and cold (L2 flushed) times, best of 3 rounds.
  • Muse's verify shape (16/2 heads, D64, window 2048, q=8, bf16) as vLLM calls it: packed LBHNC KV cache, 16-token pages, best of 5 rounds.

Test Result

  • Unit tests: 2,626 passed, 0 failed (1,952 skipped by the file's own conditions).
  • Muse verify shape with vLLM's LBHNC cache and 16-token pages, speedup vs main (warm / cold):
Batch (requests) Speedup
1–64 1.39–1.49x / 1.18–1.36x
128 1.02–1.06x / 0.94–0.95x
256–512 unchanged (main's entry)

With plain K/V caches and 64-token pages, batch 1–64 is 1.37–1.67x / 1.40–1.71x. The DSpark recipe caps the server at 64 requests.

  • All 4,212 shapes vs main:
Version Shapes whose launch differs from main Of those, more than 5% slower Worst (warm / cold)
This revision 348 14 0.82x / 0.89x
Same entries without P_LEQ_8 540 141 0.40x / 0.58x
Previous revision (3D config in the 2D launch) 2,596 357 0.54x / 0.72x

The three worst are 16/2 heads with a 128-token window at batch 128 (0.82x warm). The other 11 are at 0.89x or better.

Submission Checklist

… grid

Spec-decode verify batches (q <= 8, kv >= 512, <= 1024 tokens) on sliding-window layers were forced onto the 2D prefill grid. On MI355X with Muse Spark Open DSpark shapes (16/2 heads, D=64, window 2048, kv 8704), the split grid is 1.13-1.91x faster across q=2..8 and batch 1..256; batches above 1024 tokens stay on the 2D grid. Extends test_triton_unified_attn_3d with short-query and sliding-window cases.

Co-authored-by: Cursor <[email protected]>
Signed-off-by: Hongxia Yang <[email protected]>
@hongxiayang
hongxiayang requested review from a team and a balanced review from Copilot October 15, 2026 17:54
@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:gfx1250-ffm-triton Run the five-shard gfx1250 FFM Triton test suite
ci:triton-300x Run an additional Triton test job on MI300X in PRs (added automatically when gfx942 configs change); main branch always runs both MI35X and MI300X
ci:triton-355 Run the full Triton test suite on MI35X, not only the tests the change affects
ci:windows Windows JIT op smoke test on the gfx1201 ROCm runner
ci:multi-gpu Aiter multi-GPU tests on the 8-GPU runner
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: DeepSeek-V4-Pro, MiniMax-M3-MXFP4
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 6594 --add-label <label>

One backend per PR:
A PR changes one kernel backend: [Triton/Gluon] (Triton and Gluon count as one), [HIP], [ASM], [CK], [OPUS] or [FlyDSL]. If the title ends up with two backend tags, split the PR -- as stacked pull requests when one part cannot merge without the other.

PR title tags & labels:
Component tags ([Triton/Gluon], [HIP], [CK], [ASM], ...) are added to the PR title and as PR labels automatically from the changed files and re-synced on every push — change-type tags like [fix]/[Perf], op tags like [MLA], and human labels (ci:*) are left untouched. Add the no-auto-title label to stop the title rewrites; labels stay in sync either way.

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.

🟡 Changes recommended

Tests do not assert grid selection at the new dispatch boundaries.

1 open finding
What changed in this PR

Updates gfx950 Gluon unified-attention dispatch to use the split grid for short sliding-window queries.

Changes:

  • Enables split routing for q ≤ 8, KV ≥ 512, and total query tokens ≤ 1024.
  • Adds short-query and sliding-window output test cases.
File Description
op_tests/​triton_tests/​attention/​test_unified_attention.py Extends short-query and sliding-window coverage.
aiter/​ops/​triton/​attention/​unified_attention.py Adds bounded sliding-window split routing.

🧠 Review effort: Balanced


💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

ChuanLi1101
ChuanLi1101 previously approved these changes Oct 15, 2026

@ChuanLi1101 ChuanLi1101 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

@vgokhale
vgokhale requested a review from cagrikymk October 15, 2026 19:10
@cagrikymk

Copy link
Copy Markdown
Contributor

Human review:
Enabling actual kv split for sliding window requries some kernel boundary check changes for correctness.

This PR speeds things up not because actual kv splitting but 3d has a mechanism to combine spec tokens to a degree as they share kv cache.

Better to enable spec. decode heuristics by getting 3d spec decode heuristics to 2d as well.

Main idea is to adjust block_m for cases where we have few queries but not enough to fill whole BLOCK_M, so we lower it to to match actual workload, this is mainly for spec. decode.

I think the ideal situation is to enable actual splitting for such workloads as such large SWA might benefit from actual split (that requires kernel changes).

I am fine whichever path you wanna take but enabling 3d without kernel fixes creates footgun. So, in that situation, better to do stick to 2d, with heuristics update for SWA + spec. decode.

def _unified_attention_2d_gfx950(params: _UAParams):
    config = get_unified_attention_config("attn_2d", params, backend="gluon")
    MFMA_DIM = config["MFMA_DIM"]
    BLOCK_M = max(config["BLOCK_M"], triton.next_power_of_2(params.num_queries_per_kv))
    q_rows = triton.next_power_of_2(params.max_seqlen_q * params.num_queries_per_kv)
    if q_rows < BLOCK_M:
        # short queries: don't pay for padded MFMA rows
        BLOCK_M = max(q_rows, MFMA_DIM)
    _unified_attention_gfx950(
        params,
        config,
        BLOCK_M=BLOCK_M,
        TILE_SIZE=config["TILE_SIZE"],
        num_warps=BLOCK_M // MFMA_DIM,  # rows are split MFMA_DIM per warp, as in 3D
    )

Claude review:

What actually runs: kv_split schema is ['SW', 'D', 'Q', 'DT'] and the SW entry has MAX_SEGMENTS: 1, so every sliding-window shape gets NUM_SEGMENTS == 1. The speedup comes from the 3D grid with a widened BLOCK_M (one program covers all ≤8 q rows), not from a KV split. In that mode, tile pruning ([ctx+qpos_lo-W+1, ctx+qpos_hi]), per-row window masking, and the all-masked-row guard are the same as in the 2D path. 👍

Latent bug if SW is ever split (NUM_SEGMENTS > 1):

  • Sinks are added only in split 0, but splits divide the full [0, seq_len) range, not the window.
  • If split 0 lies entirely before the window, it takes the tile_start >= tile_end early return and writes an empty partial (M=-inf, L=0) before the sink is added → the sink is dropped and output is wrong with no error.
  • Example: decode, kv=8704, W=2048, TILE=64, 4 splits → split 0 = tiles [0,34), window starts at tile 104.
  • This is the sliding-window + sinks case (GPT-OSS-like), and the only thing preventing it today is the JSON entry.

Suggestions:

  1. Assert or force NUM_SEGMENTS == 1 when sliding_window > 0 in unified_attention.py, or have split 0's early return write the sink partial (M = sink*RCP_LN2, L = 1).
  2. If SW split is wanted later, divide the window range instead of the full sequence (most splits currently just return empty), and keep reduce_segments on the same boundaries.

Nits:

  • The description says batch 1..256, but num_tokens <= 1024 sends q=8 with batch > 128 to the 2D grid.
  • The new SW test cases only run with a single segment, so they don't exercise a real split.
  • The test comment "gfx950 -> Triton" is out of date (the default backend is Gluon).

…k sizing

Per review: the speedup came from the 3D launch's query-block sizing (the SW kv_split entry has MAX_SEGMENTS 1, so nothing was split), and routing sliding-window batches to the 3D grid would drop sinks if SW ever split. Restore the upstream routing and instead apply the unsplit 3D BLOCK_M/num_warps sizing (shared via _gfx950_3d_block_m) in the 2D launcher for sliding-window batches with q*heads_per_kv <= 128 and <= 1024 tokens.

MI355X, Muse Spark Open DSpark shapes (16/2 heads, D=64, window 2048, kv 8704), vs upstream main: 1.13-1.83x at q=2..8 x batch 1..128, 1.33-1.48x at q=2..4 x batch 256; kv 1024: 1.24-1.31x; kv 256: 1.10-1.13x. Full-attention shapes unchanged (0.99-1.06x). Applying the 3D sizing to all short queries regressed large full-attention batches (to 0.54x at q=8 x 256), hence the sliding-window and token limits. Also fixes the stale 'gfx950 -> Triton' test comment.

Co-authored-by: Cursor <[email protected]>
Signed-off-by: Hongxia Yang <[email protected]>
Copilot AI balanced review requested due to automatic review settings October 16, 2026 13:30

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.

🟡 Changes recommended

New NVFP4 test combinations reach an unsupported fallback, and the tuning gate exceeds the stated shape range.

3 open findings

🧠 Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings October 22, 2026 15:28

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.

Replace the 3D config borrowed by the gfx950 2D launch with config entries.
- unified_attention.py: back to main.
- unified_attention_utils.py: new P axis, 2D programs per CU rounded up to a power of 2.
- gfx950 gluon DEFAULT.json: attn_2d schema adds Q and P; four
  D_LEQ_64.Q_LEQ_{2,4,8,16}.P_LEQ_8.SW.DT_bf16_bf16 entries.

Signed-off-by: Giuseppe Grossi <[email protected]>
Copilot AI balanced review requested due to automatic review settings October 26, 2026 20:38

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.

@azaidy azaidy 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!

@azaidy
azaidy merged commit 1ddd9ec into ROCm:main Oct 29, 2026
70 checks passed
solinzby1 pushed a commit that referenced this pull request Nov 2, 2026
… grid (#6594)

* [Triton/Gluon] Route short sliding-window queries to the gfx950 split grid

Spec-decode verify batches (q <= 8, kv >= 512, <= 1024 tokens) on sliding-window layers were forced onto the 2D prefill grid. On MI355X with Muse Spark Open DSpark shapes (16/2 heads, D=64, window 2048, kv 8704), the split grid is 1.13-1.91x faster across q=2..8 and batch 1..256; batches above 1024 tokens stay on the 2D grid. Extends test_triton_unified_attn_3d with short-query and sliding-window cases.

Signed-off-by: Hongxia Yang <[email protected]>

* [Triton/Gluon] Keep SWA spec-decode on the 2D grid with 3D query-block sizing

Per review: the speedup came from the 3D launch's query-block sizing (the SW kv_split entry has MAX_SEGMENTS 1, so nothing was split), and routing sliding-window batches to the 3D grid would drop sinks if SW ever split. Restore the upstream routing and instead apply the unsplit 3D BLOCK_M/num_warps sizing (shared via _gfx950_3d_block_m) in the 2D launcher for sliding-window batches with q*heads_per_kv <= 128 and <= 1024 tokens.

MI355X, Muse Spark Open DSpark shapes (16/2 heads, D=64, window 2048, kv 8704), vs upstream main: 1.13-1.83x at q=2..8 x batch 1..128, 1.33-1.48x at q=2..4 x batch 256; kv 1024: 1.24-1.31x; kv 256: 1.10-1.13x. Full-attention shapes unchanged (0.99-1.06x). Applying the 3D sizing to all short queries regressed large full-attention batches (to 0.54x at q=8 x 256), hence the sliding-window and token limits. Also fixes the stale 'gfx950 -> Triton' test comment.

Signed-off-by: Hongxia Yang <[email protected]>

* [Triton/Gluon] SWA spec-decode attn_2d entries gated on programs per CU

Replace the 3D config borrowed by the gfx950 2D launch with config entries.
- unified_attention.py: back to main.
- unified_attention_utils.py: new P axis, 2D programs per CU rounded up to a power of 2.
- gfx950 gluon DEFAULT.json: attn_2d schema adds Q and P; four
  D_LEQ_64.Q_LEQ_{2,4,8,16}.P_LEQ_8.SW.DT_bf16_bf16 entries.

Signed-off-by: Giuseppe Grossi <[email protected]>

---------

Signed-off-by: Hongxia Yang <[email protected]>
Signed-off-by: Giuseppe Grossi <[email protected]>
Co-authored-by: Mehmet Cagri <[email protected]>
Co-authored-by: Giuseppe Grossi <[email protected]>
shantipriya-amd pushed a commit to shantipriya-amd/aiter that referenced this pull request Nov 18, 2026
… grid (ROCm#6594)

* [Triton/Gluon] Route short sliding-window queries to the gfx950 split grid

Spec-decode verify batches (q <= 8, kv >= 512, <= 1024 tokens) on sliding-window layers were forced onto the 2D prefill grid. On MI355X with Muse Spark Open DSpark shapes (16/2 heads, D=64, window 2048, kv 8704), the split grid is 1.13-1.91x faster across q=2..8 and batch 1..256; batches above 1024 tokens stay on the 2D grid. Extends test_triton_unified_attn_3d with short-query and sliding-window cases.

Signed-off-by: Hongxia Yang <[email protected]>

* [Triton/Gluon] Keep SWA spec-decode on the 2D grid with 3D query-block sizing

Per review: the speedup came from the 3D launch's query-block sizing (the SW kv_split entry has MAX_SEGMENTS 1, so nothing was split), and routing sliding-window batches to the 3D grid would drop sinks if SW ever split. Restore the upstream routing and instead apply the unsplit 3D BLOCK_M/num_warps sizing (shared via _gfx950_3d_block_m) in the 2D launcher for sliding-window batches with q*heads_per_kv <= 128 and <= 1024 tokens.

MI355X, Muse Spark Open DSpark shapes (16/2 heads, D=64, window 2048, kv 8704), vs upstream main: 1.13-1.83x at q=2..8 x batch 1..128, 1.33-1.48x at q=2..4 x batch 256; kv 1024: 1.24-1.31x; kv 256: 1.10-1.13x. Full-attention shapes unchanged (0.99-1.06x). Applying the 3D sizing to all short queries regressed large full-attention batches (to 0.54x at q=8 x 256), hence the sliding-window and token limits. Also fixes the stale 'gfx950 -> Triton' test comment.

Signed-off-by: Hongxia Yang <[email protected]>

* [Triton/Gluon] SWA spec-decode attn_2d entries gated on programs per CU

Replace the 3D config borrowed by the gfx950 2D launch with config entries.
- unified_attention.py: back to main.
- unified_attention_utils.py: new P axis, 2D programs per CU rounded up to a power of 2.
- gfx950 gluon DEFAULT.json: attn_2d schema adds Q and P; four
  D_LEQ_64.Q_LEQ_{2,4,8,16}.P_LEQ_8.SW.DT_bf16_bf16 entries.

Signed-off-by: Giuseppe Grossi <[email protected]>

---------

Signed-off-by: Hongxia Yang <[email protected]>
Signed-off-by: Giuseppe Grossi <[email protected]>
Co-authored-by: Mehmet Cagri <[email protected]>
Co-authored-by: Giuseppe Grossi <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants