Skip to content

[Triton/Gluon] Unified attention: opt-in prefill configs for head sizes 129+ - #5409

Merged
vgokhale merged 13 commits into
ROCm:mainfrom
cpersson-amd:ua_regression_workaround
Nov 20, 2026
Merged

vgokhale merged 13 commits into
ROCm:mainfrom
cpersson-amd:ua_regression_workaround

Conversation

@cpersson-amd

Copy link
Copy Markdown
Contributor

Motivation

This PR covers a Triton regression raised in #4137: Unified attention prefill regressed on gfx950 for head sizes 129 and above. On the Qwen3.5-397B debug shape the kernel went from about 4ms on Triton 3.6 to 16ms on 3.7 and 12ms on 3.8. This is due to three separate problems:

Register pressure. At BLOCK_M=128 a head size in 129-255 pads to a 256-element accumulator, and the kernel needs about 470 VGPRs (it uses no LDS at all). waves_per_eu=2 caps the budget at 256, so the excess spills to scratch inside the KV loop.

An LLVM scheduler regression in Triton >= 3.7. The same config that fit on 3.6 does not on 3.7+, which is what turned this from latent to visible. TTIR and TTGIR are byte-identical across the three versions and the LLVM IR instruction mix is the same; only the scratch size differs, so it is the AMDGPU machine scheduler producing longer live ranges, not anything in Triton's own passes.

Config shadowing. Because the lookup gives the leftmost axis priority, D_GEQ_256 outranks Q_GEQ_256, so head sizes 256+ in prefill were picking a BLOCK_M=16 entry meant for decode. That is why d=256 was slower than d=192 despite doing less work per program.

The goal is to fix all three without changing the default behavior so when a fix eventually lands in Triton, this change does not end up regressing the performance. The tuned configs trade occupancy for registers against one measured shape family, so they are exposed as an opt-in rather than made the default.

Technical Details

Two files change: the gfx950 DEFAULT.json and unified_attention_utils.py.

An opt-in config section. A new attn_2d.OPT_IN section holds the retuned prefill entries and is merged into the lookup only when AITER_TRITON_UA_FAST_PATH=1. With the variable unset nothing changes: the section is never consulted, and all five pre-existing sections of DEFAULT.json are byte-identical to before. The core fix in these entries is waves_per_eu=1, which lifts the VGPR budget from 256 to 512 and eliminates the spill. It is scoped to head sizes 129+ (D_GEQ_129 / D_GEQ_256 keys) because sizes below that never spilled, and halving their occupancy target only costs them speed.

The AMD backend workaround. On top of the register fix, the opt-in entries can pass amdgpu-sched-strategy=iterative-minreg through Triton's llvm_fn_attrs option. This overrides the AMDGPU machine scheduler with a register-minimising strategy, recovering a further ~25% on large caches. It is not unconditionally good, so it sits in a LARGE_KV sub-block behind three guards:

  • Cache size. Under 2**31 elements the backend indexes the cache with 32-bit buffer ops instead of 64-bit global loads. Against that different code the attribute costs about 3x rather than saving 25%. The guard counts elements, so if what the backend really tests is bytes, a borderline cache is declined rather than wrongly taken.
  • Dtype. The overrides pay off for fp8 and cost bf16 about sixfold, so only the DT_fp8_fp8 keys carry them.
  • Triton support. llvm_fn_attrs is read off the backend's own options rather than inferred from a version number, and the block is skipped with a warning where the option does not exist.

Test Plan

A standalone harness replays the Qwen3.5-397B debug shape and swaps configs through the lookup:

  • Coverage sweep across head sizes 64-512, both prefill and decode, small (128-block) and large (4795-block) KV caches, fp8 and bf16, with the flag both unset and set. Each run reports the matched config entry, p50 latency, and the compiled kernel's scratch (register spill) bytes.
  • Guard tests that exercise each of the three LARGE_KV gates: large cache with the option supported (applies), small cache (size guard declines), and a backend without llvm_fn_attrs (support guard declines). Also asserts the LARGE_KV sub-block never leaks into the launched config.
  • Numerics check comparing the opt-in base and the large-KV overrides for bitwise-identical output, since the overrides only move scheduling and occupancy.
  • Regression guard on the default by diffing every pre-existing section of DEFAULT.json against HEAD to confirm the flag-off path is untouched.

Test Result

All pre-existing DEFAULT.json sections are byte-identical to HEAD; the only addition is attn_2d.OPT_IN. The guard tests pass (overrides apply only on a large fp8 cache with a supporting Triton, and never leak), and the opt-in base and large-KV overrides are bitwise identical.

gfx950, fp8, prefill. Small cache is 128 blocks, large is 4795. Each cell is p50 latency in ms (±0.1-0.2 ms run to run), with kernel scratch (register spill) in bytes in parentheses; "unchanged" means the opt-in section holds no entry for that head size, so the flag has no effect.

head size off, small cache (ms) off, large cache (ms) on, small cache (ms) on, large cache (ms)
64, 128 2.5-2.9 2.5-3.1 unchanged unchanged
160, 192, 224 5.2-5.3 (132 B) 12.1-12.2 (288 B) 5.3 (0 B) 4.6 (20 B)
256 10.0 12.5 5.2 (0 B) 4.7 (20 B)
512 24.8 28.9 unchanged unchanged

bf16, same shape, large cache is 2400 blocks. bf16 stays on the opt-in base config, since the large-KV overrides do not apply to it:

head size off, small cache (ms) off, large cache (ms) on, small cache (ms) on, large cache (ms)
192 11.7 (236 B) 31.1 (920 B) 7.1 (0 B) 8.7 (0 B)
256 25.0 34.8 7.2 (0 B) 8.7 (0 B)

Spill drops from up to 920 B to at most 20 B on every affected head size (0 B except on the fp8 large cache, where the minreg override leaves 20 B). The d=256 bf16 row is the shadowing fix on its own; the d=192 row is the register fix, worth 3.6x on the large cache. Decode is untouched under both settings, as are head sizes 64, 128 and 512.

Notes and follow-ups

  • The opt-in section has four entries where two would do. D_GEQ_256 shadows D_GEQ_129.Q_GEQ_256, so the config has to be repeated at each D bound, and again split by dtype because only fp8 takes the LARGE_KV block.
  • These configs were tuned against one shape family. waves_per_eu=1 trades occupancy for registers, which is why this is opt-in rather than the default.

Submission Checklist

@cpersson-amd
cpersson-amd requested a review from a team September 10, 2026 15:31
@github-actions github-actions Bot changed the title Unified attention: opt-in prefill configs for head sizes 129+ [Triton/Gluon] Unified attention: opt-in prefill configs for head sizes 129+ Sep 10, 2026
@github-actions

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; main branch always runs both MI35X and MI300X
multigpu 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 5409 --add-label <label>

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 opt this PR out.

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

The opt-in accepts undocumented values, warning fallback can flood logs, and the new selection paths lack automated coverage.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

Adds an opt-in gfx950 unified-attention prefill fast path for large head sizes while preserving default behavior.

Changes:

  • Adds tuned prefill configurations for head sizes 129–511.
  • Applies large-KV compiler overrides when supported.
  • Adds environment-gated config merging and runtime derivation.
File summaries
File Description
unified_attention_utils.py Implements opt-in loading and large-KV override resolution.
DEFAULT.json Adds gfx950 prefill tuning entries.
Review details

Suppressed comments (2)

aiter/ops/triton/utils/unified_attention_utils.py:215

  • On a Triton version without llvm_fn_attrs, this warning runs on every affected attention invocation because _resolve_large_kv is deliberately outside the cached lookup. With warning logging enabled by default, an opt-in workload can flood logs and add host-side overhead in the hot path; cache the warning per unsupported option set (and check cache size before probing support) so the fallback is reported once.
    if unsupported:
        _LOGGER.warning(
            "unified attention: this Triton takes no %s, so the opt-in entry's "
            "large-KV overrides are unavailable",
            ", ".join(unsupported),
        )

aiter/ops/triton/utils/unified_attention_utils.py:330

  • The checked-in unified-attention tests run only with the flag unset, and no test references AITER_TRITON_UA_FAST_PATH, OPT_IN, or LARGE_KV. Consequently the new merge precedence, dtype/size guards, unsupported-option stripping, and preservation of the flag-off path are not regression-tested even though this test suite is run by CI. Add focused tests for flag off/on and each LARGE_KV gate described in the PR.
    if _USE_OPT_IN:
        # A merge, not an edit: an opt-in key may be new to the table, and then
        # has to enter the lookup as a candidate rather than replace a config.
        table = {**table, **config.get(op + _OPT_IN, {})}
  • Files reviewed: 2/2 changed files
  • Comments generated: 1
  • Review effort level: Balanced

💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

mustafayildirim added a commit to mustafayildirim/aiter that referenced this pull request Sep 10, 2026
MI355X benchmarks (cagrikymk) show the composite entries force
BLOCK_M=128 at head 256/512 with 2-4 warps, exceeding the 256-VGPR
budget at waves_per_eu=2: 300-600 spills per kernel, up to 3.4KB
scratch, geomean ~8.8x slower on the affected shapes. On triton
3.7.0 one entry additionally aborts the compiler (LLVM assert).

Our own gfx950 e2e (MI350X) also showed no gain (~0.4%, noise).
gfx950 large-head prefill tuning is better served by ROCm#5409's opt-in
mechanism (waves_per_eu=1 lifts the VGPR budget to 512), which lands
per-shape behind AITER_TRITON_UA_FAST_PATH instead of changing
defaults.

Keep the gfx942 keys: the 5.9% e2e win there was measured with
BLOCK_M=128 active on MI325X (head 256/512, fp8 KV) with no
spill-related regression reported.

Signed-off-by: Mustafa Yildirim <[email protected]>
@cagrikymk

Copy link
Copy Markdown
Contributor

@cpersson-amd Did you have a chance to look at why the register spill happens in newer triton versions?

@cpersson-amd

Copy link
Copy Markdown
Contributor Author

@cpersson-amd Did you have a chance to look at why the register spill happens in newer triton versions?

I think the spills are due to a change in the LLVM AMDGPU scheduler. I asked Claude to look for changes in LLVM between Triton 3.6 and 3.7 that could cause this regression. This PR llvm/llvm-project#147653 was pointed out as the possible regression point.

This was briefly tested by running the identical kernel IR through Triton 3.7's pinned LLVM (ac5dc54d, llc v23.0.0git), toggling only the #147653 mechanism via its knob (amdgpu-scheduler-pending-queue-limit, where 0 disables the pending-queue examination):

pending-queue-limit ScratchSize spill stores
0 (disabled = pre-#147653) 84 B 9
1 84 B 9
2 88 B 8
4 148 B 12
8 / default 168 B 13

This PR was also suggested as a potential fix for this issue: llvm/llvm-project#213116.

@cpersson-amd
cpersson-amd requested a review from farlukas October 7, 2026 12:39

@farlukas farlukas left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Looks good, could you clean up the code a bit and remove some of the code comments, they seem excessive for your change.

@cpersson-amd

Copy link
Copy Markdown
Contributor Author

Thanks for the review @farlukas! I cleaned up the code a bit and tests are passing. Let me know if you think anything else needs to be changed.

@azaidy
azaidy requested a review from farlukas October 22, 2026 18:51
farlukas
farlukas previously approved these changes Oct 22, 2026
tkarttunen added a commit to tkarttunen/aiter that referenced this pull request Oct 27, 2026
A QK head that is not a power of two is padded to the next one, so head 192
runs a 256-wide Q.K dot with a quarter of it masked out. On gfx950 the padded
128-row 2D tile needs about 470 VGPRs (ROCm#5409), which caps the block size the
tuner can use for long prefill.

The 2D and 3D Triton kernels gain HEAD_SIZE_LO / HEAD_SIZE_HI constexprs. When
set, they load Q and K in those two chunks and accumulate two dots:

    S = tl.dot(Q, K)
    S = tl.dot(Q_hi, K_hi, acc=S)

HEAD_SIZE_LO = 0, the default, compiles the kernels exactly as before. Static
asserts require the two chunks to add up to HEAD_SIZE and reject a shuffled KV
cache.

The wrapper's _head_split() sets 128 + 64 for head 192 with a BF16 or FP16
query and KV cache, no sliding window and an unshuffled cache: the case that
has been measured (MiMo-V2.6's full-attention layers). Other heads, FP8, and
sliding-window calls keep the padded dot until they are measured with the split.

Tests: _head_split cases, and Triton-backend correctness for head 192 (V 128
and V 192, BF16 and FP16, block sizes 1 and 16) on a verify-like batch and a
short extend (both on the 3D kernel) and on a 2048-token prefill chunk (2D).

Co-authored-by: Cursor <[email protected]>
@aiter-bot

aiter-bot commented Nov 2, 2026 •

Copy link
Copy Markdown

WAITING ON AUTHOR

PR Self-Review

Revision b44e824ce535 · 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. Which exact workload keys consume these configuration changes, and what evidence shows that unrelated shapes keep their previous selection?
  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 — missing ### Reviewed revision in the PR description
  • FAIL — missing ### Behavior and intent in the PR description
  • FAIL — missing ### Validation and unverified scope in the PR description
  • FAIL — missing ### PR-specific question in the PR description
  • FAIL — missing ### Changed op tests in the PR description
  • FAIL — Reviewed revision must contain at least the first 7 characters of the current head SHA
  • FAIL — Behavior and intent has no substantive answer
  • FAIL — Validation and unverified scope has no substantive answer
  • FAIL — PR-specific question has no substantive answer
  • FAIL — changed op test not explained in Changed op tests: op_tests/triton_tests/attention/test_unified_attention.py
  • FAIL — Changed op tests must explain why each changed op test is necessary and non-redundant

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

@cpersson-amd

cpersson-amd commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor Author

Hi @farlukas @azaidy, thanks for the review and approval! CI is green, is anything else needed before this can be merged? If @cagrikymk's or @valarLip's review is still required, I'm happy to answer questions.

@cagrikymk

cagrikymk commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Hi @farlukas @azaidy, thanks for the review and approval! CI is green, is anything else needed before this can be merged? If @cagrikymk's or @valarLip's review is still required, I'm happy to answer questions.
Human review:
I suggest tuning as is, there might be configs that can work without providing llir flags.

Also, for the modified configs, please try to see how config routing changes and how that affects perf.
I saw some slowdowns and I think it is because your configs have side effects in terms of config selection. Please try to keep config keys specific, or otherwise provide a more detailed perf. report that covers affected cases.

One more thing, the same issues might not be triggered for 3.8+. If you are targeting 3.7 specifically, what is the reasoning behind?

Claude review:

Good

  • With the flag off, all 480 lookup keys I enumerated resolve the same as on main, so the default path doesn't change.
  • bf16 at D=160/192/224 is 40–70% faster, and bf16 at D=256 is 64–78% faster (it was falling into a decode config on main). Accuracy against an fp32 reference matches baseline.

Issues with the flag on

  1. Crash: bf16 at D=320 (any head size between 256 and 512) fails with OutOfResources: shared memory (272304 > 163840). The new D_GEQ_256.Q_GEQ_256 entry uses BLOCK_M=128 with stages=2, which doesn't fit once the head is padded to 512. Main runs this shape.
  2. bf16 at D≤128 is 6–13% slower. The opt-in section replaces the existing D_LEQ_128.Q_GEQ_256 entry, dropping SPLIT_UNMASKED_LOOP and moving from stages 2 / waves_per_eu 1 to stages 1 / waves_per_eu 2. The PR description says D=64/128 is unchanged, but that only covers fp8.
  3. Existing D=256 fp8 entries are bypassed. D_LEQ_256 keys are matched before D_GEQ_256, so the tuned sliding-window and shuffled-cache entries are no longer used. Sliding window (window 1024) is 15% slower; I didn't time the shuffled-cache case.
  4. fp8 on current main: D=160–224 is 3–14% slower than main. Main's fp8 times here are already about 4.2–4.6 ms on the [Regression] Triton 3.7.0 causes ~4x regression in unified_attention on gfx950 #4137 shape. The one fp8 win I saw is the [Regression] Triton 3.7.0 causes ~4x regression in unified_attention on gfx950 #4137 shape at D=256, at about 11%.
  5. LARGE_KV doesn't help in general. For fp8 on a large cache, the stages-2 / waves_per_eu-1 config without LARGE_KV is 7–28% faster than main on plain prefill. With LARGE_KV the same cases are 3–8% slower. It only helps the [Regression] Triton 3.7.0 causes ~4x regression in unified_attention on gfx950 #4137 mixed-batch shape, so cache size doesn't predict when it pays off.

Suggestions

  • Keep the bf16 entries for D=160–256, and consider making them the default. The D=256 decode-config fallback looks like a bug on main.
  • Drop the D_LEQ_128 override, and fix or drop the D≥256 bf16 entry.
  • Re-measure the fp8 entries against current main, and keep the existing sliding-window and shuffled-cache entries for D=256 reachable.
  • Rethink or drop the LARGE_KV gate.
  • Add a test that runs with the flag on and covers bf16 at D=320.

My results were measured on Triton 3.8 only; I haven't checked Triton 3.7.

… default

Replace the opt-in section (AITER_TRITON_UA_FAST_PATH, LARGE_KV and the
llvm_fn_attrs scheduler override) with six D_LEQ_256 prefill entries in the
default attn_2d table, retuned on current main and Triton 3.8. They are keyed
on dtype (DT_fp8_fp8, DT_bf16_any) and on sliding window and shuffled cache, so
only prefill at head sizes 129-256 with an fp8 or bf16 query changes config.

Add a prefill test for head sizes 160-320 on the Triton backend.
@cpersson-amd

Copy link
Copy Markdown
Contributor Author

Thanks for the thorough review @cagrikymk. I've reworked the PR along those lines:

  • No flag, no LLVM attributes. The opt-in section, AITER_TRITON_UA_FAST_PATH, LARGE_KV and the amdgpu-sched-strategy override are gone. The configs are now default entries, retuned from scratch on current main with Triton 3.8 (the version main pins, so not 3.7). waves_per_eu=1 alone removes the spill.

  • D_LEQ only, specific keys. There are six D_LEQ_256.Q_GEQ_256 entries, each keyed on dtype (DT_fp8_fp8, DT_bf16_any), with separate sliding-window and shuffled-cache variants. No existing entry is changed and unified_attention_utils.py matches main.

  • Routing. A lookup diff against main over 1120 cases (head sizes 64-576, decode to prefill, window, shuffle, four dtype pairs) shows 144 changing entry, all of them prefill at head sizes 129-256 with an fp8 or bf16 query. That fixes the issues you found: head sizes <=128 and 320 resolve as on main, and the D_LEQ_128 override is gone. At 256, sliding-window and shuffled caches get their own tuned entries, faster than main's.

  • Perf report. The description has a 936-run A/B of main's table against the new one on the default and Triton backends, at head sizes 128-320, with plain, softcap, sliding-window and shuffled-cache shapes. Geomean speedup over the cases whose entry changed, default backend:

    plain softcap sliding window shuffled
    fp8 1.33x 1.05x 1.55x 1.36x
    bf16 2.28x 2.11x 2.40x 3.64x
    bf16 query, fp8 KV 2.93x 2.10x 2.66x 1.28x

    Cases whose entry didn't change stay within +-2% of main. With backend="triton", the bf16 decode-config fallback at 256 is fixed too (34.7 -> 5.8 ms on the [Regression] Triton 3.7.0 causes ~4x regression in unified_attention on gfx950 #4137 batch). The one regression is fp8 with softcap, 8-10% slower on two shapes. Softcap isn't a config axis, and no config in the sweep beat main there without losing the fp8 gain elsewhere.

  • Tests. I added test_triton_unified_attn_prefill_head_sizes (head sizes 160/192/256/320, three dtype pairs, with and without a window, Triton backend), which covers bf16 at 320.

While testing I found two failures that already exist on main: the Triton 2D kernel gives wrong output with a shuffled KV cache at head sizes 160, 192 and 320 (any config, main's included), and bf16 at 320 with a shuffled cache exceeds shared memory. I left both out of this PR; happy to open an issue.

@cagrikymk

Copy link
Copy Markdown
Contributor

Thanks for the thorough review @cagrikymk. I've reworked the PR along those lines:

  • No flag, no LLVM attributes. The opt-in section, AITER_TRITON_UA_FAST_PATH, LARGE_KV and the amdgpu-sched-strategy override are gone. The configs are now default entries, retuned from scratch on current main with Triton 3.8 (the version main pins, so not 3.7). waves_per_eu=1 alone removes the spill.

  • D_LEQ only, specific keys. There are six D_LEQ_256.Q_GEQ_256 entries, each keyed on dtype (DT_fp8_fp8, DT_bf16_any), with separate sliding-window and shuffled-cache variants. No existing entry is changed and unified_attention_utils.py matches main.

  • Routing. A lookup diff against main over 1120 cases (head sizes 64-576, decode to prefill, window, shuffle, four dtype pairs) shows 144 changing entry, all of them prefill at head sizes 129-256 with an fp8 or bf16 query. That fixes the issues you found: head sizes <=128 and 320 resolve as on main, and the D_LEQ_128 override is gone. At 256, sliding-window and shuffled caches get their own tuned entries, faster than main's.

  • Perf report. The description has a 936-run A/B of main's table against the new one on the default and Triton backends, at head sizes 128-320, with plain, softcap, sliding-window and shuffled-cache shapes. Geomean speedup over the cases whose entry changed, default backend:

    plain
    softcap
    sliding window
    shuffled

    fp8
    1.33x
    1.05x
    1.55x
    1.36x

    bf16
    2.28x
    2.11x
    2.40x
    3.64x

    bf16 query, fp8 KV
    2.93x
    2.10x
    2.66x
    1.28x

    Cases whose entry didn't change stay within +-2% of main. With backend="triton", the bf16 decode-config fallback at 256 is fixed too (34.7 -> 5.8 ms on the [Regression] Triton 3.7.0 causes ~4x regression in unified_attention on gfx950 #4137 batch). The one regression is fp8 with softcap, 8-10% slower on two shapes. Softcap isn't a config axis, and no config in the sweep beat main there without losing the fp8 gain elsewhere.

  • Tests. I added test_triton_unified_attn_prefill_head_sizes (head sizes 160/192/256/320, three dtype pairs, with and without a window, Triton backend), which covers bf16 at 320.

While testing I found two failures that already exist on main: the Triton 2D kernel gives wrong output with a shuffled KV cache at head sizes 160, 192 and 320 (any config, main's included), and bf16 at 320 with a shuffled cache exceeds shared memory. I left both out of this PR; happy to open an issue.

Thanks!

I have another PR that changes the way shuffling works so it doesnt have to pin the block size to the page size. I will take a look at the odd head sizes and maybe add an assert so it doesnt fail silently.

In the meantime, this PR LGTM!

@cagrikymk cagrikymk closed this Nov 13, 2026
@cagrikymk cagrikymk reopened this Nov 13, 2026
@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 5409 --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.

@cagrikymk

Copy link
Copy Markdown
Contributor

Closed and reponed the PR by mistake 🫨

tkarttunen added a commit to tkarttunen/aiter that referenced this pull request Nov 17, 2026
A QK head that is not a power of two is padded to the next one, so head 192
runs a 256-wide Q.K dot with a quarter of it masked out. On gfx950 the padded
128-row 2D tile needs about 470 VGPRs (ROCm#5409), which caps the block size the
tuner can use for long prefill.

The 2D and 3D Triton kernels gain HEAD_SIZE_LO / HEAD_SIZE_HI constexprs. When
set, they load Q and K in those two chunks and accumulate two dots:

    S = tl.dot(Q, K)
    S = tl.dot(Q_hi, K_hi, acc=S)

HEAD_SIZE_LO = 0, the default, compiles the kernels exactly as before. Static
asserts require the two chunks to add up to HEAD_SIZE and reject a shuffled KV
cache.

The wrapper's _head_split() sets 128 + 64 for head 192 with a BF16 or FP16
query and KV cache, no sliding window and an unshuffled cache: the case that
has been measured (MiMo-V2.6's full-attention layers). Other heads, FP8, and
sliding-window calls keep the padded dot until they are measured with the split.

Tests: _head_split cases, and Triton-backend correctness for head 192 (V 128
and V 192, BF16 and FP16, block sizes 1 and 16) on a verify-like batch and a
short extend (both on the 3D kernel) and on a 2048-token prefill chunk (2D).

Co-authored-by: Cursor <[email protected]>
@vgokhale
vgokhale merged commit 9e1d318 into ROCm:main Nov 20, 2026
1 check passed
azaidy pushed a commit that referenced this pull request Nov 21, 2026
… head sizes 257-511 (#8400)

test_triton_unified_attn_prefill_head_sizes (from #5409) fails on gfx942
for BF16, head_size=320, seq_lens0: the kernel requests 131072 bytes of
shared memory and the device has 65536.

Head size 320 pads to 512. On a 304-CU part this case launches too few 2D
programs, so it runs the 3D split-KV kernel. kv_split "any" gives it
TILE_SIZE 64, so the K and V tiles need 131072 bytes with a 16-bit KV
cache. The head_size >= 512 rule that keeps the 3D kernel off for large
heads does not apply, because it checks the head size before padding.

Add a kv_split entry for head sizes 257-511 with a 16-bit KV cache. It is
the "any" entry with TILE_SIZE_MAX and SEGMENT_TILE_MAX set to 32. An fp8
KV cache already fits and keeps its config.

Compiled every case of the test for gfx942 (wave64, CU_NUM=304,
Triton 3.8.0): on main only this case is above 65536 bytes; with this
change it uses 65536 bytes and the other 47 cases do not change.
tkarttunen added a commit to tkarttunen/aiter that referenced this pull request Nov 23, 2026
A QK head that is not a power of two is padded to the next one, so head 192
runs a 256-wide Q.K dot with a quarter of it masked out. On gfx950 the padded
128-row 2D tile needs about 470 VGPRs (ROCm#5409), which caps the block size the
tuner can use for long prefill.

The 2D and 3D Triton kernels gain HEAD_SIZE_LO / HEAD_SIZE_HI constexprs. When
set, they load Q and K in those two chunks and accumulate two dots:

    S = tl.dot(Q, K)
    S = tl.dot(Q_hi, K_hi, acc=S)

HEAD_SIZE_LO = 0, the default, compiles the kernels exactly as before. Static
asserts require the two chunks to add up to HEAD_SIZE and reject a shuffled KV
cache.

The wrapper's _head_split() sets 128 + 64 for head 192 with a BF16 or FP16
query and KV cache, no sliding window and an unshuffled cache: the case that
has been measured (MiMo-V2.6's full-attention layers). Other heads, FP8, and
sliding-window calls keep the padded dot until they are measured with the split.

Tests: _head_split cases, and Triton-backend correctness for head 192 (V 128
and V 192, BF16 and FP16, block sizes 1 and 16) on a verify-like batch and a
short extend (both on the 3D kernel) and on a 2048-token prefill chunk (2D).

Co-authored-by: Cursor <[email protected]>
tkarttunen added a commit to tkarttunen/aiter that referenced this pull request Nov 23, 2026
…ds at main's retuned prefill defaults

ROCm#5409 retuned the gfx950 prefill defaults for head sizes 129-256 (the D_LEQ_256
entries). The guards that keep non-split prefill off this PR's head-192 entry
still pinned the previous generic config, which would have undone that retune
for heads 129-191 and for sliding-window and shuffled-KV prefill at 192. They
now carry the D_LEQ_256 values, so only full-attention BF16 prefill at head 192
changes. The config test expects the same.

Co-authored-by: Cursor <[email protected]>
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.

6 participants