Skip to content

[Triton/Gluon] Fix unified attention routing for speculative decode - #6339

Closed
ukannika wants to merge 2 commits into
ROCm:mainfrom
ukannika:ukannika/gluon-unified-attn-kv-split-routing
Closed

ukannika wants to merge 2 commits into
ROCm:mainfrom
ukannika:ukannika/gluon-unified-attn-kv-split-routing

Conversation

@ukannika

@ukannika ukannika commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

Summary

On gfx950, use_2d_kernel() sent every batch with max_seqlen_q > 1 to the Gluon 2d (unsplit) kernel, so an MTP verify step -- long context, a handful of query blocks -- parallelized over query blocks x KV heads alone and left most of the GPU idle. The routing now also asks whether those query blocks can fill (num_2d_prgms > num_sms // 2); when they can't, the 3d kernel adds a KV-segment grid axis and recovers the parallelism from the context length.

Validation

Run once on the base commit and once with the patch, then compare the two files:
GPU=4 bash pr_bench.sh > before.txt
GPU=4 bash pr_bench.sh > after.txt

`set -u
cd "$(dirname "$0")/aiter" 2>/dev/null || cd /app/aiter
BENCH=op_tests/op_benchmarks/triton/bench_unified_attention.py
COMMON="-hq 16 -hk 1 -d 128 -block_size 128 -equal_seqlens --metric time -test -backend gluon"

run () { # dtype_label b sq sk decode_p extra_flags...
local dt=$1 b=$2 sq=$3 sk=$4 dp=$5; shift 5
local out ms chk
out=$(HIP_VISIBLE_DEVICES=${GPU:-0} python $BENCH -b "$b" -sq "$sq" -sk "$sk"
$COMMON "$@" 2>/dev/null)
ms=$(echo "$out" | awk '/^0 /{print $NF}')
chk=$(echo "$out" | grep -oE '\b(PASS|FAIL)\b' | head -1)
echo "$dt $b $sq $sk $dp ${ms:-nan} ${chk:-NA}"
}

for fp8 in "" "-fp8"; do
dt=$([ -n "$fp8" ] && echo fp8 || echo bf16)

for sq in 1 4; do # pure decode, then spec-decode verify
for b in 8 32 64 128; do
for sk in 8192 16384 65536 131072; do
run "$dt" "$b" "$sq" "$sk" 0.0 $fp8
done
done
done

for sq in 16384 32768; do # prefill
run "$dt" 1 "$sq" "$sq" 0.0 $fp8
done

run "$dt" 8 2048 16384 0.75 $fp8 -decode 0.75 # mixed
run "$dt" 32 1024 16384 0.75 $fp8 -decode 0.75
done`

shape bf16 before bf16 after bf16 fp8 before fp8 after fp8
spec b=8 x4 (32 tok), ctx 8k 0.124 0.032 3.93x 0.104 0.015 6.81x
spec b=8 x4 (32 tok), ctx 16k 0.244 0.056 4.36x 0.204 0.021 9.66x
spec b=8 x4 (32 tok), ctx 64k 0.977 0.203 4.81x 0.803 0.054 14.95x
spec b=8 x4 (32 tok), ctx 128k 2.072 0.405 5.12x 1.604 0.097 16.54x
spec b=32 x4 (128 tok), ctx 8k 0.125 0.107 1.18x 0.105 0.032 3.26x
spec b=32 x4 (128 tok), ctx 16k 0.251 0.204 1.23x 0.205 0.054 3.82x
spec b=32 x4 (128 tok), ctx 64k 1.067 0.834 1.28x 0.810 0.187 4.33x
spec b=32 x4 (128 tok), ctx 128k 2.153 1.665 1.29x 1.624 0.376 4.32x
spec b=64 x4 (256 tok), ctx 8k 0.129 0.130 1.00x 0.105 0.057 1.84x
spec b=64 x4 (256 tok), ctx 16k 0.273 0.273 1.00x 0.206 0.100 2.07x
spec b=64 x4 (256 tok), ctx 64k 1.105 1.101 1.00x 0.822 0.377 2.18x
spec b=64 x4 (256 tok), ctx 128k 2.215 2.219 1.00x 1.633 0.748 2.18x
spec b=128 x4 (512 tok), all ctx 0.149–2.377 0.149–2.380 1.00x 0.107–1.659 0.107–1.658 1.00x
decode b=8–128, all ctx (16 rows) 0.011–1.271 0.012–1.271 1.00x 0.014–0.694 0.014–0.696 1.00x
prefill 16k tokens 1.066 1.063 1.00x 0.680 0.680 1.00x
prefill 32k tokens 4.149 4.166 1.00x 2.632 2.639 1.00x
mixed 75% decode, b=8, 2048-tok prefill 0.665 0.664 1.00x 0.458 0.460 1.00x
mixed 75% decode, b=32, 1024-tok prefill 1.206 1.205 1.00x 0.788 0.789 1.00x

@ukannika
ukannika requested a review from a team October 9, 2026 19:13
@github-actions

github-actions Bot commented Oct 9, 2026

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: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: 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 6339 --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.

@zufayu
zufayu requested review from a team and k50112113 October 10, 2026 01:38
@cagrikymk

Copy link
Copy Markdown
Contributor

@ukannika Possible to compare your PR against #6336 ?

We might be solving the same problem.

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

Tuned thresholds belong in configuration, and sliding-window routing currently bypasses the specialized 2D path without gaining KV splitting.

1 open finding
What changed in this PR

Adjusts gfx950 Gluon unified-attention routing to favor KV-split 3D execution for underfilled speculative-decode workloads.

Changes:

  • Adds dtype-specific occupancy thresholds.
  • Routes low-program non-decode workloads through the 3D kernel.
File Description
aiter/​ops/​triton/​attention/​unified_attention.py Updates gfx950 Gluon kernel routing heuristics.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +169 to +172
if params.kv_cache_dtype == e4m3_dtype:
split_limit = params.num_sms * 2
else:
split_limit = params.num_sms * 3 // 4

@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

@cagrikymk

Copy link
Copy Markdown
Contributor

LGTM

@ChuanLi1101 Could we prioritize earlier PR (#6336) over this? I have some extra optimizations over this PR.
Also, e2e is verified in #6221

@azaidy azaidy assigned cagrikymk and unassigned k50112113 Oct 12, 2026
@ukannika

Copy link
Copy Markdown
Contributor Author

LGTM

@ChuanLi1101 Could we prioritize earlier PR (#6336) over this? I have some extra optimizations over this PR. Also, e2e is verified in #6221

Will check this #PR6336. Will update here with e2e results

@cagrikymk

Copy link
Copy Markdown
Contributor

LGTM

@ChuanLi1101 Could we prioritize earlier PR (#6336) over this? I have some extra optimizations over this PR. Also, e2e is verified in #6221

Will check this #PR6336. Will update here with e2e results

I think that PR (precedes this one), should fix this issue. If you also observe that, can we close this PR?

@cagrikymk

Copy link
Copy Markdown
Contributor

Closing due to inactivity.

If it’s still relevant, feel free to reopen it, and thanks!

@cagrikymk cagrikymk closed this Oct 20, 2026
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.

5 participants