Skip to content

[Triton/Gluon] [Perf] [gfx1250] unified attention: two-KV-head split-KV decode producer (GQA 8, head 64) - #8883

Draft
akao-amd wants to merge 15 commits into
ROCm:mainfrom
akao-amd:pr-gfx1250-ua-decode-2h
Draft

akao-amd wants to merge 15 commits into
ROCm:mainfrom
akao-amd:pr-gfx1250-ua-decode-2h

Conversation

@akao-amd

@akao-amd akao-amd commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Add kernel_unified_attention_decode_2h on top of #7743. Each program processes two adjacent KV heads and their 16 query heads, filling paired QK/PV tiles. It writes the existing FP32 split partials and uses the same reduce kernel.

Stack: #7743 -> #8883 -> #8884 -> #8885. The diff against main includes #7743; this PR adds the producer, selection gate, table and tests.

Motivation and changes

Block-diagonal Q is [16, 128]; QK reads both heads' K, PV accumulates [16, 128], and each row stores its own head's half. Partial last tiles, sinks and Q/K/V descales follow the generic split producer's semantics.

The gate requires all-decode with more than one segment, GQA 8, Q/V head 64, page=tile=64, even KV-head count, plain NHD FP8 K/V, BF16 or FP8 Q and compatible shapes/strides. It rejects window, softcap, ALiBi, qq_bias, output scaling and batches above 65535 slots because sequence index is grid axis 1. Query rows follow the existing one-token-per-sequence decode contract. Rejected calls use generic 3D.

Selection follows tile/split calculation and precedes scratch allocation. An architecture opts in through attn_decode_2h; only gfx1250 ships it. Its DT/any row uses warps 1, waves 2 and stages 3 at every context length. There is no K threshold or four-stage large-context row. AITER_UA_DECODE_2H=0 disables selection at import time; changing it requires a fresh process.

Shared softmax/PV extraction remains a follow-up: paired [16, 128] accumulator state differs from upstream's single-head helpers and needs a compatible interface plus separate parity/performance validation.

Performance

Earlier measurement (not re-run on this head): gpt-oss-120b TP2 on one MI455X (two 96-CU partitions), 1400 W, FP8 KV page 64 and FP8 decode Q, image rocm/sgl-dev:v0.5.23-rocm101-mi45x-20261127, Triton d436c49e2f, bench_one_batch. Arms used the same build, fresh servers and bracketing measurements.

Earlier workload 3D ms Paired ms Change
32768/1024×168, four segments 20.18 16.20 -19.7%
131072/1024×44, graph48 / eight segments 17.83 13.51 -24.2%
1048576/256×8, 64 segments 21.25 16.36 -23.0%

The arms used AITER_UA_DECODE_2H=0 and =1. Performance and warp/stage optimality have not been re-measured on this head.

The base1130_v3 stack (MI450 gpt-oss measurements, December 1, 2026) carried this change as 91bb51f30; the executable producer and table edits are identical. The new batch guard affects slots above 65535, outside its measured 168/48/8 launches. All v3 full-attention decode spans take this producer. V1/v3 contain it in both A/B arms, so that comparison does not measure this PR alone. The older whole-stack greedy-identical claim is not current validation: base1130_v3 contains a separate dense-FP8 numerical change, and serving accuracy has not been checked on this head.

Testing

GPU setup: MI455X (gfx1250) 96-CU partition, image rocm/sgl-dev:v1.0.0-rocm101-mi45x-20261202, torch 2.12.0+rocm10.1.0, Triton 3.9.0. At the reviewed revision on HIP 2 / CU_NUM=96:

  • python -m pytest -q op_tests/triton_tests/attention/test_unified_attention_config.py: 9 passed.
  • AITER_UA_DECODE_2H=1 python -m pytest -q op_tests/triton_tests/attention/test_unified_attention.py -k decode_two_heads: 43 passed, including long context and graph replay, exact with rtol=atol=0. Tests explicitly steer generic reference and paired candidate.

The earlier revision 6b04d370da41cf17f1e07860cdf1551e0bc34018 passed the same 43 cases with each import-time switch value. Explicit steering means the disabled-switch run still invokes the paired candidate.

Current CPU config/metadata checks: 11 passed / 30 subtests, with GPU initialization forbidden. They pin table values across context boundaries, absent architecture opt-ins, each input restriction and batch 65535/65536. Other architectures, unfiltered attention and current serving performance/accuracy remain unverified.

Documentation and dependencies

README/config/review guidance document table selection, input restrictions and the switch. No new dependencies or public API signature changes. Rebased onto #7743 4f3b711a2, which merges main ecfa616d8.

Breaking Changes

New import-time environment variable AITER_UA_DECODE_2H, default on, changes the default producer for eligible gfx1250 decode. Set it to 0 before importing AITER to use the generic producer. Tested producer outputs are bit-identical.

PR Self-Review

Reviewed revision

eab221a5e4b641d68ce421685543998bec2ee579

Behavior and intent

Pair two KV heads per split-decode program to fill the QK/PV layout. Metadata and architecture gates restrict selection to supported FP8-KV GQA8/head64 calls whose batch fits grid axis 1.

Validation and unverified scope

At this revision, GPU config tests passed nine cases and exact producer parity passed 43, including long context and replay. CPU gates/config passed 11 tests. Current performance, serving accuracy, other architectures and the shared-helper extraction remain unverified.

PR-specific question

Only the gfx1250 DT/any attn_decode_2h row opts in; guards pin dtype, shape, options, split count and batch limit. .github/instructions/ edits are review guidance only and add no workflow execution, permissions or privileged input path.

Changed op tests

  • test_unified_attention.py adds exact producer/long-context/replay comparisons and metadata rejection tests. Existing tests could not detect unsupported selection or compare the paired layout exactly.
  • test_unified_attention_config.py adds producer-table/architecture checks and inherits [Triton/Gluon] [Perf] [gfx1250] unified attention 3D: tuned split for plain bf16 and fp8 decode #7743's split checks, necessary because splits determine eligibility.
  • mha_test_utils.py adds shared paged_decode_case and assert_steered_parity helpers for valid cache geometry and consistent eager/replay comparison, replacing repeated setup across the stack.

akao-amd and others added 8 commits November 10, 2026 19:08
…A3D_NHD_CFG

Cherry-picked from perf1101 (no upstream PR yet).

Co-Authored-By: Claude <[email protected]>
(cherry picked from commit 1502c52)
…, head_dim <= 64

The plain (non-shuffled) bf16 KV cache fell to the 'any' entry (waves_per_eu 1). Occupancy 2 cuts the gpt-oss-120b full-attention decode kernel by ~35% in situ; outputs bitwise identical (only the launch's occupancy hint changes).

Co-Authored-By: Claude <[email protected]>
(cherry picked from commit 37d3490)
…ault

The env AITER_GFX1250_UA3D_NHD_CFG still overrides it. waves_per_eu 2 alone was the old bf16 entry; the measured config is waves 2, num_stages 3, SEGMENTS_PER_CU 16, MIN_SEGMENTS 4, for bf16 and fp8 q/KV.

Co-authored-by: Cursor <[email protected]>
The D<=64 entries matched every query length, so short prefill and verify batches that still launch the 3D kernel took the decode tuning. Key them on Q_LEQ_1 with Q after SHUF so shuffled entries still win, and drop the env override so this change is only the retune.
The env override is gone, and this branch does not need the dtype-tag edits that landed on main after it forked.
…r fp8-KV decode

The all-decode rows this PR adds for head dim <= 64 run num_stages 3. Over an fp8 KV
cache (DT_bf16_fp8 and DT_fp8_fp8 Q_LEQ_1) num_stages 4 is faster at every context we
measured and stores the same bits (num_warps 1, waves_per_eu 2 unchanged); bf16 KV
keeps 3.

Per call on one MI455X partition (96 CUs), gpt-oss TP2 decode shapes, 2.2 GHz:
- bf16 Q: 32k c168 579 -> 513 us, 128k (graph batch 48) 595 -> 555 us, 1M c8 974 -> 871 us
- fp8 Q:  32k 585 -> 480 us, 128k 579 -> 538 us, 1M 898 -> 786 us
At the 1400 W serving cap, TP2 decode step: -0.37 / -0.39 / -0.28 ms at 32k / 128k / 1M.

These are Triton attn_3d rows. The Gluon 3D kernel's num_stages == 2 requirement
(ROCm#6730) reads the gluon table and is not affected.

Upstream-PR: ROCm#7743

Co-Authored-By: Claude <[email protected]>
@akao-amd
akao-amd requested a review from a team November 28, 2026 22:17
@github-actions

Copy link
Copy Markdown
Contributor

🏷️ CI Guide

Runs automatically on every PR:

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

Extended tests (opt-in via labels):

Label Tests
ci:mi300x Run Aiter standard tests on MI300X in PRs; main branch always runs them
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 Radeon R9700 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 8883 --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.

Reviews:
A reviewer is usually assigned within one working day after the PR is ready for review (see Code Review Process). If nobody has responded for about a week, mention the area contact listed in CONTACTS.md. Want to help review? See REVIEWERS.md.

@aiter-bot

aiter-bot commented Nov 28, 2026 •

Copy link
Copy Markdown

WAITING ON AUTHOR

PR Self-Review

Revision 6b04d370da41 · mode shadow

Waiting for the PR author. The readiness report will appear after the self-review answers are complete for this revision.

Questions to answer in the PR description

  1. What behavior does this PR change, and why is the existing behavior insufficient?
  2. What did you validate, and what remains unverified? Include commands, hardware/configuration and results.
  3. What permissions and untrusted-input boundary does this CI change have, and can fork PR code or text reach a privileged execution path?
  4. For every changed op_tests/ file, what behavior does it cover and why is it not redundant? Write None if no op test changed.

Edit the PR Self-Review section in the PR description. Include the current revision SHA; this comment refreshes automatically.

Missing or invalid answers

  • FAIL — Reviewed revision must contain at least the first 7 characters of the current head SHA

Shadow mode reports what would block but keeps the status successful. Set AITER_PR_SELF_REVIEW_MODE=enforce only after reviewing real false positives.

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

Important test gaps leave gate restrictions, K-dependent configuration boundaries, and four-stage long-context parity unverified.

3 open issues
What changed in this PR

Adds a gfx1250-specific two-KV-head producer to Triton unified attention. It reduces padding for eligible GQA-8, head-64 split decode while reusing the existing partial-output layout and reduction, building on the split tuning from #7743.

Changes:

  • Process two adjacent KV heads per program for supported fp8-KV decode calls.
  • Select the producer through config opt-in and support checks, with an environment switch to disable it.
  • Add launch settings, gate checks, config tests, exact-parity comparisons and graph replay coverage.
File Description
op_tests/​triton_tests/​attention/​test_unified_attention.py Add producer gate, parity and graph replay tests.
op_tests/​triton_tests/​attention/​test_unified_attention_config.py Check decode tuning, fallback rows and segment counts inherited from #7743.
aiter/​ops/​triton/​utils/​unified_attention_utils.py Add optional-section detection and K-axis lookup support.
aiter/​ops/​triton/​configs/​gfx1250/​triton/​attention/​unified_attention/​DEFAULT.json Add decode split tuning and two-head launch settings.
aiter/​ops/​triton/​attention/​unified_attention.py Gate, select and launch the optional two-head producer.
aiter/​ops/​triton/​_triton_kernels/​attention/​unified_attention.py Compute two-head split partials for the existing reducer.

Review effort: Balanced

Comment on lines +301 to +304
"DT_fp8_fp8.K_GEQ_524288": {
"num_warps": 1,
"num_stages": 4,
"waves_per_eu": 2

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks. Measuring on the full stack changed the table. The K >= 524288 rows (num_stages 4) came from per-call kernel sweeps, but at 1M serving (gpt-oss-120b TP2, 64 segments) the 3-stage launch measured 16.344 / 16.383 ms/step against 17.784 / 17.697 / 17.723 with 4 stages (alternating fresh servers, identical greedy tokens). So attn_decode_2h now has a single any row (num_warps 1, num_stages 3, waves_per_eu 2) and the loader's K axis value is gone again. test_one_row_for_every_context checks the lookup at max_seqlen_k 8192 / 524287 / 524288 / 524289 / 1052672 for bf16 and fp8 Q, and test_unified_attn_decode_two_heads_long_context keeps exact parity with the 3D producer at 524289 (GPU: passed on MI455X).

Comment on lines +493 to +497
_steer_decode(monkeypatch, two_heads=True)
assert (
ua._select_triton_split_decode(params(bf16_q), 64, 4)
is ua._unified_attention_decode_2h
)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed: the gate test now has one metadata case each for GQA 4, sliding window, softcap, ALiBi, qq_bias and output scale. Each asserts that decode_2h_supported rejects it and that _select_triton_split_decode returns the 3D launcher while the table section is present.

},
"attn_decode_2h": {
"DT_fp8_fp8.K_GEQ_524288": {
"num_warps": 1,

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The values come from per-call sweeps of this kernel on one MI455X partition at gpt-oss TP2 shapes. At 1M (64 segments), 48 candidates over warps 1/2/4 x stages 2-5 x waves 0/2: warps 1 was best; warps 2 ran at 0.67-0.86x and warps 4 at 0.22-0.66x of its speed. At 128k (8 segments): warps 1 / stages 3 took 360.0 us per call, warps 2 / stages 3 404.9 us, warps 4 637-639 us. The 32k sweep covered warps 1 only. On the full stack we also re-checked stages at 1M, which changed the table to one row (see the other thread).

@akao-amd

Copy link
Copy Markdown
Contributor Author

This PR is the bottom of a three-PR stack: #8884 builds on this commit, and #8885 builds on #8884. I merged current main into each branch (a999c1598). The PR diffs against main still show only the stack's own changes.

Triton shard 7 failed on the previous heads with test_gemm_a16wfp4[True-False-False-True-16-4096-11008]. The output had NaNs (atomic_add=True). None of the files in this stack touch that code, and main's latest Triton run passes. It may be flaky or nondeterministic. I'd like to see it rerun on this head before treating it as unrelated.

@zufayu
zufayu requested review from a team and azaidy December 1, 2026 04:39
@akao-amd
akao-amd force-pushed the pr-gfx1250-ua-decode-2h branch from ee710dc to 6b04d37 Compare December 3, 2026 02:23
akao-amd added a commit to akao-amd/aiter that referenced this pull request Dec 3, 2026
…major grid from the attn_3d table

Stacked on ROCm#8883 (two-KV-head producer).

The Triton 3D decode grid is (q_blocks, kv_heads, segments), so the programs of one
sequence's adjacent KV heads are launched far apart. The 2D grid is already
(kv_heads, q_blocks).

An attn_3d row can now set KV_HEAD_FIRST: all-decode launches then use
(kv_heads, q_blocks, segments), and the kernel swaps its first two program ids. Each
program computes and stores the same values; only the launch order changes. The
gfx1250 rows for head dim <= 64 decode over an fp8 KV cache (DT_bf16_fp8 and
DT_fp8_fp8 Q_LEQ_1) set it. No other row changes.

This is the 3D producer, so it applies where the two-KV-head producer does not (one
segment, other GQA ratios or head sizes, AITER_UA_DECODE_2H=0).

Test: bit-exact parity of the KV-head-major and default grids for 4 and 8 KV heads,
bf16 and fp8 Q, unequal lengths and empty trailing slots. Each table row covers
seqused_k, so no read goes past the table.

gpt-oss-120b TP2 32k c168 decode step on one MI455X (3D producer): -3.9 ms. To be
re-measured on this base.

Co-Authored-By: Claude <[email protected]>
Co-authored-by: Cursor <[email protected]>
@akao-amd
akao-amd marked this pull request as draft December 3, 2026 02:38
akao-amd and others added 4 commits December 3, 2026 05:31
…KV decode producer (GQA 8, head 64)

Stacked on ROCm#7743 (pr-gfx1250-ua3d-nhd). Carries only the two-KV-head producer and its dispatch. The tuned-split and num_stages commits this branch used to repeat are dropped: ROCm#7743 already has them.

Split-KV decode on gfx1250 runs kernel_unified_attention_3d with BLOCK_M 16. With 8
query heads per KV head (gpt-oss), half of every 16-row block is padding.

kernel_unified_attention_decode_2h handles two adjacent KV heads per program, so the 16
rows are 8 query heads x 2 KV heads and none are padding. QK multiplies a block-diagonal
Q [16, 128] (each row's query in its own head's 64 columns) by both heads' K at once. PV
accumulates [16, 128], and each row keeps its own head's half. It writes the same
split partials (segm_output / segm_max / segm_expsum) as the 3D kernel, so the same
reduce follows and the results are bit-identical to the 3D kernel.

Selection:
- The producer is picked per call in _select_triton_split_decode, once the split
  (NUM_SEGMENTS, TILE_SIZE) is fixed and before its scratch is allocated; the 3D
  launch site calls the chosen launcher. It is a small producer table, so
  kernel_unified_attention_3d stays the default.
- decode_2h_supported() checks only what the kernel computes: all-decode split KV
  (NUM_SEGMENTS > 1), GQA 8, head 64, page = tile = 64, an even KV-head count, plain
  NHD fp8 K/V, bf16 or fp8 Q, optional sinks, no window, softcap, alibi, qq_bias or
  output scale.
- An arch opts in by shipping an attn_decode_2h section in its triton DEFAULT.json
  (has_unified_attention_config). gfx1250 ships one row: num_warps 1, num_stages 3,
  waves_per_eu 2, at every context length.
- AITER_UA_DECODE_2H=0 turns the producer off (read at import, like
  AITER_UA2D_FUSED_EPILOGUE).

Depends on ROCm#7743. Its all-decode split (MIN_SEGMENTS 4) is what gives gpt-oss TP2
4 / 8 / 64 segments at 32k c168 / 128k c44 / 1M c8. Main's split gives 1 / 2 / 16, and
one segment never takes this producer.

Tests (op_tests/triton_tests/attention/test_unified_attention.py):
- exact parity with the 3D producer for 4 and 8 KV heads, bf16 and fp8 Q, sinks on and
  off, lengths 1/64/65 and two empty trailing slots;
- a CUDA graph replay that moves tiles between partial and full;
- a gate test on metadata mocks: predicate, table opt-in, kill switch, and the shipped
  gfx1250 / gfx950 tables.

gpt-oss-120b TP2 decode step on one MI455X (1400 W), before the launch table:
-2.42 / -1.37 / -3.30 ms at 32k / 128k / 1M; num_stages 3 adds -1.02 / -2.37 ms
at 32k / 128k. At 1M, serving also runs faster with 3 stages than with the 4 that
per-call sweeps had picked, so the table has one row. To be re-measured on this
base for the PR.

Co-Authored-By: Claude <[email protected]>
Co-authored-by: Cursor <[email protected]>
@akao-amd
akao-amd force-pushed the pr-gfx1250-ua-decode-2h branch from 6b04d37 to eab221a Compare December 3, 2026 07:29
akao-amd added a commit to akao-amd/aiter that referenced this pull request Dec 3, 2026
…major grid from the attn_3d table

Stacked on ROCm#8883 (two-KV-head producer).

The Triton 3D decode grid is (q_blocks, kv_heads, segments), so the programs of one
sequence's adjacent KV heads are launched far apart. The 2D grid is already
(kv_heads, q_blocks).

An attn_3d row can now set KV_HEAD_FIRST: all-decode launches then use
(kv_heads, q_blocks, segments), and the kernel swaps its first two program ids. Each
program computes and stores the same values; only the launch order changes. The
gfx1250 rows for head dim <= 64 decode over an fp8 KV cache (DT_bf16_fp8 and
DT_fp8_fp8 Q_LEQ_1) set it. No other row changes.

This is the 3D producer, so it applies where the two-KV-head producer does not (one
segment, other GQA ratios or head sizes, AITER_UA_DECODE_2H=0).

Test: bit-exact parity of the KV-head-major and default grids for 4 and 8 KV heads,
bf16 and fp8 Q, unequal lengths and empty trailing slots. Each table row covers
seqused_k, so no read goes past the table.

gpt-oss-120b TP2 32k c168 decode step on one MI455X (3D producer): -3.9 ms. To be
re-measured on this base.

Co-Authored-By: Claude <[email protected]>
Co-authored-by: Cursor <[email protected]>
@zufayu
zufayu removed request for a team and azaidy December 3, 2026 23:06

This branch has not been deployed

No deployments
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.

4 participants