Repository navigation
[Qwen3.8] Cherry-pick Triton skinny GEMV for the bf16 lm_head to qwen4_v0.5.21 - #101
Conversation
…project#46) * [AMD] Triton skinny GEMV for the bf16 lm_head on gfx942 The lm_head GEMM is a pure weight-streaming workload at decode (M = batch size, N = vocab shard). On MI308X hipBLASLt picks a generic Tensile tile that reaches ~2.2 TB/s; for the Qwen3.8-Flash-Next TP2 shard [124160, 2560] this costs ~250 us per step. Add a Triton skinny GEMM (python/sglang/kernels/ops/gemm/rocm_bf16_gemv.py) with three fixed, capture-safe configs: - M == 1: row-reduction GEMV on the vector ALUs - 2 <= M <= 16: 16-row MFMA tile, kpack=2, waves_per_eu=2 - 17 <= M <= 32: 32-row MFMA tile with a narrower N tile M > 32 and non-bf16 / unaligned-K inputs keep using torch.matmul. LogitsProcessor routes the plain bf16 lm_head matmul through it on gfx942; SGLANG_ENABLE_ROCM_LM_HEAD_GEMV=0 opts out. MI308X, K=2560, us (triton / hipBLASLt): N=124160: M=1 199/269, M=8 230/286, M=32 278/320 N=31040: M=1 37/52, M=8 49/53, M=32 60/65 End-to-end TP2 (pyhip config, 12k in / 5 out, conc 1): lm_head kernel 250.7 -> 179.3 us, TPOT 8.49 -> 8.38 ms, GSM8K (chat, 200, greedy) 0.975 -> 0.980. * [AMD] Tune the gfx942 lm_head GEMV and route only tuned shapes Replace the hard-coded launch configs with a per-(N, K) table in rocm_bf16_gemv.py (_GFX942_CONFIGS, M upper-bound buckets) and add cache_modifier on the weight load as a tunable. Only shapes in the table use the Triton kernels; everything else keeps hipBLASLt. The previous generic configs were slower than hipBLASLt on untuned shapes for some M (e.g. N <= 24576 at K=2560, or K=5120), and no single N threshold separated wins from losses across K. Tuned on MI308X for the Qwen3.8-Flash-Next lm_head shards (N in {248320, 124160, 62080, 31040}, K=2560) with benchmark/kernels/rocm_bf16_gemv/tune_rocm_bf16_gemv.py. Tuned vs previous configs: 1.02-1.14x; vs hipBLASLt: 1.11-1.49x. ".cg" and narrower 1-warp MFMA tiles (BLOCK_N=64) account for most of the gain. Split-K was evaluated and dropped: no shape improved beyond noise. TP2 end to end: lm_head 249 -> 165 us (previous configs: 173.5 us). * [AMD] Time the lm_head GEMV tuner with triton.testing.do_bench and re-tune Replace the hand-rolled CUDA-event loop in tune_rocm_bf16_gemv.py with triton.testing.do_bench(warmup=25, rep=100), the setting aiter's Triton op_benchmarks use (e.g. bench_gemm_a8w8_per_token_scale.py). Candidates, hipBLASLt and the shipped config are all timed the same way, with L2 flushed between reps. Re-tuned all four Qwen3.8-Flash-Next lm_head shards on MI308X. The GPUs were shared with other jobs, so every bucket where the tuner proposed a different config was re-checked with an interleaved A/B (20 rounds of do_bench, min and median); identical configs varied by up to ~4.6%, so a config is replaced only when it wins by >5% on both: - N=31040, M<=2..32: BLOCK_K 128 -> 256 (BLOCK_K 128 kept for M<=24) and ".cg"; 1.11-1.49x vs the previous entries. The previous M<=32 entry was no faster than hipBLASLt. - N=124160, M<=2: 1-warp BLOCK_N=64 tile, 1.09x. - N=62080, M<=4: ".cg" on the weight load, 1.12x. Every shipped entry beats hipBLASLt by 1.21-1.83x (do_bench min). --------- Co-authored-by: yicyang <[email protected]> (cherry picked from commit c996fcb)
31ee472 to
ba406b4
Compare
|
This PR backports the Triton BF16
MI308X CI: PR #94 baseline → PR #101
Changes are
Additional CI summary metrics:
For the targeted Qwen3.8 cases, Base records TTFT -1.0%, TPOT -0.4%, and output throughput +0.6%; MTP records TTFT +0.4%, TPOT +0.1%, and output throughput -0.2%. GSM8K increases by 0.50 percentage points in both cases, to 98.50% and 99.00%, respectively. These serving measurements do not measure Qwen3.5 model test case output throughput changes range from -2.0% to +2.7% within run-to-run variance. |
Cherry-pick of #46 (
c996fcb1ef) fromqwen38-flash-next-amd-current-fix-install._gemv_m1_kernel). The decode step drops from 10.67 to 10.57 ms (-1%).