gcunhaseandClaude Opus 4.7 1eb71aec75 picker: add block-aware exclusion via optional blocks + block_agg args
Extends ``suggest_exclusion`` with two new keyword arguments so operators can
turn per-node sensitivity scores into a block-level exclusion set without
reimplementing the coverage / threshold / near-tie logic themselves. Motivated
by empirical validation on ViT-tiny where per-node picking hits a ~60% top-1
ceiling due to intra-block precision fragmentation; block-level exclusion
recovers ~75% top-1 (within 1pp of native ``trtexec --int8 --fp16``).

New API surface:

* ``blocks: Mapping[str, Sequence[str | re.Pattern]] | None = None`` -- maps
  group name to a list of regex patterns matching node paths. Each node is
  assigned to at most one group (first-match wins across the ``blocks``
  dict). Nodes matching no pattern become their own singleton group named
  after themselves, so architecturally-important standalone nodes (final
  ``LayerNormalization`` before the head, patch-embed ``Conv``, etc.) compete
  for exclusion on equal footing with multi-node blocks. When ``blocks`` is
  ``None`` (default) the picker behaves exactly as before -- fully
  backward-compatible.
* ``block_agg: Literal["sum", "max", "mean"] = "sum"`` -- aggregation used to
  compute a group's score from its members. Kept as ``Literal`` for
  IDE/mypy support, plus a runtime ``ValueError`` in ``suggest_exclusion``
  for defensive validation.

Semantics:

* When ``blocks`` is set, the picker computes per-group aggregated scores
  and applies coverage / threshold / near-tie / ``max_nodes`` /
  ``min_score_floor`` semantics identically to the per-node path. The
  returned exclusion list is the union of member node names across the
  selected groups, ready to pass as ``nodes_to_exclude=`` to
  ``modelopt.onnx.quantization.quantize``.
* Natural pairings between ``block_agg`` and picker mode -- documented in
  the docstring and RST guide:

  - ``block_agg="sum"`` with ``coverage`` (recommended default): identical
    "fraction of total KL mass" semantic as per-node coverage. Portable
    across per-node and per-block grouping on the same model.
  - ``block_agg="max"`` with ``threshold``: same units as per-node
    threshold (excludes any group whose peak-node score exceeds the
    cutoff). Preserves operator intuition when transferring per-node
    threshold guidance to the block level.
  - Other combinations remain valid but change what ``coverage`` and
    ``threshold`` mean in units; the docstring calls this out explicitly.

Implementation notes:

* The existing per-node core (coverage / threshold / near-tie logic) is
  extracted into a private ``_pick_from_scores`` helper. Both the per-node
  and per-block paths call it, so both share identical semantics for every
  future behavior change. Zero duplication.
* Two additional private helpers: ``_assign_groups`` (regex-based
  first-match-wins assignment with singleton fallback) and
  ``_aggregate_group_scores`` (dispatches on ``block_agg``).
* Backward compatibility: every existing ``suggest_exclusion`` call site
  behaves exactly as before because ``blocks`` defaults to ``None`` and the
  ``block_agg`` value is only inspected when ``blocks`` is set.

Documentation:

* ``docs/source/guides/_onnx_quantization.rst`` gains a new subsection at
  the end -- "Grouping per-node scores into architectural blocks" -- with:

  - A ``vit_tiny_patch16_224`` (timm) worked example at ``coverage=0.95``
    with ``block_agg="sum"`` that selects blocks 8, 10, 9, 11, 7 (~100
    nodes across 5 whole transformer blocks), which recovers ~75% top-1
    on ImageNet-1k versus ~60% for the best per-node picking.
  - A depth-2 example showing how to split each transformer block into
    ``blocks.N.attn`` and ``blocks.N.mlp`` sub-groups.
  - Guidance on the ``block_agg`` / picker-mode pairings.
  - A "when block-level grouping doesn't help" note calling out
    Conv-heavy architectures (MobileNet, ResNet families) where diffuse
    per-node sensitivity means the per-node picker still wins.

Signed-off-by: gcunhase <4861122+gcunhase@users.noreply.github.com>
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-09-01 00:54:30 +00:00

Banner image

NVIDIA Model Optimizer

Documentation version license

Documentation | Roadmap


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.8 GiB
Languages
Python 97.7%
Shell 1.1%
Cuda 0.8%
Jinja 0.2%
C++ 0.2%