Repository navigation
[Triton/Gluon] [Perf] unified_attention: split KV by actual sequence lengths under CUDA graphs (gfx950, head 64, bf16 Q / fp8 KV) - #7088
Conversation
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
One backend per PR: PR title tags & labels: |
There was a problem hiding this comment.
🔵 Needs a closer look
The gfx950 split-count retune needs exact-head CUDA-graph correctness and latency validation because the supplied measurements predate this PR and GPU execution was unavailable during review.
No open issues 🎉
What changed in this PR
This config-only PR tunes unified attention on gfx950 for head dimensions up to 64 with bf16 queries and fp8 KV, targeting long-context decode under CUDA graphs.
Changes:
- Adds a dtype-specific entry with 128 KV segments and fixed segment and tile sizes of 64.
- Leaves kernel code unchanged. Reported measurements show faster long-context decode, with a 2.6 µs slowdown for the short-sequence case.
| File | Description |
|---|---|
aiter/ops/triton/configs/gfx950/triton/attention/unified_attention/DEFAULT.json |
Adds the D_LEQ_64.DT_bf16_fp8 KV-split configuration. |
Review effort: Balanced
There was a problem hiding this comment.
🔵 Needs a closer look
The gfx950 default’s reported mixed-length gains come with uniform-batch slowdowns, requiring maintainer judgment supported by target-GPU correctness and latency measurements unavailable in this review.
No open issues 🎉
1 resolved since last review
Review effort: Balanced
There was a problem hiding this comment.
🔵 Needs a closer look
The gfx950 tuning’s reported long-context gains come with uniform-batch latency regressions, requiring maintainer judgment on the workload trade-off because GPU correctness and performance results could not be independently reproduced.
No open issues 🎉
Review effort: Balanced
4948cd3 to
be2a245
Compare
There was a problem hiding this comment.
🔵 Needs a closer look
The new GPU work-item mapping and reduction layout require exact-head gfx950 correctness and CUDA-graph replay validation, which this source-only review cannot provide and no supplied report establishes.
1 open issue
Review effort: Balanced
There was a problem hiding this comment.
🔵 Needs a closer look
The new GPU work-item mapping and slot-major reduction require independent exact-head gfx950 correctness, latency, and changing-length graph-replay validation that this source-only review could not perform.
No open issues 🎉
1 resolved since last review
Review effort: Balanced
|
gfx942 (MI300X) validation: validate-kernel-pr PASS. 1149 passed / 0 failed; independent grid 317 pass. The length-aware split is gated off on gfx942 by its config and runs correctly there when the gfx950 tables are pinned; the split and long-KV tests now run on gfx942. Bench latency within ±0.8% of base. New commits for gfx942: 4efe461. Reports were generated with the repo's validate-kernel-pr skill on a local head, so |
There was a problem hiding this comment.
🔵 Needs a closer look
The packed GPU scheduling and partial-buffer changes require independent exact-head gfx950 correctness and latency validation, especially for length changes during CUDA-graph replay, which this environment cannot perform.
No open issues 🎉
Review effort: Balanced
There was a problem hiding this comment.
🔵 Needs a closer look
The packed GPU work-item mapping and slot-major partial layout require exact-head gfx950 correctness and base/head latency checks under graph replay, which this source-only environment cannot provide.
No open issues 🎉
Review effort: Balanced
There was a problem hiding this comment.
🔵 Needs a closer look
The new GPU work-item mapping and slot-major reduction require exact-head gfx950 CUDA-graph correctness and latency validation, which this source-only review cannot perform and no head-matched report was supplied to establish.
1 open issue
Review effort: Balanced
There was a problem hiding this comment.
🔵 Needs a closer look
The packed GPU mapping and slot-major reduction lack exact-head gfx950 validation for CUDA-graph replay correctness and base-versus-head latency, which static review alone cannot establish.
1 open issue
Review effort: Balanced
There was a problem hiding this comment.
🔵 Needs a closer look
The new GPU work-item mapping and slot-major partial-buffer layout require exact-head gfx950 CUDA-graph correctness and latency validation, but no matching report was supplied and this environment cannot run those checks.
No open issues 🎉
1 resolved since last review
Review effort: Balanced
| # the length-aware split does not exclude these inputs | ||
| + [ | ||
| ("skewed", (8, 2), 4, option, torch.int32) | ||
| for option in ("shuffled_kv_cache", "softcap", "qq_bias") |
There was a problem hiding this comment.
Fixed in 4456f74 and 622db0c: ("skewed", (8, 2), 4, "sinks", torch.int32) runs the group-4 length-aware split (assert num_segments > 1 and split is not None), and sinks + 10.0 makes segment 0's sink dominant so omitting it moves the 120K-token request by 24.0% and the short requests by >=408% (failing the 2% bound). Verified on MI355X (gfx950): max relative L2 error is 0.28%.
There was a problem hiding this comment.
🔵 Needs a closer look
The default-on gfx950 scheduling and partial-buffer layout changes need human review because head-matched graph-replay validation is unavailable and the acknowledged 3–12% short-context cost requires a rollout trade-off assessment.
1 open issue
Review effort: Balanced
| ) | ||
|
|
||
| if single_tile: | ||
| if LENGTH_AWARE_SPLIT: |
There was a problem hiding this comment.
Fixed in 4456f74 and 622db0c: ("skewed", (8, 2), 4, "sinks", torch.int32) exercises the group-4 LENGTH_AWARE_SPLIT merge in _reduce_segments with a dominant sink (sinks + 10.0, moving the 120K-token request by 24.0% if omitted) and compares against ref_paged_attn. Verified on MI355X (gfx950): max relative L2 error is 0.28%.
There was a problem hiding this comment.
🔵 Needs a closer look
The default-on gfx950 work-mapping and partial-buffer changes need maintainer review of graph replay and short-context latency trade-offs because exact-head GPU validation was unavailable.
3 open issues
Review effort: Balanced
There was a problem hiding this comment.
🔵 Needs a closer look
The default-on gfx950 scheduling and partial-buffer changes need maintainer review of the short-context latency trade-off and exact-head GPU correctness and performance, as runtime validation was unavailable here.
2 open issues
1 resolved since last review
Review effort: Balanced
- Compute per-sequence KV segment counts on GPU from seqused_k (int32/int64) for CUDA-graph-safe split-KV launches. - Use slot-major partials [segment, token, head] and flat (work item, KV head) grid grouped by ITEM_RUN per XCD. - Derive SPLIT_NUM_SEGMENTS in compute_segment_params without changing uniform-split NUM_SEGMENTS behavior. - Guard length-aware split to gfx950 Triton 3D bf16 Q, fp8 KV, head dim 64, G <= 4, single query block, no window. - Add G axis and length-aware SPLIT_* keys to gfx950 unified_attention DEFAULT.json (D_EQ_64.G_LEQ_4.DT_bf16_fp8).
- Add shared _assert_request_rel_l2 helper checking per-request relative L2 error and zero output for kv_len == 0. - Add long-KV head-dim-64 bf16-Q/fp8-KV 3D attention test covering both real and 1M captured max_seqlen_k bounds. - Add length-aware split tests for skewed, uniform, empty-slot, 300-seq, int64, shuffled, softcap, qq_bias, and sinks. - Add CUDA graph replay test mutating seqused_k across skewed, uniform, and empty-slot batches at the 1M bound. - Add CPU unit test test_length_aware_split_scope verifying config key guards, G_LEQ_4 scope, and overflow bounds.
- Document G_LEQ_4 scope and SPLIT_* config keys for length-aware KV split in README.md and configs/AGENTS.md. - Add review rule in aiter-ops-triton.instructions.md flagging incomplete SPLIT_* keys or missing G_LEQ_4 scoping.
There was a problem hiding this comment.
🔵 Needs a closer look
The default gfx950 scheduling and partial-buffer changes require maintainer review of graph-replay correctness and the short-context latency trade-off because head-matched GPU validation is unavailable.
2 open issues
Review effort: Balanced


Summary
seqused_k, read on the GPU).max_seqlen_k, which a CUDA graph captures as a 1M bound.SPLIT_NUM_SEGMENTS) above 1.SPLIT_PROGRAMS_PER_CUfrom the gfx950kv_splitentry.test_length_aware_split_scope).Motivation
max_seqlen_k = 1M, so every request gets the same segment count.Changes
seqused_k(int32 or int64).split_budget + num_seqs - 1items at most.ITEM_RUNgroups an item's KV heads on one XCD.[segment, token, head].compute_segment_paramsderivesSPLIT_NUM_SEGMENTSfromSPLIT_SEGMENTS_PER_CU.NUM_SEGMENTS(uniform split) is unchanged.kv_split D_EQ_64.G_LEQ_4.DT_bf16_fp8SPLIT_PROGRAMS_PER_CUkv_split D_EQ_64.G_LEQ_4.DT_bf16_fp8SPLIT_SEGMENTS_PER_CUkv_split D_EQ_64.G_LEQ_4.DT_bf16_fp8SPLIT_SEQ_BLOCK_MIN/MAXattn_3d(any,D_LEQ_128.Q_GEQ_4)SPLIT_RUNS_PER_XCDattn_3dD_LEQ_128.Q_GEQ_4SPLIT_BLOCK_MreduceSPLIT_SEGMENT_BLOCK_MINkv_splitschema gains aGaxis (queries per KV head) afterD.(32,64)/(64,32)(not tuned).skip_reduce(callers read the uniform layout).num_seqs >= 2**15/split_budget + num_seqs >= 2**16/ int32 overflow bounds.attn_3d D_LEQ_128.Q_GEQ_4entry gets two keys.SPLIT_RUNS_PER_XCD: without it, q >= 4 calls fall back to the uniform split (0688eb5a0d).SPLIT_BLOCK_M: 16: BLOCK_M 32 padded q4 blocks to 2x rows.4ba20eba9b(b0318b2d5): the only conflict wasaiter/ops/triton/attention/unified_attention.py._LENGTH_AWARE_KV_SPLIT_KEYS,_LengthAwareSplit,_length_aware_splitand_attn_3d_block_m.gfx950_gluon_supported([Triton/Gluon] unified_attention: public gfx950 Gluon gate predicate #7958) with its private wrapper.95f38f953(ae1db9dca): the only conflict was the import block oftest_unified_attention.py.functoolsfrom this branch,osfrom main.SPLIT_*keys inconfigs/AGENTS.md,aiter/ops/triton/README.md, Copilot instructions, utils docstring.Performance (if applicable)
bench_ua_split.py(below).max_seqlen_k = 1M.e4973c4bed.12f033ff57, an early head of this branch that is not in the current history.d507d3c1avs its merge base5c1489c24:23037623ctest,6fd883da2docs, main merges.--set gptoss/--bound real(below), best of 3 alternating rounds.max_seqlen_kset to the real maximum instead of 1M, the same rows are 1.00× (0.98–1.00× in all six).9c02c030a).SPLIT_BLOCK_M(author, same method, length-aware launch at BLOCK_M 32 → 16):acd39a137vsb6997bdce: every workload within ±1%, output checksums matched.b0318b2d5vs main4ba20eba9b(its second parent, so the diff is this PR alone):bench_ua_split.py.7088-bench.log.Benchmark scripts
./run_bench.sh <gpu> <main-tree> <head-tree> 3for the Kimi rows at the 1M bound.bench_ua_split.pydirectly.--set gptoss/--bound real.bench_ua_split.py:run_bench.sh:Testing
Unit tests added or updated
Performance benchmarks run
Tested on MI250X
Tested on MI300X
MI355X (gfx950),
op_tests/triton_tests/attention/test_unified_attention.py(run by CI).test_triton_unified_attn_qq_bias_padded_query_rows.e4973c4bedf732d9af02acd39a137e7fcdde3ee)acd39a137-k "long_kv or length_aware or graph_replay or split_scope"9c02c030a-k "length_aware or rel_l2"23037623c6fd883da2-k "length_aware or split_scope or rel_l2 or long_kv"b0318b2d5cfde66b86-k "length_aware or split_scope or rel_l2 or long_kv"ae1db9dca7088-full.log)4456f745023037623cenvironment: MI355X, ROCm 10.0.0, torch 2.11.0+rocm10.0.0, Triton 3.8.0.b0318b2d5environment: MI355X, GPU 0, ROCm 10.0.0, torch 2.11.0+rocm10.0.0, Triton 3.8.0.cfde66b86and later: same host.cfde66b86: withseq_num_segmentsforced to one segment (copy in/tmp, reverted):-k length_awarefails 12 of 16.4456f7450: the newsinks(8 Q / 2 KV) andsingle_8klength-aware cases compare against the reference.single_8kis 1 sequence, 64 Q / 64 KV, shortestITEM_RUN.4efe46133crecords the length-aware and long-KV tests passing there (19 cases, gfx950 tables pinned).explain("kv_split", ...)on gfx950 matches:D_EQ_64.G_LEQ_4.DT_bf16_fp8for 8 Q / 2 KV and 64 Q / 64 KV.D_LEQ_64(the entry main uses) for 8 Q / 1 KV and 64 Q / 8 KV.Documentation
Docstrings updated
User guide updated
Performance guide updated
No documentation change is needed, with the reason stated below
SPLIT_*keys and theG_LEQ_4scope are documented in:configs/AGENTS.md.aiter/ops/triton/README.md.Dependencies
Breaking Changes
PR Self-Review
Reviewed revision
4456f74506b4db8366cd56cba91b42bcb9ea8e9fb0318b2d5merges main4ba20eba9b; see Changes for the one conflict and how it was resolved.cfde66b86(test only):segm_maxin the launch spy.ae1db9dcamerges main95f38f953.9c02c030a,d8b4be493,ede8629bbonly shorten docstrings/comments.c05579a79documents theSPLIT_*keys.d507d3c1ascopes the opt-in to up to 4 query heads per KV head (config key, test, docs).23037623cis a test fix.6fd883da2adds the group limit to the README, Copilot rule and utils docstring.0688eb5a0d(reduce kernelca444d6fb5, launcher0688eb5a0d).d507d3c1alater narrowed the config scope.Behavior and intent
seqused_kinstead of the capturedmax_seqlen_k.seqused_kthat makes short uniform decode 3–12% slower (Kimi shapes, group ≤ 4).b6997bdce):acd39a137:find_work_itemcounted empty lanes pastnum_seqs(before & valid).split is None).num_seqs * max_seqlen_kcould wrap for a numpy bound (int()).remap_xcdinstead ofITEM_RUN(1.3–1.8× slower on 7 of 10).max_seqlen_qbelow a real query length drops rows; it is the documented upper bound.d507d3c1a: GPT-OSS TP8 short decode was 0.84× with the split on for every group.Validation and unverified scope
pytest op_tests/triton_tests/attention/test_unified_attention.py(whole file), one MI355X.-kselection above.run_bench.sh(attached), one MI355X.sgl-eval 0.1.3 run gsm8k --load-preset-from-model-id moonshotai/Kimi-K3.Kimi-K3-Quark-MXFP4-AttnFP8, AgentX c16 recipe.k3-agentx-pr-stack@39d944c57d.f9b5308b2(this PR ate2355e700, before the review fixes).e2355e700, before the group scoping.b0318b2d5.kv_len0 row.4ba20eba9band atb0318b2d5.skewed_emptybatch.unified_attention.py, the kernel file and the test file with [Triton/Gluon] [Feature] unified_attention: support causal=False for bidirectional draft verify #7244.git merge-treeof the two heads (ae1db9dca, [Triton/Gluon] [Feature] unified_attention: support causal=False for bidirectional draft verify #7244c8d0b5b55) is conflict-free.32f15945f).PR-specific question
kv_split D_EQ_64.G_LEQ_4.DT_bf16_fp8setsSPLIT_PROGRAMS_PER_CU.D_LEQ_64, so the uniform split is unchanged.attn_3dkeys (SPLIT_RUNS_PER_XCD,SPLIT_BLOCK_M) andreducekey are used only on a length-aware launch.skip_reduce, query block, integer bounds.test_length_aware_split_scopechecks this and that attn_3d/reduce entries for q = 1, 4, 8 carry their keys.Changed op tests
op_tests/triton_tests/attention/test_unified_attention.py:test_triton_unified_attn_3d_long_kv: actual vs captured KV bound.test_triton_unified_attn_3d_length_aware_split:seqused_k, q=8, againstref_paged_attn.segm_max, which slot-major partials the 3D kernel wrote.test_triton_unified_attn_3d_length_aware_split_graph_replay: changesseqused_kbetween graph replays.test_length_aware_split_scope:SEQ_BLOCK.🤖 Generated with Claude Code