Skip to content

[SM100] Mega MoE: Inkling2 weight layout, SiTU for NVFP4 / FP8xFP8, broadcast output - #149

Merged
zcnrex merged 2 commits into
devfrom
chunan/inkling2-mega-moe
Nov 13, 2026
Merged

zcnrex merged 2 commits into
devfrom
chunan/inkling2-mega-moe

Conversation

@zcnrex

@zcnrex zcnrex commented Nov 12, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

Inkling2 routed experts (no shared experts; NVFP4 layers and FP8 layers with per-32 UE8M0 scales) use a SiTU-style capped SwiGLU and are loaded with gate/up rows interleaved per row and weight SFs in CUTLASS 128x4 atoms. Running them through fp8_fp4_mega_moe today needs:

  • SiTU on nvfp4xnvfp4 / fp8xfp8 (it was gated to fp8xfp4).
  • A second, megamoe-layout copy of every L1 weight and SF (~1 GB per NVFP4 layer, ~2 GB per FP8 layer per GPU), since the serving engine's other MoE paths keep the checkpoint layout.
  • An all-gather after the kernel, because the caller runs attention with every rank's tokens.

Change

  • SiTU for NVFP4 and FP8xFP8. Host asserts and SymmBuffer / transform_weights_for_mega_moe checks now accept nvfp4xnvfp4 and fp8xfp8 with activation='situ'.
  • weight_layout='inkling2'. Reads the loaded tensors in place (routed only, not localized):
    • L1 weights: a 5D (packed FP4, per 32 rows) / 4D (FP8, per 16 rows) TMA descriptor permutes the per-row gate/up interleave into the megamoe SMEM order, so the MMA and epilogue are unchanged.
    • L1 SFs: a 5D UINT32 descriptor over the CUTLASS 128x4 atoms with the same row permutation; one load per 128-row block.
    • L2 weights use the plain 3D descriptor; L2 SFs reuse the TRT-LLM CUTLASS-atom descriptor and its UTCCP SMEM indexing.
  • broadcast_y. With SymmBuffer(..., gather_output=True), sym_buffer.gathered_y holds every rank's output rows (rank-major). The combine stores each finished row into every peer's gathered_y over NVLink, then the epilogue fences, grid-syncs, and exchanges an output_ready_grid_idx tag with each peer so y is complete on return. Cleared with combine_ready_grid_idx for graph replay.
  • Op schema: use_inkling2_weights and broadcast_y added to fp8_fp4_mega_moe; both default off, so existing callers are unaffected.
  • Ported from the patch SGLang applies on 0f96f72. Its dispatch count push differed from [SM100] Mega MoE: batch the dispatch counters and let every SM wait on the NVLink barrier #147; this keeps [SM100] Mega MoE: batch the dispatch counters and let every SM wait on the NVLink barrier #147's version (red for SIMT pull, atom otherwise).

Tests

GB300, EP4 (4 ranks), CUDA 13.0, this branch built with build_sgl_deep_gemm.sh. Synthetic experts with Inkling2 shapes (384 experts, top-8, hidden 4608, intermediate 2304): NVFP4, and FP8 with per-32 UE8M0 scales. Random routing, 1/8/64/256 tokens per rank.

  • inkling2 layout = megamoe layout. In-place inkling2 weights vs transform_weights_for_mega_moe copies, SiTU: bitwise equal for NVFP4 and FP8xFP8 at every size. Kernel time is the same (CUDA graph, us, megamoe / inkling2):

    tokens/rank 1 8 64 256
    NVFP4 56.8 / 57.1 152.3 / 152.4 272.4 / 274.1 283.1 / 284.7
    FP8xFP8 72.4 / 71.9 243.5 / 244.1 464.1 / 464.7 478.2 / 479.1
  • Same results as the original patch. inkling2 outputs from this branch vs the same patch on 0f96f72 (v0.2.6, the build SGLang runs): bitwise equal, 32/32 (2 layers x 4 sizes x 4 ranks). So the port onto dev, including the count-push conflict, changes no output.

  • Existing paths unchanged. megamoe layout with SwiGLU, NVFP4 and FP8xFP8: this branch vs dev (75cfbcd) bitwise equal, 32/32. Kernel time within 0.3%.

  • broadcast_y. Real Inkling2 layers 0 (NVFP4) and 40 (FP8xFP8) interleaved on one shared symmetric buffer. Broadcast output vs plain y + NCCL all-gather: bitwise equal at 1/7/64/253/1024 tokens eager and under CUDA-graph replay (3 replays each, with and without broadcast), and eager at 4096 and 16384 tokens.

  • Empty broadcast batches and debug mode. Same layers: 0-token broadcast calls interleaved with 7/64/253-token calls, and 3 CUDA-graph replays of a 0-token call followed by a 7-token call, all bitwise equal to the NCCL reference. Also bitwise equal with DG_COMM_KERNEL_DEBUG=1. SymmBuffer.destroy() frees the allocation while the object is still alive.

  • Not run: tests/test_mega_moe.py (needs DeepEP), fp8xfp4, shared experts, B200, CC 10.7.

🤖 Generated with Claude Code

…roadcast output

- `weight_layout='inkling2'`: read checkpoint expert tensors in place (per-row
  gate/up interleave, CUTLASS 128x4 SF atoms); TMA descriptors permute L1 rows
  into the `megamoe` SMEM order, so the epilogue is unchanged.
- SiTU activation allowed for `nvfp4xnvfp4` and `fp8xfp8`.
- `broadcast_y` + `SymmBuffer(gather_output=True)`: the combine writes each row
  into every rank's gathered `y`, replacing an all-gather after the kernel.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
- Accept empty broadcast batches: locate `y` through its storage, since an
  empty tensor's `data_ptr()` is null (Python and C++ checks)
- Compute the `y` offset only for `broadcast_y`, with integer math
- Keep a broadcast `y` when `DG_COMM_KERNEL_DEBUG` zeroes the buffer
- Release `gathered_y` in `SymmBuffer.destroy()`

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