sugunav14andClaude Opus 5 74a1dce390 Speed up FSDP2 MoE calibration by dropping redundant expert-weight gathers (#2359)
### What does this PR do?

Type of change: Perf enhancement

`promote_static_block_weight_quantizers` runs at the end of
`max_calibrate`. All it does is read
quantizer state -- it takes the weight the iterator hands it and throws
it away. For this it goes through `iter_weights_for_calibration`, and on
a fused-MoE module that iterator yields `weight[idx]`, once per expert.

Under FSDP2 the fused weight is a DTensor spread across ranks, so
`weight[idx]` isn't a cheap view.
Slicing it makes PyTorch pull the whole fused expert weight back from
every rank, just to hand over
one slice that the loop then drops. That happens once per expert, per
projection, per layer -- tens
of thousands of round-trips on a large MoE.

The fix adds `iter_weight_quantizers_for_calibration`:

- The base `QuantModule` implementation delegates to
`iter_weights_for_calibration` and drops
the weight, so every subclass gets a correct implementation for free and
the two iterators
  cannot drift apart.
- Only the fused-MoE class — the one where materializing the weight view
is itself expensive —
overrides it, walking the per-expert quantizer `ModuleList` directly. It
keeps the same skip
condition as the weight iterator, since fetching an attribute is free
and only indexing
  collectives.

`promote_static_block_weight_quantizers` then iterates quantizers
instead of `(weight, quantizer)`
pairs. No other caller changes: the other four call sites genuinely use
the weight.

Why not just wrap the promote loop in
`enable_weight_access_and_writeback`, the way
`weight_only_quantize` does? It would still gather per module for
weights the
loop never reads. `weight_only_quantize` needs the window because it
actually computes amax from the
weight; promote only needs the quantizer.

Also included: a warn-once check if `_amax` is ever a `DTensor`. It
should not be — `_amax` is a
registered buffer, and `fully_shard` shards parameters, not buffers —
which is why the
`reduce_amax` in this loop stays local. If that assumption ever breaks,
the reduction becomes a
per-quantizer collective too, and the warning says so rather than
letting it degrade silently.

### Results

Measured on Qwen-3.8 2.4T at world 64 (8 nodes, B300), NVFP4:

| | pre-export |
|---|---|
| before | 79.3 min |
| after | **19.0 min** |

60.3 min saved, 4.2x. The block is gone rather than shortened -- the run
logs 13 silent minutes
in total, all of it model load. Calibration itself is unchanged at 2:23,
so the saving comes from
the promote loop rather than from work moving elsewhere. End-to-end
projects to 41.7 min.

### Usage

No API change. `mtq.quantize` picks this up automatically.

### Before your PR is "*Ready for review*"

- Is this change backward compatible?: ✅ Additive;
`iter_weights_for_calibration` and all its
  callers that use the weight are untouched.
- If you copied code from any other sources or added a new PIP
dependency, did you follow guidance in `CONTRIBUTING.md`: N/A
- Did you write any new necessary tests?: ✅
- Did you update
[Changelog](https://github.com/NVIDIA/Model-Optimizer/blob/main/CHANGELOG.rst)?:
✅ Under 0.47 Bug Fixes — the call site dates to 0.46.
- Did you get Claude approval on this PR?: ❌ Not yet.




<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

- **Performance**
- Reduced calibration overhead for FSDP2-sharded fused-MoE quantization
by avoiding unnecessary expert-weight gathering when only quantizer
state is needed.
- Preserved quantizer ordering and projection filtering during
calibration.

- **Bug Fixes**
- Added a warning when global amax reduction requires collective
processing for individual quantizers.

- **Tests**
- Added coverage for gated and non-gated fused-expert calibration,
including verification that fused weights are not unnecessarily indexed.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Signed-off-by: Suguna Velury <178320438+sugunav14@users.noreply.github.com>
Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-09 23:28:01 +00:00
2026-09-10 00:35:31 +08:00

Banner image

NVIDIA Model Optimizer

Documentation version license

Documentation | Roadmap | Announcement Blogs


NVIDIA Model Optimizer (referred to as Model Optimizer, or ModelOpt) is a library comprising state-of-the-art model optimization techniques including quantization, pruning, Neural Architecture Search (NAS), distillation, speculative decoding and sparsity to accelerate models.

[Input] Model Optimizer currently supports inputs of a Hugging Face, PyTorch or ONNX model.

[Optimize] Model Optimizer provides Python APIs for users to easily compose the above model optimization techniques and export an optimized quantized checkpoint. Model Optimizer is also integrated with NVIDIA Megatron-Bridge, Megatron-LM and Hugging Face Accelerate for training required inference optimization techniques.

[Export for deployment] Seamlessly integrated within the NVIDIA AI software ecosystem, the quantized checkpoint generated from Model Optimizer is ready for deployment in downstream inference frameworks like SGLang, TensorRT-LLM, TensorRT, or vLLM. The unified Hugging Face export API now supports both transformers and diffusers models.

Latest News

Previous News

Install

To install stable release packages for Model Optimizer with pip from PyPI:

pip install -U nvidia-modelopt[all]

Model Optimizer will download and install additional third-party open source software projects. Review the license terms of these open source projects before use.

To install from source in editable mode with all development dependencies or to use the latest features, run:

# Clone the Model Optimizer repository
git clone git@github.com:NVIDIA/Model-Optimizer.git
cd Model-Optimizer

pip install -e .[dev]

You can also directly use NVIDIA container images, which have Model Optimizer pre-installed:

  • nvcr.io/nvidia/pytorch:<version>-py3
  • nvcr.io/nvidia/nemo:<version>
  • nvcr.io/nvidia/tensorrt-llm/release:<version>

Before pulling and using the container images, please review their respective license terms. Make sure to upgrade Model Optimizer to the latest version as described above. Visit our installation guide for more fine-grained control on installed dependencies or for alternative docker images and environment variables to setup.

Techniques

Technique Description Examples Docs
Post Training Quantization Compress model size by 2x-4x, speeding up inference while preserving model quality! [HF LLMs / VLMs] [Megatron-Bridge LLMs / VLMs] [Diffusers] [ONNX] [Windows] [docs]
Quantization Aware Training / Distillation Refine accuracy of quantized models even further with a few training steps! [Hugging Face] [Megatron-Bridge] [docs]
Pruning Reduce your model parameters or memory footprint and accelerate inference by removing unnecessary weights! [General] [Megatron-Bridge]
Distillation Reduce deployment model size by teaching small models to behave like larger models! [Hugging Face] [Megatron-Bridge] [Megatron-LM] [docs]
Speculative Decoding Train draft modules to predict extra tokens during inference! [Hugging Face] [Megatron-LM] [docs]
Sparsity Efficiently compress your model by storing only its non-zero parameter values and their locations [Hugging Face] [docs]

Pre-Quantized Checkpoints

Resources

Model Support Matrix

Model Type Support Matrix
LLM / VLM Quantization View Support Matrix
Diffusers Quantization View Support Matrix
ONNX Quantization View Support Matrix
Windows Quantization View Support Matrix
Quantization Aware Training View Support Matrix
Pruning View Support Matrix
Distillation View Support Matrix
Speculative Decoding View Support Matrix

Deprecation Policy

Model Optimizer follows a structured approach to managing deprecated features:

  • Communication: Deprecation notices are documented in the Changelog. Deprecated items include source code statements indicating deprecation timing, with runtime warnings issued upon use.
  • Migration Period: Since Model Optimizer is still pre-1.0, we provide a 1-release (~1-month) migration period after deprecation. During this window, deprecated features continue functioning while issuing warnings.
  • Scope: The policy addresses both complete deprecations (entire APIs removed) and partial ones (specific parameters removed while methods remain).
  • Removal: Following the migration period, deprecated elements are removed in alignment with semantic versioning standards, potentially including breaking changes in minor version updates while Model Optimizer remains in 0.x.

Citation

If you use NVIDIA Model Optimizer in your research, please cite it as follows:

@misc{nvidia-modelopt,
  author       = {{NVIDIA Corporation}},
  title        = {{NVIDIA Model Optimizer}},
  howpublished = {\url{https://github.com/NVIDIA/Model-Optimizer}},
  year         = {2024--2026},
  note         = {GitHub repository}
}

Contributing

Model Optimizer is now open source! We welcome any feedback, feature requests and PRs. Please read our Contributing guidelines for details on how to contribute to this project.

AI Agents

ModelOpt's agent skills can be installed from this repository and used in any workspace.

Claude Code

claude plugin marketplace add https://github.com/NVIDIA/Model-Optimizer.git
claude plugin install modelopt@modelopt

Codex

codex plugin marketplace add https://github.com/NVIDIA/Model-Optimizer.git

Then open /plugins, select the modelopt marketplace, and install modelopt. Contributors can also use the skills directly from a checkout. See the agent tooling notes.

Top Contributors

Contributors

Happy optimizing!

S
Description
GitHub Trending: NVIDIA/Model-Optimizer
Readme Multiple Licenses
1.2 GiB
Languages
Python 97.3%
Shell 1.3%
Cuda 0.8%
Jinja 0.3%
C++ 0.2%