Skip to content

[GEMM] Add MI308X FP8 PTPC BPreshuffled GEMMs tuned config for Qwen - #14

Merged
sammysun0711 merged 6 commits into
apinge:qwen38-flash-next-devfrom
sammysun0711:tune/mi308x-qwen-ptpc-fp8-gemm
Dec 1, 2026
Merged

sammysun0711 merged 6 commits into
apinge:qwen38-flash-next-devfrom
sammysun0711:tune/mi308x-qwen-ptpc-fp8-gemm

Conversation

@sammysun0711

@sammysun0711 sammysun0711 commented Nov 26, 2026 •

Copy link
Copy Markdown
Collaborator

Motivation

This PR tunes packed FP8 per-token/per-channel (PTPC) GEMMs for Qwen dense attention on AMD Instinct MI308X (gfx942, 80 CUs). Across four tuned CSVs it adds 53 dispatch keys and replaces 29 existing GLM5 selections shared with Qwen3.5-35B TP2. Of the 82 changed shapes, 80 select FlyDSL and two select CK. Tuning CSVs · Packed FP8 tuner

All 82 shapes had lower median GEMM latency than the PR base with both rotating and reused weights. The table gives the median reduction across shapes, with the smallest and largest per-shape reductions in parentheses.

Target Changed keys (added / replaced) Rotating weights Reused weight
Qwen3.5-35B-A3B TP2 45 (16 / 29) 12.45% (2.79–41.10%) 18.94% (3.63–37.58%)
Qwen3.5-397B-A17B TP8 29 (29 / 0) 27.92% (1.16–46.27%) 30.88% (5.24–53.70%)
Qwen3.8-Flash-Next TP2 8 (8 / 0) 20.03% (3.77–44.31%) 21.60% (4.80–44.24%)
All targets 82 (53 / 29) 16.24% (1.16–46.27%) 20.37% (3.63–53.70%)

Eighty shapes cleared 3% in both modes. The two smaller rotating-weight gains were 2.79% at (M,N,K) = (16,4608,2048) for 35B TP2 and 1.16% at (16,2560,4096) for 397B TP8.

Qwen3.5 FP8 PTPC shapes

The tuner inputs cover all 16 powers of two from M=1 through 32768 at each of the five rank-local projection widths below. This gives 48 inputs for 35B TP2 and 32 for 397B TP8.

Model Dense projection Rank-local (N, K) Packed FP8 GEMMs per forward, per rank
35B TP2 GDN fused QKVZ input (6144, 2048) 30
35B TP2 Full-attention fused QKV input (4608, 2048) 10
35B TP2 GDN and full-attention outputs (2048, 2048) 40
397B TP8 GDN QKVZ and full-attention QKV inputs (2560, 4096) 60
397B TP8 GDN and full-attention outputs (4096, 1024) 60
Checkpoint layout and measured workload coverage
Local checkpoint Indexed FP8 weights Weight scales on disk Dense attention examples before TP sharding
Qwen3.5-35B-A3B-PTPC-FP8 30,970 BF16, [N,1] GDN in_proj_qkv weight [8192,2048], scale [8192,1]
Qwen3.5-397B-A17B-PTPC-FP8 92,535 FP32, [N,1] GDN in_proj_qkv weight [12288,4096], scale [12288,1]

With SGLANG_USE_AITER=1, SGLang converts E4M3 weights to FNUZ on gfx942, allocates FP32 channel scales and preshuffles weights in 16×16 tiles. The Qwen3.5 traces call aiter.gemm_a8w8_bpreshuffle with E4M3 FNUZ operands and FP32 scales shaped [M,1] for activations and [N,1] for weights. SGLang channel-scale loader · Packed PTPC linear

This PR target: dense attention projections account for 130 stored FP8 matrices on 35B and 195 on 397B before fusion and tensor-parallel sharding.
Non goal:

  • Routed experts use fused MoE kernels -> optimized fused moe
  • The router, GDN A/B projections and vocabulary head use BF16 in these workloads. Related BF16 tuning

Per-shape PTPC results

The paired measurements compare the public aiter.gemm_a8w8_bpreshuffle operator against base 1cf6209 on GPU 1, using ROCm 7.14, PyTorch 2.12 and FlyDSL 0.3.2. Both modes call shuffle_weight before timing. Rotating mode cycles through distinct packed-weight buffers at the same shape. Reused mode repeatedly reads one buffer. The measurements use preshuffled E4M3 FNUZ inputs, FP32 scales and BF16 output. Base · PR head

The tables report median GPU time per GEMM in microseconds for rotating weights. Each percentage is the median of the paired latency reductions, 100 × (base − tuned) / base. The audit alternated run order and collected 40 or 70 pairs per shape per mode. Rotating runs used 32 buffers through M=256, eight through M=2048, four through M=8192 and two above that.

Qwen3.5-35B-A3B TP2 · 45 changed shapes
M N K Base kernel Tuned kernel Base (µs) Tuned (µs) Rotating gain Reused gain
1 2048 2048 CK Tile 2 FlyDSL 1 4.393 3.629 17.45% 23.28%
1 4608 2048 CK fallback FlyDSL 505 5.542 4.778 14.11% 20.85%
1 6144 2048 CK 108 FlyDSL 1695 6.810 6.332 7.14% 19.73%
2 2048 2048 CK Tile 2 FlyDSL 505 4.424 3.679 16.81% 23.30%
2 4608 2048 CK fallback FlyDSL 1 5.569 4.812 13.73% 20.50%
2 6144 2048 CK 15 FlyDSL 1695 6.796 6.326 7.31% 18.94%
4 2048 2048 CK Tile 2 FlyDSL 505 4.434 3.687 17.04% 22.29%
4 4608 2048 CK fallback FlyDSL 505 5.600 4.828 13.66% 19.57%
4 6144 2048 CK 15 FlyDSL 1191 6.866 6.387 6.99% 19.88%
8 2048 2048 CK Tile 144 FlyDSL 505 4.442 3.702 16.64% 24.04%
8 4608 2048 CK fallback FlyDSL 505 5.571 4.802 13.89% 18.97%
8 6144 2048 CK 10 FlyDSL 1191 6.991 6.452 7.83% 20.14%
16 2048 2048 CK 11 FlyDSL 1 4.108 3.710 9.91% 20.16%
16 4608 2048 CK fallback FlyDSL 505 5.043 4.910 2.79% 7.35%
16 6144 2048 CK 10 FlyDSL 1191 6.836 6.596 3.65% 11.06%
32 2048 2048 CK 11 FlyDSL 505 4.466 4.060 9.13% 8.88%
32 4608 2048 CK fallback FlyDSL 10 6.968 5.692 18.33% 13.42%
32 6144 2048 CK 11 FlyDSL 10 9.178 8.226 10.35% 3.63%
64 2048 2048 CK Tile 37 FlyDSL 10 6.868 4.933 28.26% 25.64%
64 4608 2048 CK fallback FlyDSL 10 10.684 8.012 24.83% 21.90%
64 6144 2048 CK 126 FlyDSL 528 10.587 9.998 5.65% 5.33%
128 2048 2048 CK 112 CK 119 7.574 7.150 5.59% 5.68%
128 4608 2048 CK fallback FlyDSL 528 17.791 10.468 41.10% 37.58%
256 2048 2048 CK 114 FlyDSL 528 11.476 9.216 19.68% 17.85%
256 4608 2048 CK fallback FlyDSL 24 18.219 16.686 8.45% 12.32%
512 2048 2048 CK 121 FlyDSL 24 17.380 15.409 11.49% 10.60%
512 4608 2048 CK fallback FlyDSL 531 29.649 26.829 9.71% 9.40%
512 6144 2048 CK 85 FlyDSL 24 38.749 34.246 11.55% 11.68%
1024 2048 2048 CK 70 FlyDSL 531 29.266 26.934 7.69% 8.12%
1024 4608 2048 CK fallback FlyDSL 531 54.249 47.998 11.47% 11.64%
1024 6144 2048 CK 0 FlyDSL 531 67.345 58.101 13.67% 13.73%
2048 4608 2048 CK fallback FlyDSL 531 102.472 89.685 12.45% 12.48%
2048 6144 2048 CK Tile 48 FlyDSL 27 148.979 111.364 25.34% 25.31%
4096 2048 2048 CK Tile 18 FlyDSL 531 89.065 80.435 9.36% 9.76%
4096 4608 2048 CK fallback FlyDSL 531 187.905 163.736 12.57% 12.63%
4096 6144 2048 CK 68 FlyDSL 27 241.966 217.296 10.06% 10.31%
8192 2048 2048 CK Tile 48 FlyDSL 531 194.021 145.585 24.81% 25.26%
8192 4608 2048 CK fallback FlyDSL 27 362.621 317.746 12.44% 12.20%
8192 6144 2048 CK Tile 48 FlyDSL 531 575.557 425.471 25.84% 25.83%
16384 2048 2048 CK Tile 48 FlyDSL 27 382.221 286.271 25.23% 25.22%
16384 4608 2048 CK fallback FlyDSL 531 718.952 632.242 11.85% 11.83%
16384 6144 2048 CK Tile 48 FlyDSL 27 1139.424 836.262 25.63% 25.75%
32768 2048 2048 CK Tile 48 FlyDSL 531 756.662 564.941 25.18% 25.24%
32768 4608 2048 CK fallback FlyDSL 531 1459.455 1278.674 12.10% 11.97%
32768 6144 2048 CK Tile 48 FlyDSL 27 2258.937 1708.895 24.26% 24.30%
Qwen3.5-397B-A17B TP8 · 29 changed shapes
M N K Base kernel Tuned kernel Base (µs) Tuned (µs) Rotating gain Reused gain
1 2560 4096 CK fallback FlyDSL 505 7.999 6.730 16.19% 24.25%
1 4096 1024 CK fallback FlyDSL 505 4.478 3.008 32.82% 31.55%
2 2560 4096 CK fallback FlyDSL 1 8.063 6.729 16.48% 23.98%
2 4096 1024 CK fallback FlyDSL 505 4.509 3.012 33.30% 33.66%
4 2560 4096 CK fallback FlyDSL 1 8.090 6.768 16.29% 23.76%
4 4096 1024 CK fallback FlyDSL 505 4.530 3.009 33.48% 33.18%
8 2560 4096 CK fallback FlyDSL 1 8.092 6.742 16.61% 23.94%
8 4096 1024 CK fallback FlyDSL 1 4.536 3.018 33.32% 35.27%
16 2560 4096 CK fallback FlyDSL 1 6.928 6.838 1.16% 12.94%
16 4096 1024 CK fallback FlyDSL 1 4.436 3.037 31.66% 32.97%
32 4096 1024 CK fallback FlyDSL 10 4.954 3.569 27.92% 20.46%
64 4096 1024 CK fallback FlyDSL 10 9.251 5.166 44.14% 53.70%
128 2560 4096 CK fallback CK 119 17.281 12.531 27.61% 30.88%
128 4096 1024 CK fallback FlyDSL 24 8.557 6.410 25.08% 27.43%
256 2560 4096 CK fallback FlyDSL 528 28.427 17.298 39.14% 41.24%
256 4096 1024 CK fallback FlyDSL 527 12.462 11.037 11.34% 12.87%
512 2560 4096 CK fallback FlyDSL 528 29.343 26.230 10.60% 10.96%
512 4096 1024 CK fallback FlyDSL 531 28.730 16.261 43.29% 43.40%
1024 4096 1024 CK fallback FlyDSL 527 50.811 27.675 45.56% 45.73%
2048 2560 4096 CK fallback FlyDSL 531 93.649 88.733 5.37% 5.24%
2048 4096 1024 CK fallback FlyDSL 531 83.573 44.970 46.27% 46.10%
4096 2560 4096 CK fallback FlyDSL 27 180.555 169.660 5.79% 6.11%
4096 4096 1024 CK fallback FlyDSL 531 149.995 81.990 45.16% 45.55%
8192 2560 4096 CK fallback FlyDSL 531 359.766 336.371 6.24% 6.63%
8192 4096 1024 CK fallback FlyDSL 531 291.006 157.881 45.70% 45.77%
16384 2560 4096 CK fallback FlyDSL 27 711.292 664.202 6.42% 6.50%
16384 4096 1024 CK fallback FlyDSL 27 574.092 310.551 45.83% 45.82%
32768 2560 4096 CK fallback FlyDSL 531 1452.734 1355.314 6.92% 6.78%
32768 4096 1024 CK fallback FlyDSL 27 1130.044 611.422 45.75% 45.74%
Qwen3.8-Flash-Next TP2 · 8 changed shapes
M N K Base kernel Tuned kernel Base (µs) Tuned (µs) Rotating gain Reused gain
32 2560 3072 CK fallback FlyDSL 1 5.693 5.435 4.46% 11.32%
64 2560 3072 CK fallback FlyDSL 10 7.631 6.468 15.53% 20.28%
128 2560 3072 CK fallback FlyDSL 10 12.611 9.908 21.28% 19.82%
128 6656 2560 CK fallback FlyDSL 528 29.060 19.874 31.58% 29.84%
128 8192 2560 CK fallback FlyDSL 24 34.266 20.468 40.41% 38.41%
256 2560 3072 CK fallback FlyDSL 528 22.794 12.691 44.31% 44.24%
256 6656 2560 CK fallback FlyDSL 528 35.567 28.928 18.78% 22.92%
256 8192 2560 CK fallback FlyDSL 531 35.929 34.508 3.77% 4.80%

Validation

  • The merged packed PTPC table grew from 2,968 to 3,021 unique dispatch keys. The selected backend and kernel ID match the timing record for every changed shape.
  • All 82 shapes passed full-output BF16 and FP16 checks against a float32 PyTorch reference rounded to the output dtype. The checks require finite outputs and at least 99% of elements within rtol=0.01, atol=0.01.

- Tune 41 Qwen3.5-35B TP2 and 17 Qwen3.5-397B TP8 shapes with FlyDSL.
- Tune six Qwen3.8-Flash-Next TP2 decode GEMMs at M=128 and M=256.
- Update 19 shared GLM5 rows in place to avoid duplicate dispatch keys.

Signed-off-by: Xiake Sun <[email protected]>
- Select faster CK kernels for 14 of 32 existing 397B block-scale shapes.
- Cut latency by 9.3–9.7% in a replay with one call per shape.
- Use operator-first filenames for the 35B and 397B packed PTPC tables.

Signed-off-by: Xiake Sun <[email protected]>
@apinge
apinge self-requested a review November 26, 2026 03:11
- Restore the upstream 397B block-scale selections.
- Keep the 64 packed PTPC rows used by the target Qwen workloads.

Signed-off-by: Xiake Sun <[email protected]>
- Restore four original CK rows whose replacement CSV latency increased.
- Keep the other 60 packed PTPC tuning changes.
- Preserve all dispatch keys and the remaining table contents.

Signed-off-by: Xiake Sun <[email protected]>
@sammysun0711 sammysun0711 changed the title [GEMM] Add MI308X packed FP8 GEMMs tuned config for Qwen [GEMM] Add MI308X FP8 PTPC BPreshuffled GEMMs tuned config for Qwen Nov 26, 2026
- Select gfx942 FlyDSL tiles using all 48 checkpoint projection weights.
- Validate BF16 and FP16 output across the inherited M=17–64 buckets.

Signed-off-by: Xiake Sun <[email protected]>
- Cover 80 shapes from M=1 to 32768 for 35B TP2 and 397B TP8.
- Add 20 MI308X dispatch entries and retune 15 existing selections.
- Refresh four shared GLM5 timings and remove 14 non-power-of-two
  prefill overrides.

Signed-off-by: Xiake Sun <[email protected]>
@sammysun0711
sammysun0711 merged commit 7e9c20c into apinge:qwen38-flash-next-dev Dec 1, 2026
1 check passed
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