Skip to content

Add paged_attention_ragged_nhd - #2919

Draft
apinge wants to merge 6 commits into
ROCm:Qwen3.5_devfrom
apinge:pa_ragged_nhd
Draft

apinge wants to merge 6 commits into
ROCm:Qwen3.5_devfrom
apinge:pa_ragged_nhd

Conversation

@apinge

@apinge apinge commented Apr 27, 2026

Copy link
Copy Markdown
Contributor

Motivation

Technical Details

Test Plan

Test Result

Submission Checklist

@zufayu

zufayu commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

@apinge This draft has been open since April 2026 with no review activity since. Is paged_attention_ragged_nhd still something you plan to pursue? If yes, please rebase onto current main and mark it ready. If there's no update within ~2 weeks, we'll close this to keep the PR queue clean — it can always be reopened or resubmitted.

@github-actions

github-actions Bot commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

No activity for 15 days, so this is now labelled stale. A push or a comment clears it; keep-open exempts it.

@github-actions github-actions Bot added the stale The PR hasn't been updated in 2 weeks label Oct 7, 2026
Arist12 added a commit to Arist12/FlyDSL that referenced this pull request Dec 3, 2026
SGLang's aiter backend decodes with page size 1 on HIP: the cache holds
one [num_kv_heads, head_dim] row per token slot and each sequence names
its slots through kv_indptr/kv_indices, so aiter calls
paged_attention_ragged.  FlyDSL has no kernel for that layout
(pa_decode_tile takes 16- or 64-token pages in the vectorized 5-D
layout), which leaves the layout without a portable fast path.

Add pa_decode_ragged_fast for the serving geometry: one query row per
sequence, BF16 K/V/output, head_dim 256, 1..16 query heads per KV head,
at most 64 sequences, and at least 16K slots per sequence on average
(kv_indices.numel() >= 16384 * num_seqs; the predicate cannot read
device lengths).  One CTA owns one (sequence, KV head, global KV split);
its four waves walk 16-token tiles and run online softmax
independently, then merge once in LDS.  QK runs as
mfma_f32_16x16x32_bf16 with tokens on M and query heads on N, so P stays
in registers for the PV MFMA; V is staged in a wave-private LDS tile,
retired with s_waitcnt lgkmcnt(0), and read back transposed with
ds_read_b64_tr_b16.  The split count comes from the device's CU count
and the batch's total slot bound.  A second kernel merges the KV splits,
with a single-launch path for small batches.

The kernel is not wired into a page-1 entry yet: this adds the kernel
and its shape/dtype/stride/device/arch acceptance predicate so a caller
(or the generalized ragged kernel) can select it.  The predicate refuses
every non-gfx950 architecture because the kernel uses the gfx950-only
ds_read_b64_tr_b16 LDS read; the entry asserts the same condition.
Other shapes are refused by the predicate, so no existing path changes.

MI350X, public API, symmetric A/B/B/A against production's aiter HIP
paged_attention_ragged, 5 rounds x 50 calls per arm, per-call CUDA
events.  Two runs of the ten production decode shapes (B = 1, 2, 4, 8
or 12 sequences, 106,960 tokens each, 8 query heads, 1 KV head,
head_dim 256) measure 1.543x and 1.560x geomean; combined over the two
runs it is 1.552x, per-shape 1.371-1.954x.  Same-arm A/A pair medians
are ~1.01 in both runs.

A generality sweep over 18 shapes (head_dim 128/256, group 8 with 1 and
2 KV heads, group 16 with 1 KV head, a group-17 refusal, Q 1/2/4,
varlen, 64/65 sequences, 1-262,144 tokens) accepts six shapes and
refuses twelve in the predicate (head_dim, Q>1, group>16, more than 64
sequences, batch-average context below 16K slots, or a non-gfx950
arch).  The six accepted shapes are 1.274x geomean faster than HIP
(0.977-1.547x); the exact-16K-gate shape is 0.977x in this run (a 2%
loss against HIP).  A mixed-length batch [65536,1,1,1] (average
16,384.75 slots/sequence) is 2.10x faster than HIP; [32768,1,1,1]
(average 8,192.75) is refused, which is conservative.

Correctness: 18 tests, including an fp64 reference on nine length sets
with planted keys and a sparse slot pool, the 4-D cache view,
non-contiguous query/output and empty-index refusals, a real 65-sequence
refusal, a monkeypatched gfx942 arch refusal, group 1/16, repeated
launches and the mixed-length gate.  max |out - ref| /
(0.01 * (|ref| + rms/2)) is 0.175-0.194 on the ten production shapes
and 0.175-0.191 on the six accepted generality shapes; all finite.
FlyDSL 0.5.5 passes 18/18.

ISA (gfx950, production shape, 0 spills): attention 206 VGPR, 36 SGPR,
45,072 B LDS; reduce 88 VGPR, 31 SGPR, 3,072 B LDS.

No new dependencies.  No open FlyDSL PR adds a page-1 ragged decode
kernel; ROCm#1448/ROCm#1452/ROCm#1056/ROCm#1505-1507 touch other
kernels/layouts, and the aiter PA decode PRs (ROCm/aiter#8000/#7864/
#7206/#8910, draft ROCm/aiter#2919) are page-16/64/128 or HIP.
Production still calls HIP today; this is an enablement change, not a
serving win.

Signed-off-by: Arist12 <[email protected]>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

stale The PR hasn't been updated in 2 weeks

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants