Repository navigation
Conversation
…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)
…ll to the generic 3D entry)
…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]>
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
One backend per PR: PR title tags & labels: Reviews: |
WAITING ON AUTHORPR Self-ReviewRevision 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
Edit the Missing or invalid answers
Shadow mode reports what would block but keeps the status successful. Set |
0f313f8 to
14fe2a7
Compare
There was a problem hiding this comment.
🟡 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
| "DT_fp8_fp8.K_GEQ_524288": { | ||
| "num_warps": 1, | ||
| "num_stages": 4, | ||
| "waves_per_eu": 2 |
There was a problem hiding this comment.
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).
| _steer_decode(monkeypatch, two_heads=True) | ||
| assert ( | ||
| ua._select_triton_split_decode(params(bf16_q), 64, 4) | ||
| is ua._unified_attention_decode_2h | ||
| ) |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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).
14fe2a7 to
a7df9d8
Compare
|
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 ( Triton shard 7 failed on the previous heads with |
ee710dc to
6b04d37
Compare
…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]>
…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]>
6b04d37 to
eab221a
Compare
…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]>


Summary
Add
kernel_unified_attention_decode_2hon 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=0disables 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, Tritond436c49e2f,bench_one_batch. Arms used the same build, fresh servers and bracketing measurements.The arms used
AITER_UA_DECODE_2H=0and=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
6b04d370da41cf17f1e07860cdf1551e0bc34018passed 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 mainecfa616d8.Breaking Changes
New import-time environment variable
AITER_UA_DECODE_2H, default on, changes the default producer for eligible gfx1250 decode. Set it to0before importing AITER to use the generic producer. Tested producer outputs are bit-identical.PR Self-Review
Reviewed revision
eab221a5e4b641d68ce421685543998bec2ee579Behavior 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_2hrow 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.pyadds 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.pyadds 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.pyadds sharedpaged_decode_caseandassert_steered_parityhelpers for valid cache geometry and consistent eager/replay comparison, replacing repeated setup across the stack.