Skip to content

[FlyDSL][GDN] gfx942 fused decode, MTP verify and prefill front end for Qwen3.8 - #11

Merged
apinge merged 6 commits into
apinge:qwen38-flash-next-devfrom
yicyang:qwen38-gdn-flydsl-pr
Nov 20, 2026
Merged

apinge merged 6 commits into
apinge:qwen38-flash-next-devfrom
yicyang:qwen38-gdn-flydsl-pr

Conversation

@yicyang

@yicyang yicyang commented Nov 17, 2026 •

Copy link
Copy Markdown

gfx942 kernels for the Qwen3.8-Flash-Next GDN (linear attention) layers, used by the companion sglang PR (apinge/sglang, qwen4_v0.5.21).

Used through the sglang flags --linear-attn-decode-backend aiter, --linear-attn-verify-backend aiter and --linear-attn-prefill-backend aiter. The chunk_o config is added on gfx942 only; other GPUs keep the original autotune list.

End to end, MI308X: QPS +8.0% / +7.6% at TP2 and +6.6% / +6.9% at TP4 (c8 / c12), MTP off; +5.3% / +5.2% at TP2 with MTP on. gsm8k unchanged.

Decode

what before after gain (TP2 / TP4, batch 8)
unpack + causal conv update + gating + l2norm + recurrence (6 kernels) sglang torch copies + Triton causal_conv1d_update + Triton fused_recurrent_gated_delta_rule_packed_decode new FlyDSL fused_qkvzba_conv1d_gated_delta_rule_decode_flydsl, 1 kernel layer: 51.2 to 19.4 us (-62%) / 38.7 to 14.9 us (-61%)
MTP chain target verify, 4 draft tokens: unpack + conv + intermediate conv windows + gating + l2norm + 4-step recurrence + intermediate states (6 kernels) sglang torch copies + Triton causal_conv1d_update + Triton fused_sigmoid_gating_delta_rule_update new FlyDSL fused_qkvzba_conv1d_gated_delta_rule_verify_flydsl, 1 kernel layer: 59.6 to 28.6 us (-52%, serving profile, TP2)
recurrence only (drop-in) Triton fused_recurrent_gated_delta_rule_packed_decode new FlyDSL fused_recurrent_gated_delta_rule_packed_decode_flydsl, same arguments 26.2 to 14.5 us (-45%) / 18.3 to 10.0 us (-45%)

decode fusion

verify fusion

Prefill

what before after gain (TP2 / TP4, 12k tokens)
cat + causal conv1d + q/k/v split + 2x l2norm (5 kernels) torch cat + Triton causal_conv1d_fwd + Triton qkv split + Triton l2norm_fwd x2 new FlyDSL flydsl_gdn_prefill_front, 1 kernel 980 to 325 us (-67%) / 497 to 172 us (-65%)
chunk output o Triton chunk_fwd_kernel_o_opt_vk, autotune capped at BK/BV=64 on gfx942 same kernel, gfx942 config BK=64 / BV=128 (no q.k^T recompute per V tile) 642 to 421 us (-34%) / 323 to 207 us (-36%)

prefill fusion

Numerics follow the Triton kernels they replace:

  • the conv cache is bit-exact;
  • the SSM state and the verify intermediate states match within 5e-7;
  • the verify intermediate conv windows are bit-exact (written per step, so MambaPool's overlapping window layout and a plain one both work);
  • chunk_fwd_o is bit-identical;
  • q/k/v are within 1 bf16 ulp.

Test: python op_tests/test_flydsl_gdn_decode_prefill.py, all pass.

- fused_qkvzba_conv1d_gated_delta_rule_decode_flydsl: one launch per GDN
  decode layer, starting from the in_proj outputs: qkvz/ba unpack + width-4
  causal conv update + gating + q/k l2norm + gated delta recurrence. Writes
  o [B, 1, HV, V] plus a contiguous z, or applies the gated RMSNorm itself.
  State loads are issued first and use nt load/store; K reductions use DPP;
  the q/k conv state shared by HV/HK workgroups is written back by the last
  reader (self-resetting arrival counter, CUDA-graph safe).
- fused_recurrent_gated_delta_rule_packed_decode_flydsl: the recurrence
  alone, drop-in for the Triton fused_recurrent_gated_delta_rule_packed_decode.
- flydsl_gdn_prefill_front: varlen causal conv + SiLU + q/k/v split + q/k
  l2norm read straight from the in_proj output (replaces cat + conv + split
  + 2x l2norm); bf16 product rounding matches the Triton kernels.
- op_tests/test_flydsl_gdn_decode_prefill.py: torch reference + perf table.
…s (BK=64, BV=128)

The generic list caps BK/BV at 64 on 64 KB-LDS parts, which splits V and
recomputes q.k^T per V tile. On MI308X the Qwen3.8 GDN prefill shapes run
30-35% faster with BV=128, BK=64, 4 warps, 1 stage (bit-identical output).
The decode kernels read bf16 activations, fp32 A_log and bf16/fp32 dt_bias;
assert this (and HV % H == 0) instead of silently misreading other dtypes.
Create the decode arrival counter outside CUDA graph capture only, sized for
64K (token, k-head) pairs.
- chunk_fwd_kernel_o_opt_vk: keep the generic autotune list and only add the
  full-V (BK=64, BV=128, 1 stage) config on 64 KB-LDS GPUs; autotune picks it on
  MI308X (same 421 / 207 us at TP2 / TP4).
- decode kernel: drop the unused in-kernel gated RMSNorm and the fixed knobs
  (num_warps, state dtype, waves_per_eu). The generated code of both entry points
  is unchanged apart from kernarg offsets.
- op_test: cover the packed (Triton drop-in) entry point instead of the removed
  norm mode.
Uses arch_info.get_arch(); other GPUs keep the original config list.
fused_qkvzba_conv1d_gated_delta_rule_verify_flydsl replaces sglang's verify chain
(qkvz/ba unpack + causal_conv1d_update + fused_sigmoid_gating_delta_rule_update)
with one kernel: T draft tokens per request, per-step intermediate SSM states and
conv windows, conv state shifted in place, SSM state read only.
@yicyang yicyang changed the title [FlyDSL][GDN] gfx942 fused T=1 decode and prefill front end for Qwen3.8 [FlyDSL][GDN] gfx942 fused decode, MTP verify and prefill front end for Qwen3.8 Nov 20, 2026
@apinge
apinge merged commit 8d9080a into apinge:qwen38-flash-next-dev Nov 20, 2026
1 check failed
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