Skip to content

[SM100] BF16 Mega MoE: share expert counts and send buffers in smem - #178

Merged
zcnrex merged 1 commit into
devfrom
fix/bf16-mega-moe-smem-union
Nov 28, 2026
Merged

zcnrex merged 1 commit into
devfrom
fix/bf16-mega-moe-smem-union

Conversation

@zcnrex

@zcnrex zcnrex commented Nov 28, 2026

Copy link
Copy Markdown
Collaborator

Problem

On B300, every BF16 Mega MoE launch on dev I tried hits an illegal memory access. DeepEP reports it later as symmetric.hpp:136 ... Cuda failure 700.

#161 changed get_pipeline_config_for_mega_moe to size the dispatch region as max(expert_token_count, dispatch_send_buffer), matching the union it added to the FP8xFP4 kernel. The BF16 kernel uses the same host function but still lays the two out as separate 1 KiB-aligned fields. Its SharedStorage is therefore 1 KiB larger than the dynamic smem it is launched with, and every mbarrier sits past the end.

Evidence (2-rank, hidden 1024, 8 experts, top-2):

  • CUDA_LAUNCH_BLOCKING=1 moves the error to the bf16_mega_moe launch. It happens in the first non-graph call, so CUDA graphs and DeepEP are not involved.
  • GPU core dump: Warp Out-of-range Address at STS.64 [R3+0x35c40], which is warp 1 initialising the dispatch barriers. 0x35c40 = 220224 > smem_size=219524.

Fix

Put the two fields in a union, as in the FP8xFP4 kernel. Their lifetimes are disjoint here too: the counts are last used before the dispatch NVLink barrier, and the pull buffer is used only after it. sizeof(SharedStorage) now equals the host smem_size (219524).

Tests (B300, fix vs dev)

test fix dev
test_mega_moe.py 2-rank bf16 (the run_tests.sh case), corr + 24 graph replays, x3 pass IMA
same shape, --post-expert-norm pass –
test_mega_moe.py --num-processes 8 --mma-type bf16xbf16 (default shape) pass IMA
test_mega_moe_bf16_trtllm.py pass IMA

The upstream-sync PR renames this kernel to sm100_bf16_mega_moe_inference.cuh with the same separate fields, so it needs the same change.

🤖 Generated with Claude Code

PR #161 made the host size the dispatch region as
max(expert_token_count, dispatch_send_buffer), matching the union it added
to the FP8xFP4 kernel. The BF16 kernel shares that host function but kept
the two as separate 1 KiB-aligned fields, so its SharedStorage is 1 KiB
larger than the launched dynamic smem and its barriers sit past the end.

On B300 the 2-rank bf16xbf16 test (hidden 1024, 8 experts) faults on
warp 1's dispatch-barrier init (Warp Out-of-range Address, STS at smem
0x35c40 with smem_size=219524), and DeepEP reports it later as
symmetric.hpp:136 Cuda failure 700.

The two lifetimes are disjoint in the BF16 kernel as well: the counts are
last used before the dispatch NVLink barrier and the pull buffer only after.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@zcnrex
zcnrex merged commit 11f9132 into dev Nov 28, 2026
2 of 3 checks passed
@zcnrex
zcnrex deleted the fix/bf16-mega-moe-smem-union branch November 28, 2026 07:25
zcnrex added a commit that referenced this pull request Nov 28, 2026
Git carried the three PRs' edits through the *_inference renames.

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