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 |
4e82ca1 to
b204967
Compare
There was a problem hiding this comment.
🟡 Changes recommended
Unresolved findings call for adding query-head count to trace names, testing the shipped KV_HEAD_FIRST opt-ins and default grid, and documenting the new producer-selection contract.
3 open issues
What changed in this PR
This PR adds configurable KV-head-major launch order to AITER’s Triton 3D decode path. It enables the option for gfx1250 fp8-KV decode with head sizes up to 64, without changing the attention calculation.
Changes:
- Adds the decode-only
KV_HEAD_FIRSToption to the wrapper, kernel, and trace names. - Enables the option in two gfx1250 config rows; other rows retain the default grid.
- Includes stacked split-KV tuning and the two-head producer from #7743 and #8883, plus config, dispatch, and exact-parity tests.
| File | Description |
|---|---|
op_tests/triton_tests/attention/test_unified_attention.py |
Adds decode steering, parity, producer-gate, and graph-replay tests. |
op_tests/triton_tests/attention/test_unified_attention_config.py |
Checks decode config selection, launch values, and segment counts. |
aiter/ops/triton/utils/unified_attention_utils.py |
Adds producer-section detection and the KV-length lookup axis. |
aiter/ops/triton/configs/gfx1250/triton/attention/unified_attention/DEFAULT.json |
Enables head-first traversal and supplies stacked decode tuning. |
aiter/ops/triton/attention/unified_attention.py |
Selects the decode producer and applies the configured grid order. |
aiter/ops/triton/_triton_kernels/attention/unified_attention.py |
Supports swapped program IDs and adds the paired-KV-head producer. |
Review effort: Balanced
| kernel_unified_attention_decode_2h_repr = make_kernel_repr( | ||
| "kernel_unified_attention_decode_2h", | ||
| [ | ||
| "NUM_SEGMENTS_PER_SEQ", |
There was a problem hiding this comment.
Fixed in the producer's commit (which this stack carries): num_query_heads is now the first repr key of kernel_unified_attention_decode_2h, as in kernel_unified_attention_3d. Only the name changes; codegen does not.
|
|
||
| _CONFIG_NAME = "UNIFIED-ATTENTION" | ||
| _OPS = ("attn_2d", "attn_3d", "reduce", "kv_split") | ||
| _OPS = ("attn_2d", "attn_3d", "reduce", "kv_split", "attn_decode_2h") |
There was a problem hiding this comment.
Fixed: configs/AGENTS.md (unified attention), aiter/ops/triton/README.md and the review instructions now describe the attn_decode_2h table (DT key, one row), the section as the arch opt-in, the input limits, AITER_UA_DECODE_2H, and the KV_HEAD_FIRST launch key.
| self.assertEqual( | ||
| (attn["num_stages"], attn["waves_per_eu"]), (stages, 2) | ||
| ) | ||
| self.assertEqual(self._split(params)["NUM_SEGMENTS"], 16) |
There was a problem hiding this comment.
Fixed: test_kv_head_first_only_on_fp8_kv_decode_rows asserts the key on both fp8-KV decode rows (bf16 / fp8 Q, head 32 / 64) and its absence for bf16 KV, fp8 Q over bf16 KV, a 16-token query, head 128 and shuffled KV. Deleting either shipped key now fails the test.
b204967 to
487c0e9
Compare
b27ce8b to
a35d03e
Compare
…e K/V page offsets Stacked on ROCm#8884. HOIST_KV_ADDR (an attn_3d table key, all-decode, plain NHD, one page per tile) computes the in-page K/V offsets once, outside the KV loop, and adds one scalar page base per tile, instead of rebuilding [64 x 64] int64 offsets from a 64-wide block-table gather each iteration. The causal-mask skip on tiles wholly below seq_len is not part of HOIST_KV_ADDR any more. The gfx1250 rows set SPLIT_UNMASKED_LOOP: true for it, the flag the attn_2d rows already use, so the mask logic exists once. Bit-exact with the default 3D launch by construction (same tiles, same order, same masked values). Not yet run on hardware. The -1.9 / -2.6 / -3.7 ms gpt-oss-120b TP2 decode numbers from the first version were measured with the in-HOIST mask skip; re-measure with SPLIT_UNMASKED_LOOP on the rows. 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]>
…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]>
a35d03e to
c5c9bdb
Compare
…e K/V page offsets Stacked on ROCm#8884. For all-decode plain NHD KV with one page per tile, HOIST_KV_ADDR computes the invariant K/V in-page offsets before the KV loop and adds one scalar page base per tile. The public wrapper and kernel guard require no window and power-of-two head sizes. Only the two gfx1250 fp8-KV decode rows enable hoisting. They retain the normal masked loop: the 3D SPLIT_UNMASKED_LOOP use failed exact parity and produced non-finite outputs, so it is not enabled. Existing upstream split uses are unchanged. Tests independently steer address hoisting with splitting disabled, pin both opt-ins and the absence of the split key, and cover sinks, both grid orders, bf16/fp8 Q, partial/full tiles and graph replay. GPU validation on the identical source tree passed 147 selected cases and 630 broad cases (96 skips) under each import-time producer switch on gfx1250/Triton 3.9. Current address-only performance has not been measured.

Summary
On top of #8883, add
KV_HEAD_FIRSTtoattn_3d. Eligible all-decode 3D launches use(num_kv_heads, q_blocks, segments)and swap the first two kernel program IDs, grouping adjacent KV heads in launch order while preserving per-program arithmetic and output layout.Stack: #7743 -> #8883 -> #8884 -> #8885. This PR adds grid selection, two opt-ins and parity/boundary tests.
Changes and scope
The public wrapper consumes the key only for all-decode 3D launches. The shared kernel requires
GRID_3D or not KV_HEAD_FIRST. Only gfx1250D_LEQ_64.DT_bf16_fp8.Q_LEQ_1andD_LEQ_64.DT_fp8_fp8.Q_LEQ_1ship it.Decode q_blocks includes metadata padding. Above 65535,
_triton_3d_launch_gridreturns the default grid and matchingKV_HEAD_FIRST=False, avoiding the grid-axis-1 limit. Parent #8883 also rejects producer batches above 65535, so the stacked fallback remains launchable.At the measured gpt-oss TP1/TP2 serving batches, every full-attention decode call has more than one segment and takes #8883's producer; sliding-window layers use the 2D kernel. These 3D changes act with
AITER_UA_DECODE_2H=0, one-segment calls or other supported shapes, and were inactive in the default base1130_v3 serving measurements.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.At 32768/1024×168, grid off/on measured 23.41 -> 20.18 ms (-13.8%), with 2h disabled and only the grid key differing. Performance has not been re-measured on this head; 128k/1M were not measured in isolation.
The base1130_v3 stack (MI450 gpt-oss measurements, December 1, 2026) carried this change as
aecc0e64d; opt-ins and program mapping are identical. The current port uses upstream's merged kernel and adds the >65535 fallback. V1/v3 contain this change 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: 10 passed.AITER_UA_DECODE_2H=0 python -m pytest -q op_tests/triton_tests/attention/test_unified_attention.py -k "decode_kv_head_first or triton_3d_launch_grid": 24 passed (12 exact GPU parity cases and 12 CPU grid cases).Current CPU config/metadata suite: 24 passed / 39 subtests. Config tests pin the two opt-ins and unaffected rows; launch-helper cases pin both grid and constexpr at serving batches and boundaries. Other architectures, unfiltered attention and current serving performance/accuracy remain unverified.
Documentation and dependencies
README/config/review guidance document grid scope and the axis fallback. No new dependencies or public API changes. Rebased onto #8883
eab221a5e; root #7743 merges mainecfa616d8.PR Self-Review
Reviewed revision
c5c9bdb2998aaf0936c557f85d4d6cd327e185dfBehavior and intent
Reorder eligible generic 3D FP8-KV decode programs to group KV heads. Above 65535 q blocks, keep the default grid and matching constexpr so large metadata batches avoid the axis-1 limit.
Validation and unverified scope
At this revision, config tests passed ten cases, grid selection passed 24, and all 65535/65536 GPU boundary cases passed with eager/replay exact parity. Current performance, serving accuracy and other GPU architectures remain unverified.
PR-specific question
The two FP8-KV Q_LEQ_1 rows alone carry
KV_HEAD_FIRST; config checks pin BF16 KV, shuffled cache, larger heads and longer queries to previous selection. The wrapper enforces the grid boundary. Review-guidance edits add no workflow execution or permissions.Changed op tests
test_unified_attention.pyadds exact grid parity and 12 CPU grid/constexpr cases; producer tests alone do not cover launch order or its overflow fallback. Parent producer tests remain inherited.test_unified_attention_config.pyadds both opt-ins and nonmatching-row checks, inheriting parent split/producer coverage because numerical outputs do not pin selection.mha_test_utils.pyis inherited from [Triton/Gluon] [Perf] [gfx1250] unified attention: two-KV-head split-KV decode producer (GQA 8, head 64) #8883 for valid page tables and consistent eager/replay parity; the grid tests reuse it without duplicating setup.