Skip to content

[AMD] Qwen4-Exp SP: tuned prefill FP8 GEMMs, zero-copy AG consumer and faster hc_combine - #108

Merged
yicyang merged 7 commits into
apinge:qwen4_v0.5.21from
yicyang:qwen4-sp-tp2-gemm-tune-zero-copy
Nov 23, 2026
Merged

yicyang merged 7 commits into
apinge:qwen4_v0.5.21from
yicyang:qwen4-sp-tp2-gemm-tune-zero-copy

Conversation

@yicyang

@yicyang yicyang commented Nov 17, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

TP2 prefill and MTP decode on top of the SP + SDMA overlap (#89), measured on the current qwen4_v0.5.21 (with #111). The GEMM tuning lives in apinge/aiter#12 (qwen38-flash-next-dev), which this PR depends on.

  1. Two-row hc_combine (gfx942). The one-row kernel was memory-latency bound. The two-row kernel issues all loads before the gate reduction and shares the inject weight between two rows: 1.5-1.7x per call for rows of at most 4 x 2560, bit-identical. Wider rows keep the one-row kernel.
  2. AG consumer zero copy (gfx942). Each landed block's PTPC FP8 GEMM writes straight into its rows via aiter.gemm_a8w8_bpreshuffle(..., out=out[r0:r1]), saving one full-output copy per layer, bit-identical. It falls back to the copy for any other projection or an aiter without out=.
  3. lm_head skinny GEMM up to M = 64 (rocm_bf16_gemv). MTP verify runs the lm_head on bs x 4 rows, so c12 (48 rows) fell back to hipBLASLt. New 48/64 buckets for all four Qwen3.8 shards; TP2 393 / 410 us vs hipBLASLt 534 / 549 us.

apinge/aiter#12 adds:

  • tuned FlyDSL rows for the SP prefill shapes, plus a bit-identical gfx942 C-shuffle epilogue and out=;
  • decode rows for MTP verify: FlyDSL FP8, and opus BF16 at 48/64 rows;
  • removal of two stale cktile rows that ran 5x slower on the prebuilt module.

How to enable

Nothing to set: evaluation/launch_qwen38_flash_next_fp8_mi308x_pure_tp_4_or_8_or_2.sh defaults turn everything on (SP + SDMA, MTP=1). Install aiter with apinge/aiter#12; it is Python and CSV only, so no rebuild is needed. Leave AITER_CONFIG_GEMM_A8W8_BPRESHUFFLE unset.

Non-gfx942 devices take the original paths.

E2E

MI308X TP2, launch script as is, 12000 in / 350 out, base = qwen4_v0.5.21 @ b2ff410 (#111) with aiter qwen38-flash-next-dev @ 8d9080a8d. Base and PR are interleaved, 2 rounds each per mode; every round passed the GPU-isolation guard.

MTP off (MTP=0):

c8 c12
QPS base / PR 1.004 / 1.047 1.127 / 1.183
QPS +4.2 % +4.9 %
TTFT / TPOT -6.2 % / -2.7 % -5.2 % / -4.4 %

MTP on (MTP=1, EAGLE 3/1/4):

c1 c8 c12
QPS base / PR 0.564 / 0.613 1.189 / 1.256 1.262 / 1.334
QPS +8.7 % +5.7 % +5.7 %
TTFT / TPOT -6.0 % / -8.5 % -14.5 % / -0.3 % -7.8 % / -4.8 %
  • Every PR round beats every base round at c8 and c12. c1 has 4 requests per round and is noisier.
  • Accept length is unchanged: 3.49-3.54 for base, 3.33-3.71 for the PR.
  • The decode GEMM rows and the lm_head buckets alone, measured on the previous base: MTP c1 TPOT -8.8 %, c12 QPS +1.4 %. Most of the c1 gain comes from replacing the stale cktile rows at bs = 1.

Accuracy

  • gsm8k, TP2: MTP off 0.974 (base) / 0.979 (PR); MTP on 0.977 / 0.979.
  • hc_combine and zero copy are bit-identical to the paths they replace. The tuned FlyDSL GEMMs differ from CK by 1 ulp on about 5e-6 of bf16 outputs.
  • test_hc_combine.py: 22 passed; test_rocm_bf16_gemv.py: 95 passed.

Notes

  • 48K input needs no retune: prefill chunks are 16384 tokens, so the SP GEMMs see the same M (8192 / 4096) as the tuned rows, and the last chunk pads onto them.
  • MTP draft prefill also uses the two-row hc_combine. Its linear layers are BF16, so the FP8 rows and the zero copy do not apply there.
  • The new base was brought in with a merge commit (no force push). The merged tree is identical to the rebased tree that was measured.

Trace(Before)

AG + in_proj

image

out_proj

image

hc_combine

image

Trace(After)

AG + in_proj

image

out_proj

image

hc_combine

image

…e gate reduction

The one-row kernel is memory-latency bound on MI308X: half the issue slots
idle, two serial memory round trips per row. The two-row variant issues every
load before the gate reduction and shares each inject-weight vector between
two rows: 1.5-1.7x per call for 4 x 2560 rows, bit-identical.

- HcCombineKernel gains a kRows2 flag that launches hc_combine_rows2_kernel
  with the same tensor checks.
- Built and used on ROCm only, for rows of at most 4 x 2560 elements (wider
  rows spill registers: 0.89x at 4 x 4096); CUDA builds are unchanged.
- test_hc_combine.py: rows2 vs one-row bit-identity, and AMD CI registration.
@yicyang
yicyang force-pushed the qwen4-sp-tp2-gemm-tune-zero-copy branch from b07141c to 5f6fc8f Compare November 18, 2026 04:23
…eshuffle(out=)

Each landed all-gather block's PTPC FP8 GEMM writes its rows of the gathered
output in place, saving one full-output copy per layer. It applies only where
the projection's forward is exactly aiter's PTPC GEMM (compressed-tensors
per-channel FP8, no bias, no output gather, no layernorm-SP matmul) and aiter's
gemm_a8w8_bpreshuffle accepts out=; otherwise the per-block copy stays.
Bit-identical to the copy path.

With aiter's TP2 prefill GEMM rows and C-shuffle epilogue (qwen38-flash-next-dev),
TP2 c8 / c12 QPS at 12000 in / 350 out goes up 4.6 % / 4.3 %.
@yicyang
yicyang force-pushed the qwen4-sp-tp2-gemm-tune-zero-copy branch from 5f6fc8f to 5601928 Compare November 18, 2026 08:23
Comment thread python/sglang/srt/models/qwen4_exp.py Resolved
Comment thread python/sglang/srt/models/qwen4_exp.py Resolved
Comment thread python/sglang/srt/models/qwen4_exp.py Resolved
Comment thread python/sglang/srt/models/qwen4_exp.py Resolved
Review follow-up: reuse sglang.srt.utils.is_hip, as elementwise.py next to it
does, instead of a module-level torch.version.hip check.
…on gfx942

Both are measured on MI308X only, so every other device keeps the original
path: no two-row wrapper is built and hc_combine runs the one-row kernel, and
the AG consumer keeps the per-block GEMM + copy. Uses the existing
is_gfx942_supported(). The two-row test runs on the gfx942 AMD CI runner.
MTP verify runs the lm_head on bs x 4 rows, so c12 (48 rows) fell back to
hipBLASLt. Tuned 48/64 buckets for all four Qwen3.8 shards on MI308X:
TP2 393/410 us vs hipBLASLt 534/549 us (TP1 734/765 vs 1007/1033,
TP4 216/225 vs 298/305, TP8 126/127 vs 128/148).
@yicyang

yicyang commented Nov 23, 2026

Copy link
Copy Markdown
Collaborator Author

Changes are (after / before - 1) × 100%, calculated from unrounded artifact values and rounded to one decimal place. Negative TTFT/TPOT changes mean lower latency; positive throughput/QPS changes mean higher throughput.

Case GSM8K (before → after) TTFT ms (before → after; Δ %) TPOT ms (before → after; Δ %)
Qwen3.8-Flash-TP2-Base 98.50% → 98.00% 552.433 → 518.205 (-6.2%) 6.752 → 6.582 (-2.5%)
Qwen3.8-Flash-TP2-MTP 98.00% → 97.00% 582.103 → 546.562 (-6.1%) 3.530 → 3.109 (-11.9%)
Qwen3.5-35B-TP4-Base 98.00% → 98.50% 163.105 → 163.898 (+0.5%) 4.159 → 4.130 (-0.7%)
Qwen3.5-35B-TP1-DFlash 97.50% → 98.00% 298.045 → 298.035 (0.0%) 2.885 → 2.846 (-1.4%)
Qwen3.5-397B-TP8-Base 99.00% → 98.50% 329.173 → 330.842 (+0.5%) 6.067 → 6.105 (+0.6%)
Qwen3.5-397B-TP8-DFlash 99.00% → 98.50% 360.135 → 361.082 (+0.3%) 3.002 → 3.011 (+0.3%)

Additional CI summary metrics:

Case Output tokens/s (before → after; Δ %) QPS (before → after; Δ %) Accept length (before → after; Δ %)
Qwen3.8-Flash-TP2-Base 120.281 → 124.291 (+3.3%) 0.344 → 0.355 (+3.3%) —
Qwen3.8-Flash-TP2-MTP 192.857 → 214.405 (+11.2%) 0.551 → 0.613 (+11.2%) 3.481 → 3.539 (+1.7%)
Qwen3.5-35B-TP4-Base 223.289 → 224.643 (+0.6%) 0.447 → 0.449 (+0.6%) —
Qwen3.5-35B-TP1-DFlash 287.589 → 290.863 (+1.1%) 0.575 → 0.582 (+1.1%) 5.929 → 5.950 (+0.4%)
Qwen3.5-397B-TP8-Base 148.915 → 148.023 (-0.6%) 0.298 → 0.296 (-0.6%) —
Qwen3.5-397B-TP8-DFlash 268.936 → 268.152 (-0.3%) 0.538 → 0.536 (-0.3%) 7.952 → 7.893 (-0.7%)
  • The targeted Qwen3.8 MTP case records TPOT -11.9%, TTFT -6.1% and output throughput +11.2%, with accept length +1.7%; Base records TTFT -6.2%, TPOT -2.5% and output throughput +3.3%. GSM8K changes from 98.50% to 98.00% for Base and from 98.00% to 97.00% for MTP; both stay above the CI minimum (95.06% / 95.54%). The principal measured improvement is MTP decode latency (TPOT).

  • The four Qwen3.5 cases record output throughput changes from -0.6% to +1.1% and GSM8K changes within run-to-run variation (±0.5 points).

@yicyang
yicyang requested a review from sammysun0711 November 23, 2026 05:40
@yicyang
yicyang merged commit 33deaa6 into apinge:qwen4_v0.5.21 Nov 23, 2026
13 of 15 checks passed
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.

3 participants