Skip to content

Support ScaledSReLU in TE grouped MLP fuser - #4859

Merged
sraman-rgb merged 14 commits into
NVIDIA:mainfrom
sraman-rgb:srelu-fused-grouped-mlp
May 29, 2026
Merged

Support ScaledSReLU in TE grouped MLP fuser#4859
sraman-rgb merged 14 commits into
NVIDIA:mainfrom
sraman-rgb:srelu-fused-grouped-mlp

Conversation

@sraman-rgb

@sraman-rgb sraman-rgb commented May 19, 2026

Copy link
Copy Markdown
Contributor

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 the @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
  • 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 the @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.

For MRs into `dev` branch The proposed review process for `dev` branch is under active discussion.

MRs are mergable after one approval by either eharper@nvidia.com or zijiey@nvidia.com.

@sraman-rgb
sraman-rgb requested review from a team as code owners May 19, 2026 01:55
@copy-pr-bot

copy-pr-bot Bot commented May 19, 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 May 19, 2026 01:55
@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.

@sraman-rgb
sraman-rgb marked this pull request as ready for review May 19, 2026 02:00
@svcnvidia-nemo-ci
svcnvidia-nemo-ci requested a review from a team May 19, 2026 02:01
@yaox12

yaox12 commented May 19, 2026

Copy link
Copy Markdown
Member

/claude strict-review

Comment thread megatron/core/transformer/moe/experts.py
Comment thread megatron/core/transformer/moe/experts.py
Comment thread tests/unit_tests/transformer/moe/test_grouped_mlp.py

@claude claude Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review Summary

CRITICAL: 0 | IMPORTANT: 1 | SUGGESTION: 2

Findings

  1. [IMPORTANT Compatibility] — The self.activation_funcself.config.activation_func change in _is_fused_impl_supported and _make_fused_ops is broader than just ScaledSReLU support. It also enables the fused TE op path for SwiGLU and quick_gelu when use_te_activation_func=True, which was previously blocked (assertion failure). This is a correct fix — the fused TE ops handle activation themselves — but it's a behavior change for existing configurations that deserves mention in the PR description.

  2. [SUGGESTION Simplification]use_srelu_fusion doesn't guard against gated_linear_unit=True. Adding and not self.config.gated_linear_unit would be a cheap defensive check against a misconfiguration where ScaledSReLU (non-GLU) would be used with doubled FC1 output. Not a regression (the same gap exists in the non-fused path at line 661), but easy to fix while the block is being refactored.

  3. [SUGGESTION] — The test at line 526 (module.activation_func = object()) is a good pattern that verifies _is_fused_impl_supported reads from config.activation_func rather than self.activation_func.

Overall Assessment

Low risk. The core implementation is correct — ScaledSReLU is properly gated behind use_fused_weighted_squared_relu, the TE import check (try/except ImportError) follows the existing pattern for ScaledClampedQGeGLU, and the tests cover both the _is_fused_impl_supported gate (parametrized True/False) and _make_fused_ops construction. The self.config.activation_func switch is a sensible fix that makes the fused path work correctly regardless of use_te_activation_func. No dtype, parallelism, or checkpoint compatibility concerns.

@sraman-rgb

Copy link
Copy Markdown
Contributor Author

/ok to test 68349b0

@sraman-rgb

Copy link
Copy Markdown
Contributor Author

/ok to test b079324

@svcnvidia-nemo-ci svcnvidia-nemo-ci added the Approved All necessary approvals have been made label May 28, 2026
@sraman-rgb
sraman-rgb enabled auto-merge May 28, 2026 18:33
@sraman-rgb

Copy link
Copy Markdown
Contributor Author

/ok to test e15f4eb

@chtruong814

Copy link
Copy Markdown
Contributor

/ok to test d4dad68

@sraman-rgb

Copy link
Copy Markdown
Contributor Author

/ok to test 1292dcc

@sraman-rgb

Copy link
Copy Markdown
Contributor Author

/ok to test 092f812

@copy-pr-bot

copy-pr-bot Bot commented May 29, 2026

Copy link
Copy Markdown

/ok to test 092f812

@sraman-rgb, there was an error processing your request: E2

See the following link for more information: https://docs.gha-runners.nvidia.com/cpr/e/2/

@sraman-rgb

Copy link
Copy Markdown
Contributor Author

/ok to test dcf3a7e

@svcnvidia-nemo-ci

Copy link
Copy Markdown
Contributor

🔄 Merge queue validation started!

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

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 complexity: low Expert Review [deprecated] Apply this label to indicate that your PR is ready for expert review. nemotron

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants