Skip to content

perf(moe): fuse batch-invariant permute and MXFP8 quantization - #7660

Merged
wdykas merged 2 commits into
NVIDIA:mainfrom
CharlesXu-HQ:perf/mxfp8-batch-invariant-permute-quantization
Oct 5, 2026
Merged

wdykas merged 2 commits into
NVIDIA:mainfrom
CharlesXu-HQ:perf/mxfp8-batch-invariant-permute-quantization

Conversation

@CharlesXu-HQ

Copy link
Copy Markdown
Contributor
  • I, the PR author, have personally reviewed every line of this PR.

What does this PR do?

Fuses batch-invariant MCore MoE token permutation with MXFP8 quantization while preserving the inverse-map and zero-padding contracts required by deterministic unpermute.

The fused Triton kernel can now optionally:

  • emit the (token, local expert) -> permuted row inverse map;
  • initialize MXFP8 alignment-padding rows to zero; and
  • retain the existing four-value API when neither option is requested.

mcore_fused_moe uses this path for batch-invariant MXFP8 squared-ReLU and SwiGLU. Activation behavior is unchanged; only input permutation and quantization are fused.

Issue tracking

Linked issue: Fixes #7659

Performance

RTX 5090, PyTorch 2.11.0+cu128, Triton 3.6.0. Each measurement covers batch-invariant preprocessing: permutation, zero padding, inverse-map generation, and MXFP8 quantization.

tokens hidden top-k local experts separate fused speedup
128 2688 8 128 0.121 ms 0.045 ms 2.70x
512 4096 8 64 0.121 ms 0.047 ms 2.56x
2048 4096 8 16 0.260 ms 0.087 ms 2.98x

Validation

  • TestPermuteAndQuantizeMxfp8 plus test_batch_invariant_mxfp8_permute_replays: 24 passed, 1 environment-incompatible test deselected on SM120.
  • Fused vs. separate preprocessing is byte-exact for logical FP8 data, E8M0 scales, probabilities, inverse maps, and alignment padding.
  • Squared-ReLU and SwiGLU dispatch tests exercise the real fused preprocessing path; grouped GEMM is stubbed because PyTorch's MXFP8 scaled_grouped_mm does not support SM120.
  • tools/check_kernel_determinism_coverage.py --base-ref upstream/main passes.
  • Black, isort, Ruff, py_compile, and git diff --check pass for all changed files.

Contribution process

Pre-checks

  • I have added relevant unit tests
  • I have added relevant functional tests
  • I have added or updated the bit-exact determinism test; the existing inference_moe_kernels manifest entry covers this kernel file
  • I have added proper typing to my code
  • I have added relevant documentation
  • I have run the autoformatter checks on my PR

@copy-pr-bot

copy-pr-bot Bot commented Sep 26, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

Signed-off-by: charlesxu91 <charlesxu.mi@gmail.com>
@CharlesXu-HQ
CharlesXu-HQ force-pushed the perf/mxfp8-batch-invariant-permute-quantization branch from 677853a to 94dfdf0 Compare September 26, 2026 07:54
@CharlesXu-HQ
CharlesXu-HQ marked this pull request as ready for review September 26, 2026 07:58
@CharlesXu-HQ
CharlesXu-HQ requested review from a team as code owners September 26, 2026 07:58
@svcnvidia-nemo-ci
svcnvidia-nemo-ci requested a review from a team September 26, 2026 07:59
@svcnvidia-nemo-ci svcnvidia-nemo-ci added the waiting-on-maintainers Waiting on maintainers to respond label Sep 28, 2026
@wdykas

wdykas commented Sep 29, 2026

Copy link
Copy Markdown
Contributor

thanks for contributing! left a small comment but looks good overall.

@svcnvidia-nemo-ci svcnvidia-nemo-ci added waiting-on-customer Waiting on the original author to respond and removed waiting-on-maintainers Waiting on maintainers to respond labels Sep 29, 2026
Signed-off-by: charlesxu91 <charlesxu.mi@gmail.com>
@svcnvidia-nemo-ci svcnvidia-nemo-ci removed the waiting-on-customer Waiting on the original author to respond label Oct 3, 2026
@wdykas
wdykas enabled auto-merge October 3, 2026 12:35
@svcnvidia-nemo-ci svcnvidia-nemo-ci added Approved All necessary approvals have been made and removed Final Review PR is in the "final review" stage labels Oct 3, 2026
@wdykas

wdykas commented Oct 4, 2026

Copy link
Copy Markdown
Contributor

/ok to test 213b1b8

@wdykas
wdykas added this pull request to the merge queue Oct 5, 2026
@nemo-automation-bot

Copy link
Copy Markdown

🔄 Merge queue validation started!

You can track the progress here: https://github.com/NVIDIA/Megatron-LM/actions/runs/37327446671

Merged via the queue into NVIDIA:main with commit 60e8ebd Oct 5, 2026
103 checks passed

This branch was previously deployed

2 inactive deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Approved All necessary approvals have been made community-request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fuse batch-invariant MoE permutation with MXFP8 quantization

6 participants