Skip to content

perf(rocm): head_dim=128 decode arm -- the ROCm half of #382, default OFF - #767

Open
joral wants to merge 2 commits into
mudler:mainfrom
joral:row/ROCM-DECODE-ATTN-D128-IMPL
Open

perf(rocm): head_dim=128 decode arm -- the ROCm half of #382, default OFF#767
joral wants to merge 2 commits into
mudler:mainfrom
joral:row/ROCM-DECODE-ATTN-D128-IMPL

Conversation

@joral

@joral joral commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

Implements .agents/specs/rocm-decode-attn-d128.md, which landed ahead of this change as #564.

The ROCm half of #382. The CUDA half merged as #425 (66399617); this mirrors it, adopting that arm's flag, default and stated reason rather than inventing new ones.

What changes

d == 128 — the Qwen3-dense / Llama / Mistral head size — reaches the fast decode kernels instead of falling through to the generic PagedAttnOnline. LoadRowEplBf16/StoreRowEplBf16 gain an EPL=4 (uint2) case beside the existing EPL=8/16; the dispatch gates and the two launch switches gain a d == 128 arm. No new kernel and no new algorithm — the kernel bodies were already generic over EPL.

Default OFF, opt in with VT_ATTN_DECODE_D128=1 — the same env var, default and reason as the merged CUDA arm. The arm is correctness-complete but not byte-exact against the kernel it replaces: warp-strided online softmax reduces the KV sequence in a different order than PagedAttnOnline's per-tile loop, so a greedy anchor can move at an exact bf16 tie. Shipping OFF keeps every existing golden byte-identical. The flip owes the near-tie razor, a distributional gate and regen under the ratified-tie rule, and per the spec must be argued per backend — see the reversal below. That is what keeps #382 open.

Reviewer note

Spec §4 item 3 writes the gate as (d == 128 && (decode_d128 || decode_wmma)). This commit implements it without the decode_wmma disjunct, which is what the same item's "Forward reference" paragraph instructs: VT_ATTN_DECODE_WMMA does not exist in the tree, and the flag lands with the rocWMMA arm on its own branch. The difference is intentional; it is visible in the diff before the note explaining it is.

Evidence

gfx1200 (RX 9060 XT, RDNA4, 32 CU), ROCm 7.2.3, $GPU_LOCK held. All figures are a same-binary flag A/B — no rebuild between arms — at 1024-token synthetic prompt, 128 generated, greedy, seed 0, 2 reps per cell agreeing within ~1%.

Model head_dim decode path TPOT OFF TPOT ON speedup
Qwen3-0.6B 128 qg=2 fused 42.53 ms 11.78 ms 3.61x
Qwen3-1.7B 128 qg=2 fused 52.85 ms 21.93 ms 2.41x
Qwen3-4B 128 qg=4 per-head 81.89 ms 39.22 ms 2.09x
Qwen3.5-0.8B 256 — (control) 23.76 ms 23.55 ms 1.01x

Qwen3-4B has no GQA fusion at any head_dim, so its 2.09x isolates the EPL widening from the fusion.

Qwen3.5-0.8B is the negative control and it earned its keep. Its head_dim is 256, so the d == 128 gate provably cannot reach it. Its first OFF rep came in a 33% outlier at 31.14 ms, which a blind 2-rep average would have reported as a ~1.2x "win" for a model the flag cannot affect. Re-run three times: 23.86 / 23.75 / 23.68 against ON's 23.52 / 23.57.

End-to-end output throughput rises less than TPOT on the same runs (0.6B 2.48x, 1.7B 2.05x, 4B 2.02x) because they carry a 1024-token prefill the flag does not touch. TPOT isolates decode; throughput dilutes it.

Concurrency — the advantage grows, it does not compress

Qwen3-1.7B, --num-prompts = 2x concurrency:

Conc tok/s OFF tok/s ON ratio TPOT ratio
1 12.89 24.66 1.91x 2.40x
2 23.27 47.45 2.04x 2.45x
4 39.10 86.86 2.22x 2.46x
8 58.97 147.35 2.50x 2.77x
16 78.43 227.08 2.90x 3.18x

This refuted the prediction made before the run, which reasoned that a tiny grid at concurrency 1 flatters the fast kernel. The dominant effect is the reverse: from c8 to c16 the fallback scales only 1.33x against the arm's 1.54x, and scaling efficiency at c16 relative to perfect-linear-from-c1 is 38% OFF against 58% ON. PagedAttnOnline is the batch-scaling bottleneck, not merely slow per call, so the win is largest in the regime a server actually runs in.

The c1 row reproduces an independently-run four-model sweep to within ~1% (52.85/21.93 there vs 53.40/22.26 here).

Correctness

  • ctest -R 'rocm|cross_device' 5/5, chained directly to the exact-SHA push.
  • New case: "paged attention at Qwen3 geometry (bf16, GQA 2, head_dim 128) matches the CPU oracle", looped over RegisteredDevices(), NMSE <= 5e-4 vs the CPU oracle plus OpProviderStats::declines == 0. Genuinely new coverage — the existing generic cross-device test runs at d=8, f32 and never reached any bf16 EPL-templated kernel, so none of them had bf16 coverage in this suite. (The merged CUDA arm shipped with no test at all.)
  • Because the arm ships OFF and its flag is read into a static const bool — once per process — the default registration can only ever gate the fallback. tests/CMakeLists.txt adds a second invocation with the flag set, same shape as the existing test_dense_gateup_fused_marlin_off_* pair. Verified non-vacuous against the test_voxtral_e2e reports SUCCESS with zero assertions when its weights env var is unset (and ~40 more gates share the shape) #463 trap: 1 case, 6 assertions, not zero.
  • Full ctest 448/455. The 7 failures are proven pre-existing, not asserted: a clean main 2784dd7b worktree built from source with none of this code fails the identical set (only test_op_parity's index shifts 403 -> 404, from the added registration). They are a missing shellcheck, an mmap-RSS assertion, a JSON type error, and the SharedExpertGate ROCm registration gap owed to unmerged feat(rocm): MoE combine/gate ops — SharedExpertGate, MoeCombine, MoeCombineGate (issue #41) #509.
  • agent-preflight fails 9, a strict subset of that same baseline's 10 (differing only by role-undeclared). check-commit-trailers and check-doc-checkpoint both pass against this base.

Carried finding

#382 measured this same EPL=4 arm 1.6x slower on sm_110 / Jetson AGX Thor, where gfx1200 measures it 2-3.6x faster. Recorded, not reconciled — different kernels, different fallbacks, different memory systems. It is why the default-ON flip must be argued per backend rather than once, and it is preserved in the spec rather than averaged away.

Not claimed

This does not close #488. That issue reports an 8.1x per-call gap against vLLM and explicitly asserts no cause; this removes one cause without re-measuring the residual against the oracle (blocked on a Nix-glibc vs container-glibc ABI mismatch). Also out of scope and named in the spec: the dtype gap (ROCm's decode-opt is bf16-only at every head_dim, so 4 of 5 dtype combinations still fall to PagedAttnOnline at d=128 — pre-existing, inherited, not introduced), qg=4/qg=8 fusion, d=128 prefill, and the rocWMMA arm.

Issue: #382
Spec: #564

…efault OFF

FOLLOWING_AGENTS_PROTOCOL

Implements .agents/specs/rocm-decode-attn-d128.md, committed ahead of this
change.

The ROCm mirror of PR mudler#425's CUDA arm for issue mudler#382. Every fast decode kernel
in rocm_paged_attn.hip was gated to d == 256 || d == 512, so head_dim 128 --
Qwen3-dense, Llama and Mistral -- fell straight through to PagedAttnOnline.
LoadRowEplBf16/StoreRowEplBf16 gain an EPL=4 (uint2) case, and both decode
dispatch switches gain a d == 128 branch, so that geometry reaches
PagedAttnDecodeGqaBf16 (qg=2, fused) or PagedAttnDecodeOptBf16T (per-head)
instead.

Gated VT_ATTN_DECODE_D128, DEFAULT OFF -- the same env var, default and reason
as the merged CUDA arm, because the warp-strided online softmax reduces the KV
sequence in a different ORDER than PagedAttnOnline, so a greedy anchor can move
at an exact bf16 tie and OFF keeps every golden byte-identical. No allowlist
entry is owed: the CUDA arm already added VT_ATTN_DECODE_D128.

Testing: a new bf16 Qwen3-geometry (GQA 2, head_dim 128) cross-device case,
where the suite previously had no bf16 coverage of any EPL-templated kernel.
Because the arm ships OFF and its flag is read into a static const bool -- once
per process -- the default registration can only ever gate the fallback, so
tests/CMakeLists.txt registers a second invocation of the same binary with the
flag set. Verified non-vacuous against the issue mudler#463 trap: 1 case, 6
assertions, not zero.

Scope note: this commit is the SCALAR arm only. The rocWMMA d=128 decode spike
that was originally developed alongside it is split into its own spec and its
own PR -- it is a spike with its own (unfiled) issue, and bundling the two put
474 lines of two unrelated kernels in one review. The `|| decode_wmma` disjunct
in the bf16_decode_opt gate belongs to that change, not this one: it only means
anything once a second opt-in kernel for this head size exists.

Row: BACKEND-ROCM
Issue: mudler#382

Following-Agents-Protocol: true
AI-Assisted: true
Assisted-by: Claude:claude-sonnet-5 [Claude Code]
Assisted-by: Claude:claude-opus-5 [Claude Code]
@joral

joral commented Aug 14, 2026

Copy link
Copy Markdown
Contributor Author

Follow-up: the oracle comparison this PR listed as blocked is no longer blocked, and here is the number

The PR body's "Not claimed" section says the residual gap to vLLM was not re-measured because the same-tool comparison was blocked on a Nix-glibc-vs-container ABI mismatch. That diagnosis was wrong and I'm retracting it. Our binary runs inside the pinned oracle container fine; the earlier failures were self-inflicted (exporting LD_LIBRARY_PATH container-wide, which breaks the container's own tools, plus a bind mount that silently yielded nothing and looked exactly like a missing ELF interpreter).

Sanity check first, since running our binary against the container's ROCm rather than the host's is a substitution worth proving inert — in-container matches native:

Qwen3-0.6B, 1024 in / 128 out, conc 1 native in container
TPOT, flag unset 42.53 ms 42.79 ms
TPOT, VT_ATTN_DECODE_D128=1 11.78 ms 12.03 ms

Both sides in the same container, matched workload (Qwen3-0.6B, 1024 in / 128 out, concurrency 1, 8 prompts, warmup discarded, 3 reps), oracle = vLLM 555967922 in production config via vllm bench serve:

TPOT reps mean vs oracle
ours, flag unset 42.54 / 42.46 / 42.19 42.40 ms 6.35x slower
ours, VT_ATTN_DECODE_D128=1 11.97 / 11.38 / 11.66 11.67 ms 1.75x slower
vLLM 555967922 6.57 / 6.90 / 6.58 6.68 ms

So this arm closes the decode gap from 6.35x to 1.75x against the oracle on this shape.

What this is not

One measurement note worth recording: at --num-prompts 2 the oracle gave TPOT 6.96 ms and 13.45 ms on consecutive reps — a ~2x spread that averages to a plausible-looking and entirely fictional number. The figures above use 8 prompts with a discarded warmup, where both sides hold to ~±0.3 ms.

One stale line on main, if you want it fixed

.agents/specs/rocm-decode-attn-d128.md (merged in #564) says in §6:

…(blocked on the container/glibc issue recorded in the WMMA spec)

That is now false, and it is the kind of line that stops the next person from trying. Happy to send a one-line PR changing it to "not run — not blocked", or to fold it into this PR, or to leave it — your call. The reproduction details are host-specific (nix store paths, local mounts) so I'd keep those out of the repo and only correct the claim.

FOLLOWING_AGENTS_PROTOCOL

CI on mudler#767 failed `check-commit-trailers` with "range base must be an ancestor
of range head". Not a trailer defect: main had advanced 39 commits past this
branch's base (2784dd7), so main's tip was no longer an ancestor of the head
and the checker could not form a range at all.

Merged rather than rebased -- this repo's convention (`merge: origin/main into
row/<ID>` appears throughout the history), and it keeps the pushed SHA a
fast-forward instead of needing a force-push.

No conflicts. Both auto-merged test files verified by hand rather than trusted:
the head_dim-128 cross-device case and the VT_ATTN_DECODE_D128 ctest
registration are both present and intact, and main touched neither
rocm_paged_attn.hip nor the d128 dispatch.

Re-gated on the merge result, gfx1200, $GPU_LOCK held: build 599/599,
`ctest -R 'rocm|cross_device'` 5/5 including the flag-on registration.

Row: BACKEND-ROCM
Issue: mudler#382

Following-Agents-Protocol: true
AI-Assisted: true
Assisted-by: AGENT:claude-opus-5 [Claude Code]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ROCm gfx1200: PagedAttnOnline is 8.1x slower per call than vLLM's paged-attention kernel (41.1us vs 5.10us)

1 participant