Skip to content

Support efficient TEGroupedMLP (moe_grouped_gemm=True) for Minitron Pruning - #1955

Merged
kevalmorabia97 merged 1 commit into
mainfrom
kmorabia/minitron-moe-grouped-gemm
Jul 24, 2026
Merged

Support efficient TEGroupedMLP (moe_grouped_gemm=True) for Minitron Pruning#1955
kevalmorabia97 merged 1 commit into
mainfrom
kmorabia/minitron-moe-grouped-gemm

Conversation

@kevalmorabia97

@kevalmorabia97 kevalmorabia97 commented Jul 9, 2026

Copy link
Copy Markdown
Collaborator

What does this PR do?

Type of change: New feature

Add Minitron pruning support for MoE models loaded with the efficient fused grouped GEMM experts (TEGroupedMLP), in addition to the existing TESequentialMLP path.

  • New _DynamicTEGroupedLinear + _DynamicTEGroupedMLP dynamic modules slice the per-expert grouped weights (num_moe_experts / moe_ffn_hidden_size / hidden_size) and reorder/drop experts via num_gemms, mirroring the SequentialMLP path with a minimal DynamicModule diff.
  • Since Minitron prunes homogeneously, a single shared moe_ffn_hidden_size is pruned across experts (SequentialMLP keeps one per expert). Same pruned width and independent per-expert weights; only the kept-channel index set is shared.
  • examples/megatron_bridge/prune_minitron.py uses grouped GEMM by default (--no_moe_grouped_gemm to fall back to SequentialMLP).

Usage

torchrun --nproc_per_node 2 prune_minitron.py \
    --hf_model_name_or_path <moe-model> \
    --prune_target_active_params 3e9 \
    --output_hf_path /tmp/pruned   # add --no_moe_grouped_gemm to use SequentialMLP

Testing

Verified in an nvcr.io/nvidia/nemo:26.06 + MBridge main (as of 23 Jul) mounted so it mimics nemo:26.08 behavior.

  • GPT MoE dynamic-module + pruning + parameter-sorting tests parametrized over both expert impls.

  • Mamba hybrid NAS metric tests: params-based now covers grouped GEMM, memory-based stays SequentialMLP (exact param counts / top-k / search-space-size assertions hold identically).

  • NemotronH end-to-end test_prune_minitron exercises real-forward NAS without grouped GEMM (to be enabled in 26.08 container)

  • Compared Nemotron-3-Nano-30B-A3B pruning: SequentialMLP vs GroupedGEMM on 4x B300 (accuracy + speed)

Metric TESequentialMLP (old) TEGroupedLinear (new)
Calibration time 6.5 mins 3.5 mins
Time to evaluate Top-10 pruned candidates 23 mins 11 mins

Top-10 Pruned Candidates — MMLU Scores

# export_config params TESequentialMLP (old) TEGroupedLinear (new)
1 L52, h2688, mamba 56×48, 96 experts, ffn 1536, shared 3072 20.09B 0.2713 0.2846
2 L52, h2688, mamba 48×56, 104 experts, ffn 1536, shared 3072 21.61B 0.2580 0.2594
3 L52, h2560, mamba 48×64, 96 experts, ffn 1536, shared 3712 19.28B 0.3951 0.3895
4 L52, h2304, mamba 64×64, 104 experts, ffn 1856, shared 3072 22.28B 0.4951 0.4944
5 L52, h2560, mamba 48×48, 96 experts, ffn 1792, shared 3328 21.99B 0.2685 0.2580
6 L48, h2560, mamba 56×56, 104 experts, ffn 1792, shared 3072 23.68B 0.4741 0.4657
7 L46, h2560, mamba 64×56, 104 experts, ffn 1792, shared 3072 23.68B 0.2385 0.2371
8 L52, h2688, mamba 48×56, 96 experts, ffn 1536, shared 3072 20.09B 0.2587 0.2622
9 L52, h2304, mamba 64×64, 96 experts, ffn 1856, shared 3072 20.70B 0.4888 0.4860
10 L50, h2560, mamba 48×48, 104 experts, ffn 1792, shared 3712 23.68B 0.2517 0.2531

Before your PR is "Ready for review"

  • Is this change backward compatible?: ✅
  • Did you write any new necessary tests?: ✅
  • Did you update Changelog?: ✅
  • Did you get Claude approval on this PR?: ✅

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features
    • Improved MoE pruning and NAS/search-space handling to support both grouped-GEMM and sequential expert layouts, including optimized grouped-GEMM execution for Minitron.
    • Added --no_moe_grouped_gemm to force the sequential expert path when required.
  • Bug Fixes
    • Tightened --prune_score_func parsing for MMLU to accept only mmlu_<N>pct_bs<bs>.
    • Added a safety check in Megatron prefill to prevent int32 indexing overflow by asking to reduce calibration batch size.
  • Tests
    • Expanded GPT and Mamba GPU pruning/search-space tests to cover both MoE modes.
  • Documentation
    • Updated release notes and bridge/pruning guidance for the grouped-GEMM behavior.

@coderabbitai

coderabbitai Bot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 7f96b2dc-0add-44f7-8807-ee72c3990994

📥 Commits

Reviewing files that changed from the base of the PR and between d1dd5f6 and ab0387f.

📒 Files selected for processing (10)
  • CHANGELOG.rst
  • examples/megatron_bridge/prune_minitron.py
  • modelopt/torch/nas/plugins/megatron.py
  • modelopt/torch/prune/plugins/mcore_minitron.py
  • modelopt/torch/utils/plugins/mbridge.py
  • modelopt/torch/utils/plugins/megatron_generate.py
  • tests/examples/megatron_bridge/test_prune_minitron.py
  • tests/gpu_megatron/torch/nas/plugins/test_megatron_gpt_dynamic_modules.py
  • tests/gpu_megatron/torch/prune/plugins/test_mcore_gpt_minitron_pruning.py
  • tests/gpu_megatron/torch/prune/plugins/test_mcore_mamba_minitron_pruning.py
🚧 Files skipped from review as they are similar to previous changes (10)
  • CHANGELOG.rst
  • tests/examples/megatron_bridge/test_prune_minitron.py
  • modelopt/torch/utils/plugins/megatron_generate.py
  • tests/gpu_megatron/torch/nas/plugins/test_megatron_gpt_dynamic_modules.py
  • modelopt/torch/utils/plugins/mbridge.py
  • tests/gpu_megatron/torch/prune/plugins/test_mcore_mamba_minitron_pruning.py
  • examples/megatron_bridge/prune_minitron.py
  • modelopt/torch/prune/plugins/mcore_minitron.py
  • modelopt/torch/nas/plugins/megatron.py
  • tests/gpu_megatron/torch/prune/plugins/test_mcore_gpt_minitron_pruning.py

📝 Walkthrough

Walkthrough

Adds grouped-GEMM MoE expert support to dynamic NAS and Minitron pruning, exposes grouped/sequential selection in the pruning example, expands grouped and sequential test coverage, and adds an int32 indexing guard for Mamba calibration prefill.

Changes

Grouped GEMM MoE Pruning

Layer / File(s) Summary
Dynamic grouped-GEMM MoE modules
modelopt/torch/nas/plugins/megatron.py
Adds dynamic grouped linear and MLP modules for slicing, reordering, exporting, and modifying grouped expert weights.
Grouped MLP importance estimation
modelopt/torch/prune/plugins/mcore_minitron.py
Registers grouped MLPs and collects fused linear_fc2 activations to estimate shared FFN hidden-size importance.
Pruning example and bridge configuration
examples/megatron_bridge/prune_minitron.py, modelopt/torch/utils/plugins/mbridge.py, CHANGELOG.rst, tests/examples/megatron_bridge/test_prune_minitron.py
Adds --no_moe_grouped_gemm, wires moe_grouped_gemm, tightens MMLU score parsing, updates bridge guidance, and documents the feature.
NAS and pruning validation
tests/gpu_megatron/torch/nas/plugins/test_megatron_gpt_dynamic_modules.py, tests/gpu_megatron/torch/prune/plugins/*
Tests grouped and sequential MoE module types, search-space calculations, parameter sorting, pruning shapes, and Mamba hybrid configurations.

Mamba calibration indexing guard

Layer / File(s) Summary
Prefill indexing validation
modelopt/torch/utils/plugins/megatron_generate.py
Validates Mamba calibration indexing against int32 limits using the padded sequence length and raises on overflow.

Estimated code review effort: 4 (Complex) | ~60 minutes

Sequence Diagram(s)

sequenceDiagram
  participant PruneExample
  participant MegatronBridge
  participant DynamicMoE
  participant ImportanceRegistry
  PruneExample->>MegatronBridge: set moe_grouped_gemm
  MegatronBridge->>DynamicMoE: construct TEGroupedMLP experts
  DynamicMoE->>ImportanceRegistry: register grouped MLP importance
  ImportanceRegistry->>DynamicMoE: collect expert and FFN activations
  DynamicMoE-->>PruneExample: export pruned grouped experts
Loading

Suggested reviewers: chenhanyu, aanoosheh, jenchen13

🚥 Pre-merge checks | ✅ 5 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 6.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: adding TEGroupedMLP grouped-GEMM support to Minitron pruning.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Security Anti-Patterns ✅ Passed Changed Python files add no forbidden loads, hardcoded trust_remote_code, builtin eval/exec, #nosec, or new deps; trust_remote_code remains configurable.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch kmorabia/minitron-moe-grouped-gemm

Comment @coderabbitai help to get the list of available commands.

@copy-pr-bot

copy-pr-bot Bot commented Jul 9, 2026

Copy link
Copy Markdown

Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually.

Contributors can view more details about this message here.

@kevalmorabia97 kevalmorabia97 changed the title Add Minitron pruning support for grouped-GEMM MoE (TEGroupedMLP) Support efficient TEGroupedMLP (moe_grouped_gemm=True) for Minitron Pruning Jul 9, 2026
@kevalmorabia97

Copy link
Copy Markdown
Collaborator Author

/claude review

@kevalmorabia97

Copy link
Copy Markdown
Collaborator Author

@CodeRabbit full review

@coderabbitai

coderabbitai Bot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor
✅ Action performed

Full review finished.

@github-actions

github-actions Bot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor
PR Preview Action v1.8.1
Preview removed because the pull request was closed.
2026-07-24 16:42 UTC

@kevalmorabia97

Copy link
Copy Markdown
Collaborator Author

/ok to test 21269a2

@codecov

codecov Bot commented Jul 9, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.70115% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 77.84%. Comparing base (d984de3) to head (ab0387f).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
modelopt/torch/nas/plugins/megatron.py 96.87% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1955      +/-   ##
==========================================
- Coverage   78.47%   77.84%   -0.63%     
==========================================
  Files         518      518              
  Lines       58574    58658      +84     
==========================================
- Hits        45967    45664     -303     
- Misses      12607    12994     +387     
Flag Coverage Δ
examples 43.28% <29.88%> (-0.23%) ⬇️
gpu 58.99% <97.70%> (-0.58%) ⬇️
regression 15.11% <1.14%> (+0.05%) ⬆️
unit 54.95% <1.14%> (-0.07%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@coderabbitai coderabbitai 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.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
modelopt/torch/utils/plugins/mbridge.py (1)

106-107: 📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Stale docstring contradicts this PR's new grouped-GEMM pruning support.

The moe_grouped_gemm arg docstring still says "Pruning does not support grouped GEMM yet," but this PR adds exactly that support, and prune_minitron.py now defaults to moe_grouped_gemm=True. Please update this line to reflect current behavior.

📝 Proposed fix
-        moe_grouped_gemm: Whether to use grouped GEMM for MoE.
-            Pruning does not support grouped GEMM yet.
+        moe_grouped_gemm: Whether to use grouped GEMM for MoE.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@modelopt/torch/utils/plugins/mbridge.py` around lines 106 - 107, The
docstring for `moe_grouped_gemm` in `MBridge` is stale and still says pruning
does not support grouped GEMM; update that description to match the new behavior
introduced by this PR, since grouped-GEMM pruning is now supported and
`prune_minitron.py` defaults to `moe_grouped_gemm=True`. Keep the wording
aligned with the current implementation so the documentation in `mbridge.py`
accurately reflects the `moe_grouped_gemm` flag.
🧹 Nitpick comments (1)
modelopt/torch/prune/plugins/mcore_minitron.py (1)

1390-1391: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Unclear purpose of the inserted middle dimension.

[:, None, :] inserts a size-1 dim that is immediately collapsed by the subsequent .mean(dim=0) / .sum(dim=0), making it a no-op given the following reductions. If this is intentionally mirroring a [seq, batch, hidden] shape convention from the non-grouped path, a short comment would help; otherwise it can be simplified.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@modelopt/torch/prune/plugins/mcore_minitron.py` around lines 1390 - 1391, The
`acts` computation in `mcore_minitron.py` has an inserted singleton middle
dimension that is immediately removed by the later `mean(dim=0)` and
`sum(dim=0)`. Either simplify the
`gather_from_tensor_model_parallel_region`/`acts` pipeline to remove the no-op
`[:, None, :]` shape expansion, or keep it and add a brief clarifying comment in
the `acts` assignment block explaining why the `[seq, batch, hidden]`-style
dimension is needed for consistency with the non-grouped path.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@modelopt/torch/utils/plugins/mbridge.py`:
- Around line 106-107: The docstring for `moe_grouped_gemm` in `MBridge` is
stale and still says pruning does not support grouped GEMM; update that
description to match the new behavior introduced by this PR, since grouped-GEMM
pruning is now supported and `prune_minitron.py` defaults to
`moe_grouped_gemm=True`. Keep the wording aligned with the current
implementation so the documentation in `mbridge.py` accurately reflects the
`moe_grouped_gemm` flag.

---

Nitpick comments:
In `@modelopt/torch/prune/plugins/mcore_minitron.py`:
- Around line 1390-1391: The `acts` computation in `mcore_minitron.py` has an
inserted singleton middle dimension that is immediately removed by the later
`mean(dim=0)` and `sum(dim=0)`. Either simplify the
`gather_from_tensor_model_parallel_region`/`acts` pipeline to remove the no-op
`[:, None, :]` shape expansion, or keep it and add a brief clarifying comment in
the `acts` assignment block explaining why the `[seq, batch, hidden]`-style
dimension is needed for consistency with the non-grouped path.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: f6ded485-9fc1-4504-b19d-855a1c305887

📥 Commits

Reviewing files that changed from the base of the PR and between 0593df0 and 21269a2.

📒 Files selected for processing (8)
  • CHANGELOG.rst
  • examples/megatron_bridge/prune_minitron.py
  • modelopt/torch/nas/plugins/megatron.py
  • modelopt/torch/prune/plugins/mcore_minitron.py
  • modelopt/torch/utils/plugins/mbridge.py
  • tests/gpu_megatron/torch/nas/plugins/test_megatron_gpt_dynamic_modules.py
  • tests/gpu_megatron/torch/prune/plugins/test_mcore_gpt_minitron_pruning.py
  • tests/gpu_megatron/torch/prune/plugins/test_mcore_mamba_minitron_pruning.py

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Claude review passed — no blocking issues found. LGTM

Summary

Findings — CRITICAL: 0, IMPORTANT: 0, SUGGESTION: 1

Reviewed all 8 changed files. Prioritized the three modelopt/torch/ source files (nas/plugins/megatron.py, prune/plugins/mcore_minitron.py, utils/plugins/mbridge.py), the example driver, and the three GPU test files. (Note: the two-dot diff against the shallow base tip surfaced unrelated main-branch churn in examples/onnx_ptq/* and modelopt/onnx/*; those are not part of this PR's file list and were excluded.)

This is a clean, well-scoped feature that adds a TEGroupedMLP (grouped-GEMM) dynamic-module path alongside the existing SequentialMLP path for Minitron MoE pruning. I traced the algorithm end-to-end:

  • Mode/State composability ✅ — The num_local_experts TracedHp is the same object shared across linear_fc1, linear_fc2, and (via _DynamicMoELayer) the router, so _slice_order-based expert reorder/drop stays consistent across all three. moe_ffn_hidden_size is a single shared hparam (correct for Minitron's homogeneous pruning), and the search-space-size / sortable-hparam-count test assertions were updated accordingly.
  • Export fidelity ✅_DynamicTEGroupedLinear.export() reads all reordered+sliced weight{i}/bias{i} via the dynamic getters before mutating, clones them, drops the per-expert params, folds num_gemms/in_features/out_features through super().export(), then re-registers exactly the active kept experts. Ordering is correct.
  • Importance estimator ✅_register_grouped_mlp_importance reuses the SequentialMLP expert-L2 hook for num_local_experts and adds an fc2-input activation score for moe_ffn_hidden_size matching the dense _DynamicMLP reduction. The score is stashed in _activations["ffn_activations"] so it round-trips through the per-rank score checkpoint.
  • Performance ✅ — No hot-path CPU sync: the _slice_order.tolist() in the expert getter only runs post-sort, and _DynamicMoELayer.forward already blocks forward in the sorted/trimmed state until export.

The single finding is a non-blocking stale docstring in mbridge.py (the inline comment below it was correctly updated, but the Args: entry still says pruning doesn't support grouped GEMM).

Risk: low. Additive change mirroring an established, tested pattern; both paths are exercised by the parametrized GPU tests.

@kevalmorabia97
kevalmorabia97 force-pushed the kmorabia/minitron-moe-grouped-gemm branch from 21269a2 to fc29d46 Compare July 10, 2026 05:54
@kevalmorabia97

Copy link
Copy Markdown
Collaborator Author

/ok to test fc29d46

@kevalmorabia97
kevalmorabia97 force-pushed the kmorabia/minitron-moe-grouped-gemm branch 3 times, most recently from 1073a71 to f8b2d51 Compare July 16, 2026 18:20
@kevalmorabia97

Copy link
Copy Markdown
Collaborator Author

/ok to test f8b2d51

@kevalmorabia97

Copy link
Copy Markdown
Collaborator Author

/ok to test 1c8cf2b

@kevalmorabia97
kevalmorabia97 force-pushed the kmorabia/minitron-moe-grouped-gemm branch 2 times, most recently from db0afc9 to a1bc8b3 Compare July 23, 2026 06:09
@kevalmorabia97

Copy link
Copy Markdown
Collaborator Author

/ok to test a1bc8b3

@kevalmorabia97

Copy link
Copy Markdown
Collaborator Author

/ok to test d83f4ba

@kevalmorabia97
kevalmorabia97 force-pushed the kmorabia/minitron-moe-grouped-gemm branch from d83f4ba to 1a7dbc2 Compare July 23, 2026 13:03
@kevalmorabia97

Copy link
Copy Markdown
Collaborator Author

/ok to test 1a7dbc2

@kevalmorabia97
kevalmorabia97 force-pushed the kmorabia/minitron-moe-grouped-gemm branch from 1a7dbc2 to d1dd5f6 Compare July 23, 2026 16:51
@kevalmorabia97

Copy link
Copy Markdown
Collaborator Author

/ok to test d1dd5f6

@kevalmorabia97
kevalmorabia97 marked this pull request as ready for review July 23, 2026 17:15
@kevalmorabia97
kevalmorabia97 requested review from a team as code owners July 23, 2026 17:15

@coderabbitai coderabbitai 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.

Warning

CodeRabbit couldn't request changes on this pull request because it doesn't have sufficient GitHub permissions.

Please grant CodeRabbit Pull requests: Read and write permission and re-run the review.

👉 Steps to fix this

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
examples/megatron_bridge/prune_minitron.py (1)

513-518: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Validate the parsed MMLU parameters.

The regex checks only the format, so values such as mmlu_0pct_bs0 and mmlu_101pct_bs1 are accepted and passed downstream as invalid fraction/batch_size values. Reject percentages outside 1..100 and batch sizes below 1. Also align the existing help text with the accepted mmlu_<N>pct_bs<bs> format.

Proposed validation
         if match:
-            mmlu_frac = float(match.group(1)) / 100.0
-            batch_size = int(match.group(2))
+            mmlu_pct = int(match.group(1))
+            batch_size = int(match.group(2))
+            if not 1 <= mmlu_pct <= 100 or batch_size < 1:
+                raise ValueError("MMLU percentage must be 1-100 and batch size must be positive")
+            mmlu_frac = mmlu_pct / 100.0

As per coding guidelines, validate external input once at the interface boundary.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@examples/megatron_bridge/prune_minitron.py` around lines 513 - 518, Update
the MMLU argument parsing around args.prune_score_func to validate the parsed
percentage is between 1 and 100 and batch_size is at least 1 before assigning or
passing downstream. Keep the existing mmlu_<N>pct_bs<bs> format and revise the
associated help text to describe that format and accepted ranges.

Source: Coding guidelines

🧹 Nitpick comments (1)
tests/examples/megatron_bridge/test_prune_minitron.py (1)

63-65: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add coverage for the new grouped-GEMM default.

Both integration commands pass --no_moe_grouped_gemm, so they exercise only TESequentialMLP. A regression in the new default or in moe_grouped_gemm=not args.no_moe_grouped_gemm would go undetected. Keep these compatibility runs if needed, but add or parameterize a nemo:26.08+ run without the flag.

As per path instructions, tests for new behavior must exercise the real implementation.

Also applies to: 130-132

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/examples/megatron_bridge/test_prune_minitron.py` around lines 63 - 65,
Add integration-test coverage for the grouped-GEMM default in the prune command
setup, while preserving the existing compatibility runs that pass
--no_moe_grouped_gemm. Add or parameterize a nemo:26.08+ execution without that
flag so the real default path and moe_grouped_gemm behavior are exercised.

Source: Path instructions

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@modelopt/torch/utils/plugins/megatron_generate.py`:
- Around line 103-106: Update the overflow message in the guard around
batch_size, seq_length, and d to calculate the maximum safe batch size with
(2**31 - 1) // (seq_length * d), matching the existing >= 2**31 rejection
condition.

---

Outside diff comments:
In `@examples/megatron_bridge/prune_minitron.py`:
- Around line 513-518: Update the MMLU argument parsing around
args.prune_score_func to validate the parsed percentage is between 1 and 100 and
batch_size is at least 1 before assigning or passing downstream. Keep the
existing mmlu_<N>pct_bs<bs> format and revise the associated help text to
describe that format and accepted ranges.

---

Nitpick comments:
In `@tests/examples/megatron_bridge/test_prune_minitron.py`:
- Around line 63-65: Add integration-test coverage for the grouped-GEMM default
in the prune command setup, while preserving the existing compatibility runs
that pass --no_moe_grouped_gemm. Add or parameterize a nemo:26.08+ execution
without that flag so the real default path and moe_grouped_gemm behavior are
exercised.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 07e15542-5db1-43f7-b695-eaff3c4983f2

📥 Commits

Reviewing files that changed from the base of the PR and between 21269a2 and d1dd5f6.

📒 Files selected for processing (10)
  • CHANGELOG.rst
  • examples/megatron_bridge/prune_minitron.py
  • modelopt/torch/nas/plugins/megatron.py
  • modelopt/torch/prune/plugins/mcore_minitron.py
  • modelopt/torch/utils/plugins/mbridge.py
  • modelopt/torch/utils/plugins/megatron_generate.py
  • tests/examples/megatron_bridge/test_prune_minitron.py
  • tests/gpu_megatron/torch/nas/plugins/test_megatron_gpt_dynamic_modules.py
  • tests/gpu_megatron/torch/prune/plugins/test_mcore_gpt_minitron_pruning.py
  • tests/gpu_megatron/torch/prune/plugins/test_mcore_mamba_minitron_pruning.py
🚧 Files skipped from review as they are similar to previous changes (7)
  • CHANGELOG.rst
  • tests/gpu_megatron/torch/prune/plugins/test_mcore_mamba_minitron_pruning.py
  • modelopt/torch/utils/plugins/mbridge.py
  • modelopt/torch/prune/plugins/mcore_minitron.py
  • tests/gpu_megatron/torch/nas/plugins/test_megatron_gpt_dynamic_modules.py
  • tests/gpu_megatron/torch/prune/plugins/test_mcore_gpt_minitron_pruning.py
  • modelopt/torch/nas/plugins/megatron.py

Comment thread modelopt/torch/utils/plugins/megatron_generate.py Outdated
Support pruning MoE models loaded with moe_grouped_gemm=True (fused
TEGroupedMLP) in addition to the existing TESequentialMLP path.

- Add _DynamicTEGroupedLinear + _DynamicTEGroupedMLP dynamic modules that
  slice per-expert grouped weights (num_moe_experts / moe_ffn_hidden_size /
  hidden_size) and reorder/drop experts via num_gemms, mirroring the
  SequentialMLP path. A single shared moe_ffn_hidden_size is pruned across
  experts since Minitron prunes homogeneously.
- Route ffn/expert importance for grouped experts and store scores in the
  checkpoint-tracked _activations dict so reprune-from-checkpoint works.
- prune_minitron.py uses grouped GEMM by default (--no_moe_grouped_gemm opts out).
- Cover both expert impls in tests: parametrize the GPT MoE dynamic-module and
  pruning tests, and switch the mamba hybrid params NAS test to grouped GEMM
  (memory NAS test stays SequentialMLP).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Signed-off-by: Keval Morabia <28916987+kevalmorabia97@users.noreply.github.com>
@kevalmorabia97
kevalmorabia97 force-pushed the kmorabia/minitron-moe-grouped-gemm branch from d1dd5f6 to ab0387f Compare July 24, 2026 12:46
@kevalmorabia97
kevalmorabia97 merged commit d143276 into main Jul 24, 2026
55 checks passed
@kevalmorabia97
kevalmorabia97 deleted the kmorabia/minitron-moe-grouped-gemm branch July 24, 2026 16:43
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