Skip to content

[GDN] gfx950 / 16-48 head support: HIP decode fixes, sync-free prefill metadata, FlyDSL decode configs - #1

Open
yicyang wants to merge 8 commits into
base/v0.1.19from
gdn-gfx950-qwen38
Open

yicyang wants to merge 8 commits into
base/v0.1.19from
gdn-gfx950-qwen38

Conversation

@yicyang

@yicyang yicyang commented Oct 20, 2026 •

Copy link
Copy Markdown
Owner

Summary

GDN (gated delta rule) work for Qwen3.8-27B (16 key / 48 value heads) on MI355X (gfx950), on top of aiter v0.1.19 (base branch base/v0.1.19 = tag v0.1.19).

Commit Change
1dde3c4, fdccab1 Cherry-picks from Qwen3.5_dev: HIP inline-asm GDN decode (ROCm#2880), Fix adapt diff head shape (ROCm#3142). Original authors kept.
2ab42ce Port of ROCm#4540 (FlyDSL GDR reduction fix) onto v0.1.19
8e1a932 HIP decode on gfx950 / 16-48 heads (see below)
9a3dd27 chunk_gated_delta_rule_opt_vk(seq_lens_cpu=...): sync-free prefill metadata
13a45f7 gdr_decode_tuned.csv: 16/48 rows for gfx950 (b=1..32)
7b1dda2 flydsl_gdr_mtp: GDR decode with vLLM's MTP-verify contract (mtp_chain kernel mode: rollback from ssm_state_indices[n, num_accepted-1], state written per token to ssm_state_indices[n, t], slots < min_valid_index skipped); sq=4 rows for 16/48 in gdr_decode_tuned.csv; nearest tuned batch fallback
2a905e5 flydsl_gdr_decode: optional strided q/k/v (no .contiguous() copies) and min_valid_index (skip padding rows); defaults unchanged

HIP decode fixes (8e1a932)

  • JIT build targets the current GPU only. It hardcoded --offload-arch=gfx942, and torch's PYTORCH_ROCM_ARCH list (which includes gfx1100) broke the inline asm.
  • Added a <16,48> instantiation. Previously an unsupported head pair launched no kernel and returned torch.empty_like garbage; it now raises.
  • A_log is converted to fp32, since the kernel reads float* but the checkpoints store bf16.
  • Measured: correct, but 9-30% slower than vLLM's Triton kernel for 16/48, so it is not used by vLLM.

Sync-free prefill metadata (9a3dd27)

prepare_chunk_indices (.tolist()), prepare_num_chunks (int()) and prepare_chunk_offsets (new_tensor([0])) each forced a device->host sync on the first layer of every step. In vLLM with async scheduling this cost +3.9% TTFT for a 4K prefill arriving while 15 requests decode.

The new optional seq_lens_cpu (same name and semantics as ROCm#4694 on Qwen3.5_dev) builds them on the host with pinned non_blocking copies.

  • Verified with torch sync debug mode: 0 syncs (was 2-3), output/state bit-identical.
  • After the fix, end to end the regression is gone (-0.3% / -0.5%).
  • Explicit device="cpu" makes it safe under torch.set_default_device("cuda").

FlyDSL decode tuning (13a45f7)

Sweep NUM_BLOCKS_PER_V_DIM x NUM_WARPS x WARP_THREADS_K (48 configs). Each config is fp32-reference checked, then re-measured with fresh inputs; b=5,6,10,12,14 kept the default because the tuned config lost there.

  • Default -> tuned: b=1 4.64->3.60 us (1.29x), b=8 9.22->8.10, b=32 32.92->31.37.
  • With these rows FlyDSL is the fastest T=1 decode backend for b<=8 among vLLM Triton (tuned), FlyDSL and HIP.

Strided q/k/v + min_valid_index (2a905e5)

In vLLM's packed decode layout, the three .contiguous() copies cost 7-9 us per call and made FlyDSL 22-51% slower than vLLM's packed Triton kernel for batch >= 2. With strided views and padding rows skipped, at vLLM capture sizes vs packed decode: padded size 1-2 1.27-1.34x, 4-8 1.12-1.20x, 16 1.00-1.11x, 24-32 0.96-1.01x. Output/state checked against an fp32 reference; slot 0 and other slots untouched.

flydsl_gdr_mtp (7b1dda2)

Kernel-only GPU time (torch profiler, median of 3 runs on idle GPUs), T=4, 16/48 heads, MI355X, FlyDSL tuned vs vLLM's tuned Triton fused_sigmoid_gating_delta_rule_update_kernel: N=1 9.7 vs 9.6 us, N=4 16.1 vs 16.0, N=8 23.4 vs 26.0, N=16 40.1 vs 44.4, N=24 60.2 vs 66.8, N=32 87.3 vs 95.1. Every row checked against an fp32 token-by-token reference (outputs, all written slots, untouched slots incl. 0). Tuning: 48-config sweep per batch size (4 configs fail an in-kernel assert).

Not changed / notes

  • Triton prefill configs are not changed. For 48/16, GATED_DELTA_RULE_TRITON_AUTOTUNE=1 picks the same config regardless of the first shape seen, and gives 1.17-1.38x vs vLLM FLA.
  • FlyDSL/HIP K5 were within ~5% of the Triton K5 once the other stages were autotuned.
  • Validated only on MI355X; no model-accuracy eval (gsm8k) was run.

AI assistance

This work was AI-assisted and needs human review of every changed line before any upstream use.

IzacharyI and others added 6 commits October 19, 2026 13:58
* [feat]hip inline asm for GDN linear attn in decode phase

* [opt]Hoist GDN state transpose to backend-level multi-layer batched kernel

(cherry picked from commit ce7a2e0)
* [feat]hip inline asm for GDN linear attn in decode phase

* [opt]Hoist GDN state transpose to backend-level multi-layer batched kernel

* [fix]Acc issue in qwen 27b, fallback linear attn into flydsl in different head shapes which have not been included in hip inline asm dispatch. And flydsl cherrypick from PR ROCm#2682

(cherry picked from commit 15cdb0b)
…4540 onto v0.1.19)

Takes the Qwen3.5_dev versions of the files touched by fbed08d. Against
v0.1.19 the only kernel delta is wrapping vector reduction operands with
_to_raw() in the VK GDR decode kernel; gdr_decode_tuned.csv and
linear_attention_kernels.py were already identical. Adds the test file.

(cherry picked from commit fbed08d, conflicts resolved to Qwen3.5_dev state)
…3.8-27B)

Fixes found while benchmarking the Qwen3.5_dev GDN decode kernels on MI355X
(gfx950) with Qwen3.8-27B TP1 shapes (16 key heads / 48 value heads, d=128):

- Build for the current GPU only. The extension hardcoded
  --offload-arch=gfx942, and torch's cpp_extension additionally adds one
  --offload-arch per PYTORCH_ROCM_ARCH entry; with the container default
  (gfx90a;gfx942;gfx950;gfx1100;...) the inline asm fails to assemble for
  gfx1100. Set PYTORCH_ROCM_ARCH to the detected arch before load().
- Add a <16,48> instantiation to launch_gdn_decode_iasm_generic. Previously an
  unsupported (num_k_heads, num_v_heads) pair launched no kernel at all and
  returned torch.empty_like() garbage; the Python wrapper now raises
  ValueError for pairs that are not dispatched.
- Convert A_log to fp32 before launch: the kernel reads it as float*, but
  Qwen3.5/3.8 checkpoints store A_log in bf16.

Verified (T=1 decode, fp32 torch reference, 1..32 sequences): output max abs
err <= 2.4e-4, state max abs err <= 1.8e-7. Measured on MI355X under CUDA-graph
replay, the generic 16/48 path is 9-30% slower than vLLM's Triton
fused_sigmoid_gating kernel for these shapes, so it is not wired into vLLM.
Raw data: Qwen3.8-27B/gdn-opt/microbench/decode_t1.csv
…q_lens_cpu)

chunk_gated_delta_rule_opt_vk derived its chunk indices/offsets from the
device cu_seqlens: prepare_chunk_indices (.tolist()), prepare_num_chunks
(int()) and prepare_chunk_offsets (new_tensor([0]) H2D) each forced a
device->host sync on the first GDN layer of every step. In a serving engine
with async scheduling this stalls mixed prefill/decode steps: measured in
vLLM on MI355X (Qwen3.8-27B), a 4K prefill arriving while 15 requests decode
took +3.9% TTFT with this backend.

Add optional seq_lens_cpu (same name/semantics as ROCm#4694 on Qwen3.5_dev):
register_host_seq_lens() attaches the host lengths to cu_seqlens, and the
three helpers build their results on the host and copy them with pinned
non_blocking H2D. Without seq_lens_cpu behaviour is unchanged, except that
prepare_chunk_offsets uses new_zeros(1) instead of new_tensor([0]).

Verified on gfx950 (torch sync debug mode "error"): with seq_lens_cpu the
Triton-K5 and FlyDSL-K5 paths issue 0 syncs (before: 2 and 3); output and
final state are bit-identical to the original path.
…27B TP1)

gdr_decode_tuned.csv had no 16 key / 48 value head rows, so
flydsl_gdr_decode fell back to NUM_BLOCKS_PER_V_DIM=1, NUM_WARPS=4,
WARP_THREADS_K=8. Adds b=1..32 rows (bf16 q/k/v, fp32 state, sq=1).

Sweep: NUM_BLOCKS_PER_V_DIM {1,2,4,8} x NUM_WARPS {1,2,4} x
WARP_THREADS_K {4,8,16,32} (4 of 48 configs fail an in-kernel assert), each
config checked against an fp32 reference (output and state) before CUDA-graph
timing. Then re-measured with fresh inputs, 5 interleaved rounds: b=5,6,10,
12,14 lost to the default there, so those rows keep the default config.

MI355X, median us, default -> tuned: b=1 4.64->3.60 (1.29x), b=2 5.09->4.35,
b=4 6.73->6.46, b=8 9.22->8.10, b=16 17.62->16.62, b=32 32.92->31.37.
Two optional knobs on create_vk_gdr_decode_kernel / flydsl_gdr_decode, both
defaulting to the old behaviour:

- qkv_strides: q/k/v may be strided views with unit inner stride (e.g.
  column slices of a packed conv output). flydsl_gdr_decode now passes such
  views through instead of calling .contiguous(). In vLLM's packed decode
  layout the three copies cost 7-9 us per call and made FlyDSL 22-51% slower
  than vLLM's packed Triton kernel for batch >= 2.
- min_valid_index: rows whose state index is below it are skipped. vLLM pads
  CUDA-graph decode batches with state index 0 (reserved slot); with
  min_valid_index=1 those rows do no work and slot 0 is not written.

MI355X, Qwen3.8-27B (16/48 heads), padded to vLLM capture sizes, vs vLLM
packed decode: padded size 1-2: 1.27-1.34x, 4-8: 1.12-1.20x, 16: 1.00-1.11x,
24-32: 0.96-1.01x. Output/state checked against an fp32 reference; slot 0 and
all other slots untouched.
Adds an mtp_chain mode to create_vk_gdr_decode_kernel and a
flydsl_gdr_mtp entry point implementing what vLLM's
fused_sigmoid_gating_delta_rule_update does with num_accepted_tokens:

- ssm_state_indices is [N, T]; the initial state is read from
  ssm_state_indices[n, num_accepted_tokens[n] - 1] and the row is skipped
  if that slot is below min_valid_index (vLLM's null block 0);
- the state after each token t is written to ssm_state_indices[n, t]
  (slots below min_valid_index are skipped);
- q/k/v/a/b may be strided views, so vLLM's packed conv output can be
  passed without the rearrange copy.

Default (mtp_chain=False) behaviour of flydsl_gdr_decode is unchanged; the
kernel gains a num_accepted argument that decode passes as a placeholder.
gdr_decode_tuned.csv gets sq=4 rows for 16/48 heads on gfx950 at
b=1,2,4,6,8,12,16,20,24,28,32, and flydsl_gdr_mtp falls back to the
nearest tuned batch size.

MI355X, Qwen3.8-27B (16/48), T=4, one CUDA-graph padding row, vs vLLM's
spec path (rearrange copy + fused_sigmoid_gating_delta_rule_update, default
/ tuned launch): n=1 25.71/23.72 -> 8.85us (2.9x), n=4 37.21 -> 15.30,
n=8 44.53 -> 22.24, n=16 63.50 -> 39.57, n=31 112.91 -> 85.36 (1.32x).
Every row checked against an fp32 token-by-token reference (outputs of real
rows, every written slot, all other slots incl. 0 untouched).
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.

2 participants