Skip to content

Honor per-module quantization override in the fused GroupedMLP path - #8286

Open
xrennvidia wants to merge 4 commits into
NVIDIA:mainfrom
xrennvidia:xren/fused_grouped_mlp_quant_override
Open

xrennvidia wants to merge 4 commits into
NVIDIA:mainfrom
xrennvidia:xren/fused_grouped_mlp_quant_override

Conversation

@xrennvidia

@xrennvidia xrennvidia commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

The TE op-fuser builds its quantizers from the ambient autocast recipe, so a --te-precision-config-file override that keeps the experts quantized but with a different recipe (e.g. MXFP8 MTP experts under a global NVFP4 recipe) was ignored by the fused kernels: forward ran under NVFP4 while the module and its GTP gather were MXFP8, and backward then failed in the NVFP4 amax lookup.

Enter the module's own quantization autocast around the fused call, exactly as TEGroupedLinear.forward does on the unfused path. fc1 and fc2 must carry the same override since fusion spans both. A bf16 override still disables fusion.

Requires the matching Transformer Engine change that quantizes GTP-gathered BF16 weights inside the fused grouped MLP.

  • I, the PR author, have personally reviewed every line of this PR.

What does this PR do?

⚠️ For major changes (either in lines of code or in its impact), please make sure to first share a design doc with the team. If you're unsure what's the best way to do so, contact @NVIDIA/mcore-oncall.

Issue tracking

For PRs from open-source community contributors:

  • New features: a linked issue is required. Please open a feature request and reference it here before submitting the PR.
  • Small updates (bug fixes, minor improvements): a linked issue is recommended and will accelerate the PR review process.

Linked issue:

Contribution process

Pre-checks

  • I have added relevant unit tests
  • I have added relevant functional tests
  • If this PR adds or changes a GPU kernel (Triton, jit_fuser/torch.compile, CUDA extension, TE or external-library dispatch, or a scatter/index accumulation), I have added or updated its bit-exact determinism test and registered it in tests/unit_tests/determinism/kernels/manifest.py (guide)
  • I have added proper typing to my code Typing guidelines
  • I have added relevant documentation
  • I have run the autoformatter.sh on my PR

Code review

Feel free to message or comment @NVIDIA/mcore-oncall to help accelerate your merge into main. The less complex your PR is, the faster it will be approved and merged!

All PRs start as draft. If you open a non-draft PR, it will be automatically converted to draft.

Step 1: Mark PR as "Ready for Review"

  1. When your PR is ready, click Ready for Review.
  2. An oncall reviewer is auto-assigned and expert reviewers are notified based on your changes.
    • Some PRs may jump straight to step 2. This is determined by .github/CODEOWNERS.

⚠️ Only mark as ready once merge-conflicts are resolved and the CI is passing.
Final Review might get declined if these requirements are not fulfilled.

Step 2: Final Review

For PRs that change megatron/core, once all expert reviewers have approved, the Final Review label is applied automatically and final reviewers are assigned.

For PRs outside megatron/core, this step is skipped.

Step 3: Approved

Once all required reviewers have approved, the Approved label is applied automatically.

Merge

Any member of mcore-engineers will be able to merge your PR.

@xrennvidia
xrennvidia requested review from a team as code owners October 16, 2026 06:28
@copy-pr-bot

copy-pr-bot Bot commented Oct 16, 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.

@svcnvidia-nemo-ci
svcnvidia-nemo-ci marked this pull request as draft October 16, 2026 06:28
@github-actions

Copy link
Copy Markdown
Contributor

This PR has been automatically converted to draft because all PRs must start as drafts.

When you are ready for review, click Ready for Review to begin the review process. This will:

  1. Add the oncall reviewer (optional reviewer)
  2. Add required review teams based on your changes

See the contribution guide for more details.

@xrennvidia
xrennvidia marked this pull request as ready for review October 16, 2026 06:28
The TE op-fuser builds its quantizers from the ambient autocast recipe, so a
--te-precision-config-file override that keeps the experts quantized but with a
different recipe (e.g. MXFP8 MTP experts under a global NVFP4 recipe) was
ignored by the fused kernels: forward ran under NVFP4 while the module and its
GTP gather were MXFP8, and backward then failed in the NVFP4 amax lookup.

Enter the module's own quantization autocast around the fused call, exactly as
TEGroupedLinear.forward does on the unfused path. fc1 and fc2 must carry the
same override since fusion spans both. A bf16 override still disables fusion.

Requires the matching Transformer Engine change that quantizes GTP-gathered
BF16 weights inside the fused grouped MLP.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Signed-off-by: Xiaowei Ren <xren@nvidia.com>
@xrennvidia
xrennvidia force-pushed the xren/fused_grouped_mlp_quant_override branch from 9a1309e to dfb6d3a Compare October 16, 2026 06:42
xrennvidia and others added 3 commits October 15, 2026 23:57
Single-process (test_grouped_mlp.py):
  * An MXFP8 override on the experts under a global NVFP4 autocast keeps
    _with_fused_impl True, forms the CuTeDSL fused op, enters the module's
    MXFP8 recipe inside the NVFP4 autocast (checked via FP8GlobalStateManager
    and the fused op's weight quantizers), and matches a plain global-MXFP8 run
    of the same weights bit-exactly in output, input grad and weight grads.
  * An override matching only linear_fc2 keeps fusion on but raises at
    forward, since fusion spans fc1 and fc2.

4-GPU EGTP_remat (test_moe_egtp.py):
  * Quantized counterpart of the bf16-override worker: MXFP8 override on
    `*mtp.layers.*`, fused weighted squared-ReLU experts, global NVFP4
    autocast, egtp_remat_size 1 (control) and 2 (production repro). Asserts
    the fused op formed, that it quantized with MXFP8 rather than the ambient
    NVFP4, and that backward reaches main_grad.

Without the experts.py change the single-process tests fail on the missing
context, and the EGTP_remat=2 case fails the quantizer assertion (the fused op
silently inherits NVFP4). The EGTP_remat=2 case additionally needs the
Transformer Engine fix that quantizes re-gathered BF16 shards in the fused
grouped MLP; without it the backward raises AttributeError on _columnwise_data.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Signed-off-by: Xiaowei Ren <xren@nvidia.com>
…P fix

The EGTP_remat=2 case re-gathers BF16 expert shards in the fused grouped MLP
backward, which needs Transformer Engine to quantize them with the layer
quantizer. Gate it on a capability probe for the helper that fix introduced
(ops/fused/grouped_mlp.py _quantize_unquantized_weights) rather than a version
check, since the fix is not tied to a TE release yet. The unsharded control and
the single-process tests do not depend on it and keep running everywhere.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Signed-off-by: Xiaowei Ren <xren@nvidia.com>

This branch has not been deployed

No deployments
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.

2 participants