Skip to content

[perf] Optimize w4a8 MoE for glm5.2 on H200 - #38220

Merged
BBuf merged 6 commits into
sgl-project:mainfrom
cognaiger9:perf/perf-w4a8-moe-glm52
Sep 19, 2026
Merged

BBuf merged 6 commits into
sgl-project:mainfrom
cognaiger9:perf/perf-w4a8-moe-glm52

Conversation

@cognaiger9

@cognaiger9 cognaiger9 commented Sep 6, 2026 •

Copy link
Copy Markdown
Contributor

Motivation

dispatch_w4a8_moe_mm_sm90 (python/sglang/kernels/aot/csrc/moe/cutlass_moe/w4a8/w4a8_grouped_mm_c3x.cu) picks a CUTLASS config for the W4A8 grouped GEMM by matching on (n, k). Every named branch was tuned for DeepSeek's 7168-hidden shapes on H20. GLM-5.2 (hidden=6144, moe_intermediate_size=2048, E=256, topk=8) matches none of them, so both of its production sharding layouts - TP-8 and EP-8 without DeepEP - fall through to the generic fallback tail and run untuned.

Modifications

Add four named branches to dispatch_w4a8_moe_mm_sm90 for GLM-5.2's actual GEMM shapes, one per GEMM per layout:

  • TP-8: all 256 experts local, intermediate size partitioned by tp_size=8 -> gemm1 (n=512, k=6144), gemm2 (n=6144, k=256).
  • EP-8, no DeepEP: 32 experts local at the full intermediate size -> gemm1 (n=4096, k=6144), gemm2 (n=6144, k=2048).

This tuning adds four unique CUTLASS configurations, increasing the W4A8 configuration count from 12 to 16. These add compilation work and binary size.

Accuracy Tests

Correctness is covered by python/sglang/kernels/aot/tests/test_cutlass_w4a8_moe_mm.py's extended parametrization

Speed Tests and Profiling

test/manual/layers/moe/bench_w4a8_sm90_dispatch.py times the complete
cutlass_w4a8_moe call (preprocess/reorder/quant → GEMM1 → silu+requant →
GEMM2 → post-reorder) - the full MoE-layer boundary across both of its production sharding layouts:

  • TP-8 (mode="tp").
  • EP-8, no DeepEP (mode="ep"): the script builds only the 32 local-expert weights and remaps global routing ids to local ids (or a drop sentinel for the other 224), reproducing what a real EP-8 rank sees.

Shapes with m<=2048 run captured under a CUDA graph, larger shapes run eager. Each shape reports median and min latency across 30 timed calls (5 warmup calls beforehand).

The results below is produced from running the script on 1x H200.

TP-8 (win at every M)

tokens base median (µs) patched median (µs) speedup
8 127.7 113.4 1.126x
16 194.5 172.3 1.129x
32 275.6 239.1 1.153x
64 380.1 309.2 1.230x
128 423.1 346.7 1.221x
256 433.3 353.7 1.225x
512 452.9 400.3 1.131x
1024 565.6 544.9 1.038x
2048 865.6 824.6 1.050x
4096 1418.4 1366.9 1.038x
8192 2403.5 2311.8 1.040x

EP-8 (no DeepEP) (win at M <= 256)

tokens base median (µs) patched median (µs) speedup
8 101.4 99.2 1.022x
16 134.9 132.5 1.019x
32 224.6 218.1 1.030x
64 274.1 256.2 1.070x
128 304.4 283.4 1.074x
256 306.5 288.7 1.062x

Checklist


CI States

Latest PR Test (Base): ⏳ Run #35441337493
Latest PR Test (Extra): ❌ Run #35441337543
Latest PR Test (AMD ROCm 10): ⏳ Run #35441337421

@cognaiger9
cognaiger9 force-pushed the perf/perf-w4a8-moe-glm52 branch 2 times, most recently from a3eb052 to d2edf1a Compare September 6, 2026 16:57
@cognaiger9
cognaiger9 marked this pull request as ready for review September 6, 2026 16:57
@cognaiger9
cognaiger9 force-pushed the perf/perf-w4a8-moe-glm52 branch 4 times, most recently from b415456 to 2f06124 Compare September 8, 2026 08:21
@cognaiger9

Copy link
Copy Markdown
Contributor Author

@BBuf can you take a look at this?

@cognaiger9
cognaiger9 force-pushed the perf/perf-w4a8-moe-glm52 branch 3 times, most recently from 1e51565 to 0964717 Compare September 11, 2026 07:17
_check_int4_fp8_grouped_gemm(batch_size, k, n, num_experts)


# M is the original token count; the kernel receives M * topk routed rows.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we remove these two files? They seem to be temporary test and benchmarking scripts and are probably unnecessary to keep in the repository.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i've removed these 2

@@ -197,6 +263,29 @@ void cutlass_w4a8_moe_mm_sm90(
torch::Tensor const& s_strides,
int64_t chunk_size,
int64_t topk) {
const c10::cuda::CUDAGuard device_guard(a_tensors.device());
// Match the model token, allowing descriptions such as "NVIDIA H200 SXM".

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Match the model token, allowing descriptions such as "NVIDIA H200 SXM".
// Detect H200 devices, including names such as "NVIDIA H200 SXM".

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@cognaiger9
cognaiger9 force-pushed the perf/perf-w4a8-moe-glm52 branch 2 times, most recently from 0e99cf5 to c502d85 Compare September 16, 2026 09:01
@BBuf BBuf added the run-ci CI: run the baseline test suite on this PR label Sep 18, 2026
@cognaiger9
cognaiger9 force-pushed the perf/perf-w4a8-moe-glm52 branch from c502d85 to 126994e Compare September 18, 2026 04:21
@BBuf
BBuf merged commit 83e29d6 into sgl-project:main Sep 19, 2026
88 of 118 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

run-ci CI: run the baseline test suite on this PR sgl-kernel

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants