Skip to content

Commit 6d80e22

Browse files
Merge [1/3] (#2623) into the GLM-5.3-Flash branch
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Signed-off-by: Keval Morabia <28916987+kevalmorabia97@users.noreply.github.com>
2 parents 66c08a6 + 905cb1b commit 6d80e22

96 files changed

Lines changed: 6456 additions & 1724 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.claude/skills/run-agentx‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../.agents/skills/run-agentx

‎.github/workflows/example_tests.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ jobs:
179179
# a torch-tensorrt build for the newer TensorRT is available.
180180
docker_image: "nvcr.io/nvidia/tensorrt:26.05-py3"
181181
example: ${{ matrix.example }}
182-
timeout_minutes: 45
182+
timeout_minutes: ${{ matrix.example == 'diffusers' && 60 || 45 }}
183183
pip_install_extras: "[onnx,hf,dev-test]"
184184
runner: ${{ startsWith(github.ref, 'refs/heads/pull-request/') && 'linux-amd64-gpu-rtxpro6000-latest-1' || 'linux-amd64-gpu-rtxpro6000-latest-2' }}
185185
allow_failure: ${{ contains(format(',{0},', vars.ALLOW_FAILURE_EXAMPLE_TESTS), format(',{0},', matrix.example)) }}

‎.github/workflows/unit_tests.yml‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ jobs:
5959
plugins/modelopt/skills/**
6060
linux:
6161
runs-on: ubuntu-latest
62-
timeout-minutes: 15
62+
timeout-minutes: 20
6363
steps:
6464
- uses: actions/checkout@v6
6565
- uses: ./.github/actions/ubuntu-setup
@@ -83,7 +83,7 @@ jobs:
8383
if: needs.check-file-changes.outputs.any_changed == 'true'
8484
needs: [linux, check-file-changes]
8585
runs-on: windows-latest
86-
timeout-minutes: 15
86+
timeout-minutes: 20
8787
permissions:
8888
contents: read
8989
steps:
@@ -97,7 +97,7 @@ jobs:
9797
if: needs.check-file-changes.outputs.any_changed == 'true'
9898
needs: [linux, check-file-changes]
9999
runs-on: ubuntu-latest
100-
timeout-minutes: 15
100+
timeout-minutes: 20
101101
strategy:
102102
fail-fast: false
103103
matrix:

‎.pre-commit-config.yaml‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,8 @@ repos:
117117
modelopt/torch/speculative/plugins/modeling_domino.py|
118118
modelopt/torch/speculative/plugins/hf_dflash.py|
119119
modelopt/torch/speculative/plugins/modeling_dflash.py|
120+
modelopt/torch/speculative/plugins/hf_dflash2.py|
121+
modelopt/torch/speculative/plugins/modeling_dflash2.py|
120122
modelopt/torch/speculative/plugins/hf_dspark.py|
121123
modelopt/torch/speculative/plugins/modeling_dspark.py|
122124
modelopt/torch/speculative/plugins/hf_lilicorr.py|

‎AGENTS.md‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,12 @@ These instructions apply to AI-assisted work in this repository.
4848

4949
## Sizing and splitting PRs
5050

51-
- **Keep each PR that goes up for review under ~500 changed lines of source.**
51+
- **Keep each PR that goes up for review under ~500 added lines of source.**
5252
Large PRs stall in review; exceed the budget only when the change genuinely
5353
cannot be split — a mechanical rename, generated files, or a self-contained
5454
drop such as a new example or a new model/backend that has no working
55-
intermediate state. Check the size with `git diff --stat <base>...HEAD`
55+
intermediate state. Deletions, tests, and docs don't count; check the
56+
insertions from `git diff --shortstat <base>...HEAD -- . ':!tests' ':!docs'`
5657
before opening.
5758
- **Propose the split before opening an oversized PR.** When the work in flight
5859
is already over budget, offer a series of smaller PRs and, once the user

‎CHANGELOG.rst‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,25 @@ Changelog
1313

1414
*Quantization*
1515

16+
- Add composed Hugging Face AutoQuantize recipes that run fixed PTQ or weight AutoQuantize before
17+
a separate KV-cache AutoQuantize stage, with independent resumable checkpoints for the weight and
18+
KV searches. Uniform-weight plus layer-wise mixed-KV exports are marked unsupported for deployment
19+
until a runtime consumes that metadata combination.
1620
- Add IQ1_S and IQ2_XS weight-only quantization with GGML-compatible 256-value block encoders, built-in ``iq1_s`` / ``iq2_xs`` PTQ recipes, and unified HF and Megatron export of the packed blocks. Quantized weights must have a final dimension divisible by 256, and Megatron export requires tensor and pipeline parallel sizes of 1.
1721
- Add ``iq2_xxs`` weight-only quantization with a CUDA encoder and a ``general/ptq`` recipe, at 2.0625 bits per weight between ``iq1_s`` and ``iq2_xs``. The same 256-value block constraint applies.
22+
- Add ``iq2_s`` weight-only quantization with a CUDA encoder and a ``general/ptq`` recipe, at 2.5625 bits per weight above ``iq2_xs``. The same 256-value block constraint applies.
23+
- Add ``iq1_m`` weight-only quantization with a CUDA encoder and a ``general/ptq`` recipe, at 1.75 bits per weight between ``iq1_s`` and ``iq2_xxs``. The same 256-value block constraint applies.
1824
- A recipe can now **delegate its whole body to another recipe** with a top-level ``$import``; any top-level key given alongside it overrides the imported one. ``metadata.recipe_type`` became optional along with it: a recipe states its kind with a ``# modelopt-schema:`` comment, with ``metadata.recipe_type``, or by delegating to a recipe that does, and only a recipe that another file imports has to carry the schema comment. Whatever a recipe does state must be true: a schema comment and a ``recipe_type`` must agree, and so must a recipe and the recipe it delegates to. ``modelopt_recipes/models/`` uses this for checkpoint entries that a portable recipe already reproduces: the entry aliases that recipe instead of copying it.
1925
- Backfill the recipes behind NVIDIA's already-published checkpoints under ``modelopt_recipes/models/``, so a released checkpoint's quantization scheme is reachable from its own model-hub path rather than only from the general tier. For example, ``moonshotai/Kimi-K2.6`` (published as ``nvidia/Kimi-K2.6-NVFP4``) and ``Qwen/Qwen3.5-397B-A17B`` (published as ``nvidia/Qwen3.5-397B-A17B-NVFP4-V2``) each alias a portable recipe wholesale -- the general expert-only NVFP4 recipe and the ``qwen3_5_moe`` architecture recipe respectively -- rather than copying its body; other checkpoints follow in separate changes.
2026
- Add ``layerwise.export_dir``: layerwise calibration writes each decoder layer to its own quantized checkpoint shard as it finishes, so no separate ``export_hf_checkpoint()`` pass is needed and, with ``layerwise.checkpoint_dir``, an interrupted run resumes without redoing finished layers. Calibration writes the layer shards; ``finalize()`` on the exporter left on the model adds the tail shard, the index and the config artifacts, and the checkpoint does not load until it runs. ``examples/hf_ptq`` does this for you. Supports FP8 and NVFP4 on single-process models, resident or offloaded, including multimodal models and models with MTP layers; other formats and placements raise ``NotImplementedError`` before calibration starts.
2127
- Add support for quantizing and calibrating enabled operators outside the transformer layers, such as ``lm_head``, when using layerwise calibration.
2228
- Add an end-to-end BEVFormer ONNX PTQ example with temporal calibration data generation, INT8 and FP8 quantization, TensorRT engine building, and nuScenes accuracy evaluation. See `examples/onnx_ptq/bevformer/README.md <https://github.com/NVIDIA/Model-Optimizer/tree/main/examples/onnx_ptq/bevformer>`_ for details.
2329
- Add a reusable local-Hessian NVFP4 PTQ recipe and the quantization recipe used for ``nvidia/Qwen3.8-27B-NVFP4``.
2430

31+
*Speculative Decoding*
32+
33+
- Add the DFlash2 draft variant, selected with ``dflash_architecture_config.projector_type="dflash2"``: DFlash's one-pass parallel backbone plus a grouped dynamic convolution around every attention/MLP sublayer (``conv_kernel_size`` / ``conv_group_size``) and a low-rank candidate selector (``selector_rank`` / ``selector_top_k``, weighted by ``dflash_selector_loss_alpha``). Exported checkpoints declare ``DFlash2DraftModel`` and load in the SGLang/vLLM DFlash2 serving path.
34+
2535
*Megatron Framework (M-LM / M-Bridge)*
2636

2737
- Add an end-to-end W4A4 NVFP4 PTQ and QAD tutorial for Qwen3.6-35B-A3B also covering evaluation and vLLM throughput benchmarking. See `examples/megatron_bridge/tutorials/Qwen3.6-35B-A3B/README.md <https://github.com/NVIDIA/Model-Optimizer/tree/main/examples/megatron_bridge/tutorials/Qwen3.6-35B-A3B/>`_ for details.
@@ -72,6 +82,9 @@ Changelog
7282

7383
**Deprecations**
7484

85+
- KV-domain searches in ``examples/hf_ptq`` now use ``--kv_auto_quantize_checkpoint``;
86+
``--auto_quantize_checkpoint`` remains a deprecated fallback for a KV-primary recipe for one
87+
release.
7588
- Rename the architecture-specific recipe tier from ``modelopt_recipes/huggingface/`` to ``modelopt_recipes/model_type/`` to clarify that it holds recipes shared across every checkpoint of a Hugging Face ``model_type``. Saved ``--recipe huggingface/<model_type>/...`` paths still resolve via a backward-compatibility alias but now emit a ``FutureWarning``, so update them to ``model_type/<model_type>/...`` as the ``huggingface/`` prefix is deprecated.
7689
- The single-format quantization CLI flags are deprecated in favour of ``--recipe`` and will be removed in a future release; passing one now emits a ``FutureWarning``. ``examples/hf_ptq``: ``--qformat`` and ``--kv_cache_qformat``. ``examples/megatron_bridge/quantize.py``: ``--quant_cfg``, ``--kv_cache_quant`` and ``--weight_only``. ``examples/torch_onnx/torch_quant_to_onnx.py``: ``--qformat``. A recipe carries the quantization config, the calibration algorithm and the KV-cache setting in one file, so they cannot drift apart the way separate flags can -- and ``--recipe`` already took precedence over all six, silently on ``hf_ptq`` and with a warning on ``megatron_bridge`` -- with one gap the recipe closes rather than inherits: a weight AutoQuantize recipe that omits ``kv_cache`` still falls back to ``--kv_cache_qformat``, so set ``kv_cache`` in the recipe when migrating. Use a recipe from ``modelopt_recipes/general/ptq/``, an architecture-specific one under ``modelopt_recipes/model_type/<model_type>/``, or a checkpoint-specific one under ``modelopt_recipes/models/``. The warning fires only when a flag is passed explicitly: ``--qformat`` defaults to ``fp8`` and ``--kv_cache_qformat`` to ``fp8_cast``, so warning on the defaults would fire on every run, including runs that correctly use ``--recipe``. ``examples/speculative_decoding/scripts/quantize_drafter.py`` keeps ``--qformat`` undeprecated: it has no ``--recipe`` alternative yet.
7790
- The TensorRT-LLM checkpoint export format is deprecated and will be removed in 0.49.0: ``export_tensorrt_llm_checkpoint`` and ``torch_to_tensorrt_llm_checkpoint`` now emit a ``DeprecationWarning`` on use. Use ``export_hf_checkpoint``, which exports a unified Hugging Face checkpoint deployable on TensorRT-LLM, vLLM and SGLang. Its implementation moved to ``modelopt.torch.export.trtllm``, so import those two functions from there and the ``ModelConfig`` dataclasses from ``modelopt.torch.export.trtllm.model_config``; both functions remain importable from ``modelopt.torch.export`` for this release only.

‎README.md‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -106,14 +106,14 @@ more fine-grained control on installed dependencies or for alternative docker im
106106

107107
<div align="center">
108108

109-
| **Technique** | **Description** | **Examples** | **Docs** |
109+
| **Technique** | **Description** | **Getting started** | **Examples** |
110110
| :------------: | :------------: | :------------: | :------------: |
111-
| Post Training Quantization | Compress model size by 2x-4x, speeding up inference while preserving model quality! | \[[HF LLMs / VLMs](./examples/hf_ptq/)\] \[[Megatron-Bridge LLMs / VLMs](./examples/megatron_bridge/)\] \[[Diffusers](./examples/diffusers/)\] \[[ONNX](./examples/onnx_ptq/)\] \[[Windows](./examples/windows/)\] | \[[docs](https://nvidia.github.io/Model-Optimizer/guides/1_quantization.html)\] |
112-
| Quantization Aware Training / Distillation | Refine accuracy of quantized models even further with a few training steps! | \[[Hugging Face](./examples/llm_qat/)\] \[[Megatron-Bridge](./examples/megatron_bridge)\] | \[[docs](https://nvidia.github.io/Model-Optimizer/guides/1_quantization.html)\] |
113-
| Pruning | Reduce your model parameters or memory footprint and accelerate inference by removing unnecessary weights! | \[[General](./examples/pruning/)\] \[[Megatron-Bridge](./examples/megatron_bridge/)\] | |
114-
| Distillation | Reduce deployment model size by teaching small models to behave like larger models! | \[[Hugging Face](./examples/llm_distill/)\] \[[Megatron-Bridge](./examples/megatron_bridge/)\] \[[Megatron-LM](./examples/llm_distill/README.md#knowledge-distillation-kd-in-nvidia-megatron-lm-framework)\] | \[[docs](https://nvidia.github.io/Model-Optimizer/guides/4_distillation.html)\] |
115-
| Speculative Decoding | Train draft modules to predict extra tokens during inference! | \[[Hugging Face](./examples/speculative_decoding/)\] \[[Megatron-LM](./examples/speculative_decoding#mlm-example)\] | \[[docs](https://nvidia.github.io/Model-Optimizer/guides/5_speculative_decoding.html)\] |
116-
| Sparsity | Efficiently compress your model by storing only its non-zero parameter values and their locations | \[[Hugging Face](./examples/llm_sparsity/)\] | \[[docs](https://nvidia.github.io/Model-Optimizer/guides/6_sparsity.html)\] |
111+
| Post Training Quantization | Compress model size by 2x-4x, speeding up inference while preserving model quality! | \[[Start&nbsp;here](https://nvidia.github.io/Model-Optimizer/guides/1_quantization.html)\] | \[[HF LLMs / VLMs](./examples/hf_ptq/)\] \[[Megatron-Bridge LLMs / VLMs](./examples/megatron_bridge/README.md#post-training-quantization)\] \[[Diffusers](./examples/diffusers/)\] \[[ONNX](./examples/onnx_ptq/)\] \[[Windows](./examples/windows/)\] |
112+
| Quantization Aware Training / Distillation | Refine accuracy of quantized models even further with a few training steps! | \[[Start&nbsp;here](https://nvidia.github.io/Model-Optimizer/guides/quantization_aware_training_and_distillation.html)\] | \[[Hugging Face](./examples/llm_qat/)\] \[[Megatron-Bridge](./examples/megatron_bridge/README.md#quantization-aware-distillation-qad)\] |
113+
| Pruning | Reduce your model parameters or memory footprint and accelerate inference by removing unnecessary weights! | \[[Start&nbsp;here](./examples/pruning/README.md)\] | \[[General](./examples/pruning/)\] \[[Megatron-Bridge](./examples/megatron_bridge/README.md#pruning)\] |
114+
| Distillation | Reduce deployment model size by teaching small models to behave like larger models! | \[[Start&nbsp;here](https://nvidia.github.io/Model-Optimizer/guides/4_distillation.html)\] | \[[Hugging Face](./examples/llm_distill/)\] \[[Megatron-Bridge](./examples/megatron_bridge/README.md#distillation)\] \[[Megatron-LM](./examples/llm_distill/README.md#knowledge-distillation-kd-in-nvidia-megatron-lm-framework)\] |
115+
| Speculative Decoding | Train draft modules to predict extra tokens during inference! | \[[Start&nbsp;here](https://nvidia.github.io/Model-Optimizer/guides/5_speculative_decoding.html)\] | \[[Hugging Face](./examples/speculative_decoding/)\] \[[Megatron-LM](./examples/speculative_decoding#mlm-example)\] |
116+
| Sparsity | Efficiently compress your model by storing only its non-zero parameter values and their locations | \[[Start&nbsp;here](https://nvidia.github.io/Model-Optimizer/guides/6_sparsity.html)\] | \[[Hugging Face](./examples/llm_sparsity/)\] |
117117

118118
</div>
119119

Lines changed: 4 additions & 122 deletions
Original file line numberDiff line numberDiff line change
@@ -1,125 +1,7 @@
1-
.. _quantization-aware-training:
1+
:orphan:
22

3-
===============================================
43
Quantization-Aware Training and Distillation
5-
===============================================
4+
============================================
65

7-
Quantization-aware training (QAT) and quantization-aware distillation (QAD) recover
8-
quality lost when a model is quantized. Both train with simulated quantization
9-
enabled, so the resulting checkpoint retains its ModelOpt quantization state for
10-
deployment.
11-
12-
QAT versus QAD
13-
==============
14-
15-
QAT is standard supervised fine-tuning of a quantized model. It uses the usual
16-
cross-entropy (CE) loss against labeled data while the quantized forward pass lets
17-
the weights adapt to quantization error. Use QAT to adapt a quantized model to a
18-
task or dataset.
19-
20-
QAD uses knowledge distillation: a frozen BF16 teacher guides the quantized student
21-
with a logit-level KL-divergence loss. Use QAD after PTQ to recover accuracy lost
22-
specifically to quantization. It requires the teacher during training and therefore
23-
uses more memory and compute than QAT.
24-
25-
In both cases, start from a PTQ checkpoint and retain its quantization configuration
26-
during training. Choose QAT for task adaptation; choose QAD for quantization-accuracy
27-
recovery.
28-
29-
QAD rationale
30-
=============
31-
32-
`Quantization-Aware Distillation for NVFP4 Inference Accuracy Recovery
33-
<https://arxiv.org/abs/2601.20088>`_ recommends QAD for recovery after aggressive
34-
quantization, especially for models that have passed through multi-stage
35-
post-training such as SFT, RL, or model merging. The teacher signal makes recovery
36-
more robust when training-data quality or coverage is limited.
37-
38-
For broader background, see `How Quantization-Aware Training Enables Low-Precision
39-
Accuracy Recovery
40-
<https://developer.nvidia.com/blog/how-quantization-aware-training-enables-low-precision-accuracy-recovery/>`_. The
41-
`Nemotron 3.5 Lightning QAD blog
42-
<https://developer.nvidia.com/blog/developing-nemotron-3-5-lightning-nvfp4-with-qad-using-nvidia-model-optimizer/>`_
43-
discusses the PTQ-to-QAD-to-export workflow and its scale-handling considerations.
44-
45-
Choose a framework
46-
==================
47-
48-
ModelOpt supports QAT with Hugging Face, Megatron-Bridge, and Megatron-LM.
49-
50-
.. list-table::
51-
:header-rows: 1
52-
:widths: 20 40 40
53-
54-
* - Framework
55-
- Advantages
56-
- Trade-offs
57-
* - Hugging Face
58-
- Starts directly from Hugging Face checkpoints and is the simplest path for
59-
small to medium models. It supports FSDP2, DDP, and DeepSpeed through
60-
Accelerate, with no conversion to Megatron-Core.
61-
- Its parallelism is less efficient for large-scale training, so it is better
62-
suited to smaller models than the Megatron-based options.
63-
* - Megatron-Bridge
64-
- Automatically converts Hugging Face models to Megatron-Core and uses
65-
Megatron-LM's distributed training stack. It is a convenient scalable
66-
workflow without a separate conversion step.
67-
- The high-level workflow exposes fewer customization points than working
68-
directly in Megatron-LM.
69-
* - Megatron-LM
70-
- Provides the most control over model configuration, data, parallelism, and
71-
training behavior, making it the most customizable option for large-model
72-
training.
73-
- Requires manually converting the model to Megatron-Core and managing that
74-
checkpoint workflow.
75-
76-
Implementation guides
77-
=====================
78-
79-
Use the framework README as the executable source of truth. Each guide owns its
80-
prerequisites, commands, data preparation, distributed topology, and export options.
81-
82-
* `Hugging Face QAT/QAD Quick Start
83-
<https://github.com/NVIDIA/Model-Optimizer/tree/main/examples/llm_qat#quick-start>`_
84-
* `Megatron-Bridge README
85-
<https://github.com/NVIDIA/Model-Optimizer/tree/main/examples/megatron_bridge>`_
86-
* `Megatron-LM ModelOpt post-training documentation
87-
<https://github.com/NVIDIA/Megatron-LM/tree/main/examples/post_training/modelopt>`_
88-
89-
QAD launcher examples
90-
===================================
91-
92-
Model Optimizer includes a `launcher
93-
<https://github.com/NVIDIA/Model-Optimizer/tree/main/tools/launcher>`_ for
94-
running supported QAD pipelines as one-click commands. Follow the launcher's
95-
`Quick Start <https://github.com/NVIDIA/Model-Optimizer/tree/main/tools/launcher#quick-start>`_
96-
to set it up.
97-
98-
The `NVIDIA Nemotron 3.5 Lightning QAD launcher examples
99-
<https://github.com/NVIDIA/Model-Optimizer/tree/main/tools/launcher/examples/nvidia/NVIDIA-Nemotron-3.5-Lightning-30B-A3B-BF16>`_
100-
provide Slurm pipelines for Megatron-Bridge and Megatron-LM. Both create an NVFP4
101-
student with PTQ, distill it from the BF16 teacher, and export a deployable Hugging
102-
Face checkpoint.
103-
104-
Review the example directory's README and the selected YAML before running. Adapt
105-
the model and data locations, output paths, and Slurm topology for your environment.
106-
107-
Run the Megatron-Bridge pipeline:
108-
109-
.. code-block:: bash
110-
111-
cd tools/launcher
112-
source .env-slurm
113-
uv run launch.py \
114-
--yaml examples/nvidia/NVIDIA-Nemotron-3.5-Lightning-30B-A3B-BF16/mbridge_qad.yaml \
115-
--yes
116-
117-
Run the Megatron-LM pipeline:
118-
119-
.. code-block:: bash
120-
121-
cd tools/launcher
122-
source .env-slurm
123-
uv run launch.py \
124-
--yaml examples/nvidia/NVIDIA-Nemotron-3.5-Lightning-30B-A3B-BF16/megatron_lm_qad.yaml \
125-
--yes
6+
This guide has moved. See
7+
:doc:`quantization_aware_training_and_distillation`.

0 commit comments

Comments
 (0)