Skip to content

refactor(sm10x): MegaMoE arch policy + SM107 FP4 K=128 mainloop - #165

Merged
zcnrex merged 1 commit into
devfrom
chunan/sm103-decode-megamoe-1d1d-opt
Nov 27, 2026
Merged

zcnrex merged 1 commit into
devfrom
chunan/sm103-decode-megamoe-1d1d-opt

Conversation

@zcnrex

@zcnrex zcnrex commented Nov 24, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Split note: The NVFP4 decode block_m=128 + SM103 SIMT pull heuristic was split into draft PR #174 (stacked on this PR, pending Muse replay-routing benchmarks), and the independent 1D1D small-M GEMM heuristic was split into #175. This PR focuses strictly on the MegaMoE arch/mainloop refactor and SM107 FP4 K=128 mainloop, keeping existing decode block_m and SM103 dispatch-pull defaults unchanged.

  1. Architecture & MegaMoE mainloop refactor (types.cuh, sm100.hpp, mega_moe.hpp, sm100_fp8_fp4_mega_moe.{hpp,cuh})

    • Introduce shared SM10xArch { SM100, SM103, SM107 }, device-only get_compiled_sm10x_arch(), MegaMoEMainloop { Default, SM107PackedK64, SM103UltraK96, SM107K128 }, is_mega_moe_mainloop_valid() (including num_stages >= 3 for SM103UltraK96), and uses_packed_fp4_weights() in deep_gemm/include/deep_gemm/common/types.cuh.
    • Select the host arch from the JIT target (get_sm10x_arch(), i.e. 103a / 107a / 100f matching __CUDA_ARCH__) and remove unused SM103ArchSpec.
    • Consolidate per-arch mainloop selection, store-tile overrides (SM103 K=96 32/8 at BLOCK_M = 192), SIMT/TMA dispatch pull, and SMEM budget into get_mega_moe_arch_policy() (csrc/jit_kernels/heuristics/mega_moe.hpp). After get_pipeline_config_for_mega_moe() computes num_stages, re-check is_mega_moe_mainloop_valid(..., num_stages) and fall back to Default if the pipeline has too few stages (e.g. DG_MEGA_MOE_TILES overrides on SM103).
    • Preserve env overrides (DG_MEGA_MOE_SM107_K64, DG_MEGA_MOE_SM103_K96, DG_MEGA_MOE_SIMT_PULL, 5- or 6-int DG_MEGA_MOE_TILES), add DG_MEGA_MOE_SM107_K128 (default 1), and include fp4_weights, gran_k, and mainloop in the DG_PRINT_CONFIGS dedup key.
    • Compute TMEM column sizing, exclusive-allocator selection, and Default-loop tail requirement once in constexpr make_mega_moe_mainloop_plan(). Remove the unreachable compact 32-col K=96 ring for BLOCK_M = 240.
    • Drop redundant not use_k64 or not use_shuffled_weights host/device asserts (still implied on dev by RowShuffled requiring NVFP4, avoiding unnecessary conflict with [SM100] Mega MoE: one-rank FP8xFP4 fast paths for die-local weights, with opt-in bitwise parity with trtllm-gen #166).
  2. SM107 FP4 (NVFP4 / MXFP4) K=128 MegaMoE mainloop & 576-col exclusive TMEM (sm100_fp8_fp4_mega_moe.cuh, tcgen05.cuh)

    • Uses SM107's dense K=128 instruction descriptor encoding ({k_size_upper_=bit3, k_size_lower_=bit31} = {1, 0}), issuing 2 MMAs per BLOCK_K=256 stage (a_desc.lo = base + k_sub * 4, block16 for NVFP4 with 2 SF chunks/MMA, block32 via SM100_MMA_MXF4NVF4_BLOCK32_2x1SM_SS for MXFP4 with 1 SF chunk/MMA) with no cross-stage grouping and no remainder tail.
    • Supports 4 TMEM SF ring slots across all tiles: non-exclusive Allocator2Sm (<= 512 cols) for BM <= 192, and Allocator2SmExclusive (<= 576 cols: 576 for NVFP4, 544 for MXFP4) at BM = 240, with sfa_chunk_stride = (umma_n > 128) ? 8 : 4.

Verification & Relative Performance

SM107 (4× CC 10.7, 212 SMs, EP4, CUDA 13.4)

  • Correctness (SM107K128 vs Default, deterministic mode):
    • NVFP4 (gate_up_interleaved): BM=16, 64, 128, 192 (umma_n>128), 240 (T=256 & T=2048, 576-col exclusive) → calc_diff = 0.00e+00, max_abs = 0.0000e+00 (bit-exact)
    • NVFP4 (gate_up_block8): BM=128 → calc_diff = 0.00e+00, max_abs = 0.0000e+00
    • MXFP4 (gate_up_block8): BM=64, 128, 192 and BM=240 (T=2048, 544-col exclusive) → calc_diff = 0.00e+00, max_abs = 0.0000e+00
    • FP8×FP4 (SM107PackedK64 vs Default regression): BM=64 → calc_diff = 0.00e+00
  • Perf (on top of [SM10x] Mega MoE: recover the NVFP4 prefill perf regression #170):
    • NVFP4 BM=192 prefill (Muse shape, uniform routing): SM107K128 beats Default by 0.9% (T=2048, 266.6 vs 269.2 us), 0.9% (T=4096, 402.2 vs 405.8 us), and 1.3% (T=8192, 757.7 vs 768.6 us) against 0.0–0.2% A/A.
    • MXFP4 BM=240 prefill (T=2048, 544-col exclusive): 1.09x speedup (242.4 → 222.3 us).

SM103 (4× B300 SXM6, 148 SMs, EP4, CUDA 13.0)

  • Correctness (SM103UltraK96 vs Default, deterministic mode):
    • NVFP4 (gate_up_interleaved & gate_up_block8): BM=16, 128, 192 → calc_diff = 0.000e+00, max_abs = 0.0000e+00 (bit-exact); BM=240 under DG_MEGA_MOE_TILES runs Default (bitwise match).
  • MegaMoE test suite (nvfp4_trtllm, situ, l1_fp4_accuracy, l1_sentinel, nvfp4_alphas, global_tokens, pre_dispatch, and test_mega_moe_sgl on SM103) passed on the pre-split build; please re-run a quick SM103/SM107 build & smoke test after the latest review fixes (num_stages validation + get_compiled_sm10x_arch device-only).

@zcnrex zcnrex changed the title perf(sm103): optimize NVFP4 MegaMoE decode tiling/SIMT pull and SM100 1d1d small-M heuristics perf(sm10x): MegaMoE NVFP4 decode block_m=128 + SM107 FP4 K=128 + arch-cap refactor + 1d1d small-M heuristic Nov 24, 2026
zcnrex added a commit that referenced this pull request Nov 24, 2026
- Add SM10xArch, MegaMoEMainloop, is_mega_moe_mainloop_valid (including
  num_stages >= 3 for SM103UltraK96), and uses_packed_fp4_weights in
  types.cuh; keep get_compiled_sm10x_arch() device-only.
- Select the host SM10x arch from the JIT target (get_sm10x_arch()) and
  remove unused SM103ArchSpec.
- Consolidate per-arch MegaMoE mainloop, store-tile override, SIMT/TMA
  dispatch pull, and SMEM budget into get_mega_moe_arch_policy(), and
  fall back to Default if the resulting pipeline has too few stages.
- Add 5- or 6-int DG_MEGA_MOE_TILES support and include fp4_weights,
  gran_k, and mainloop in the DG_PRINT_CONFIGS dedup key.
- Add constexpr make_mega_moe_mainloop_plan() and remove unreachable
  SM103 BM=240 compact K=96 ring.
- Add SM107 FP4 (NVFP4/MXFP4) K=128 mainloop (2 MMAs per BLOCK_K=256
  stage, no Default tail), SM100_MMA_MXF4NVF4_BLOCK32_2x1SM_SS, and
  576-col Allocator2SmExclusive for BM=240.
- Drop redundant RowShuffled/K64 asserts already implied by RowShuffled
  requiring NVFP4 (avoiding unnecessary conflict with #166).
@zcnrex
zcnrex force-pushed the chunan/sm103-decode-megamoe-1d1d-opt branch from fd0f49c to 65167ac Compare November 27, 2026 07:54
@zcnrex zcnrex changed the title perf(sm10x): MegaMoE NVFP4 decode block_m=128 + SM107 FP4 K=128 + arch-cap refactor + 1d1d small-M heuristic refactor(sm10x): MegaMoE arch policy + SM107 FP4 K=128 mainloop Nov 27, 2026
@zcnrex

zcnrex commented Nov 27, 2026

Copy link
Copy Markdown
Collaborator Author

Post-split verification (65167acb)

SM107 (nv-slurm, 4× CC 10.7 / 212 SMs, CUDA 13.4, Slurm job 7323)

  • Built _C.so fresh at 65167acb.
  • MegaMoE test suite (all PASS):
    • test_mega_moe_situ.py (SM107PackedK64, use_simt_pull=1)
    • test_mega_moe_l1_fp4_accuracy.py (SM107PackedK64 + SM107K128)
    • test_mega_moe_l1_sentinel.py (NVFP4 + MXFP4, both SM107K128)
    • test_mega_moe_nvfp4_alphas.py (SM107K128)
    • test_mega_moe_global_tokens.py (4-rank NVFP4, 2-rank MXFP4 T=4096 BM=240 544-col exclusive TMEM, 2-rank --x-scales)
    • test_mega_moe_pre_dispatch.py
    • test_mega_moe_nvfp4_trtllm.py: SM107K128 default (BM=192), Default (DG_MEGA_MOE_SM107_K128=0), and BM=240 576-col exclusive via 6-int DG_MEGA_MOE_TILES=2,240,40,40,128,2 (all bitwise equal)
  • Bitwise A/B (bench_sm107_all.py, deterministic):
    • NVFP4 (gate_up_interleaved, BM=16, 64, 128, 192, 240) & gate_up_block8 (BM=128): calc_diff=0.00e+00, max_abs=0.0000e+00
    • MXFP4 (BM=64, 128, 192): calc_diff=0.00e+00, max_abs=0.0000e+00
    • FP8×FP4 (SM107PackedK64 vs Default, BM=64): calc_diff=0.00e+00

SM103 (ke-bao/kebao-b300-4node-mmx, B300 SXM6, CUDA 13.0)

  • Built _C.so fresh at 65167acb.
  • MegaMoE test suite (all PASS): test_mega_moe_situ.py, test_mega_moe_l1_fp4_accuracy.py, test_mega_moe_l1_sentinel.py, test_mega_moe_nvfp4_alphas.py, test_mega_moe_global_tokens.py (4-rank NVFP4, 2-rank MXFP4 T=4096, 2-rank --x-scales), test_mega_moe_pre_dispatch.py.
  • test_mega_moe_nvfp4_trtllm.py (all PASS, bitwise):
    • SM103UltraK96 default (BM=192, 32/8 stores, 6 stages, use_simt_pull=0)
    • Default (DG_MEGA_MOE_SM103_K96=0, BM=192, 48/48 stores, 5 stages)
    • BM=240 (DG_MEGA_MOE_TILES=2,240,40,128,2 -> Default)
    • 6-int DG_MEGA_MOE_TILES=2,192,48,48,128,2 (5 stages), 2,192,96,96,128,2 (4 stages), and 2,64,16,16,128,2 (BM=64, SM103UltraK96, use_simt_pull=0).

@zcnrex
zcnrex merged commit c7b056f into dev Nov 27, 2026
zcnrex added a commit that referenced this pull request Nov 27, 2026
Use block_m=128 as the decode floor for NVFP4 on SM103 and SM107
(monotonic in the multi-block loop) and enable SIMT dispatch pull by
default on SM103 NVFP4 decode (block_m <= 128).

Split out from #165 so it can be gated on Muse replay-routing
benchmarks independently of the arch-policy refactor and SM107 K=128.
aryatsc added a commit to aryatsc/DeepGEMM that referenced this pull request Nov 28, 2026
Brings in sgl-project#170, sgl-project#165, sgl-project#169, sgl-project#178 and sgl-project#171.

Conflicts:
- csrc/jit_kernels/impls/sm100_fp8_fp4_mega_moe.hpp: the K=64 switch is now
  `uses_packed_fp4_weights(config.mainloop)` (sgl-project#165); the row-shuffled FP8 x FP4
  layout asserts that mainloop instead of `config.use_sm107_k64`. The kernel
  template takes the mainloop in place of the two K=64 / K=96 flags, followed by
  this branch's four parameters.
- deep_gemm/include/deep_gemm/impls/sm100_fp8_fp4_mega_moe.cuh: sgl-project#165's mainloop
  plan and validity check replace the K=64 static assert; the base MMA loop is
  taken from dev (now under `run_base_loop`) with this branch's SFB word order
  for row-shuffled packed FP4 weights re-applied in it.
zcnrex added a commit that referenced this pull request Dec 1, 2026
…174)

* perf(sm10x): NVFP4 MegaMoE decode block_m=128 + SM103 SIMT dispatch pull

Use block_m=128 as the decode floor for NVFP4 on SM103 and SM107
(monotonic in the multi-block loop) and enable SIMT dispatch pull by
default on SM103 NVFP4 decode (block_m <= 128).

Split out from #165 so it can be gated on Muse replay-routing
benchmarks independently of the arch-policy refactor and SM107 K=128.

* Drop the NVFP4 decode block_m=128 floor; keep the SM103 SIMT pull

A 4-round decode sweep (expected 1..64 tokens per expert, uniform / zipf /
biased routing) found the BM128 floor 1-5% slower than BM64 on SM103 and
SM107 for uniform and moderately skewed routing; it wins only under heavy
skew at 16+ expected tokens per expert. The SM103 SIMT pull alone is
0.2-1.8% faster in every cell, including BM16.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
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.

1 participant