Chenjie LuoandClaude Opus 5.5 a3a487f415 Calibrate the GGML IQ2 experts-only recipes with local_hessian instead of imatrix (#3274)
### What does this PR do?

Type of change: new feature (changes the default calibration of three
built-in recipes)

The three GGML IQ2 experts-only recipes, `iq2_xxs_experts_only`,
`iq2_xs_experts_only` and `iq2_s_experts_only`, now calibrate with
`local_hessian` (#3158) instead of imatrix. The IQ1 experts-only
recipes, `iq1_s_experts_only` and `iq1_m_experts_only`, keep imatrix,
which scored higher at IQ1 (see below).

Both encode each expert weight once from one calibration forward pass,
need no layerwise calibration, and pin the codes. local_hessian picks
each group's local scale by the layer-output error under the 256-column
Hessian of the tokens routed to that expert. imatrix picks it by the
squared error weighted by `sqrt(E[x²])`, llama.cpp's statistic.

Only the algorithm changes; the quantized weights (`*.experts.*`,
`*block_sparse_moe*`) stay the same. The full `<format>` recipes keep
GPTQ followed by imatrix: GPTQ already encodes every weight there, and
AutoQuantize accepts only `max` alongside GPTQ.

**Accuracy.** SciCode subtask accuracy (%), imatrix → local_hessian, IQ2
formats, 8 runs per arm. Settings: 1,024 calibration samples, INT8
fake-quant serving (BF16 for Flash-Next), 64K token cap. Each ± is one
standard error of the difference over the 8 runs per arm, not a 95%
interval; |z| > 2 counts as significant. From #3158:

| Model (quantized weights) | IQ2_XXS | IQ2_XS | IQ2_S |
|---|---|---|---|
| GLM-5.3-Flash (all routed experts, as these recipes) | 3.9 → 9.9
(**+6.0 ± 0.5**) | 12.5 → 18.3 (**+5.8 ± 0.5**) | 31.2 → 30.7 (−0.5 ±
0.6) |
| Qwen3.8-Flash-Next (routed experts' `gate_up`) | 38.4 → 37.2 (−1.2 ±
0.9) | 40.2 → 39.1 (−1.1 ± 1.1) | 41.9 → 42.7 (+0.8 ± 0.8) |
| Qwen3.8-27B (dense MLP, for the method) | 9.5 → 16.0 (**+6.5 ± 0.8**)
| 20.6 → 26.5 (**+5.9 ± 1.0**) | 32.0 → 34.0 (+2.0 ± 1.1) |

- **IQ2_S:** no significant gain on any model, at the same calibration
cost as IQ2_XXS. It switches for consistency with the other IQ2 recipes;
a follow-up PR that derives the super-block scale `d` is expected to
make local_hessian better at IQ2_S.
- **Never significantly worse than imatrix.** It is clearly better at
IQ2_XXS and IQ2_XS on GLM and 27B, mostly through fewer runaway
repetition loops. Flash-Next never loops under either and ties.
- **GLM arm:** quantized exactly the weights these recipes quantize.
- **Truncation:** 10–51% of generations per arm hit the 64K cap, so read
these as relative comparisons under identical settings.
- **Doom-loop detector:** on for both GLM arms and off for the Qwen arms
at IQ2, the same within each model.

**Why IQ1 keeps imatrix.** The same comparison at IQ1, run on `main`
with the doom-loop detector on for every arm (`repetition_detection`
256/32/3):

| Model (quantized weights) | IQ1_S SciCode, imatrix → local_hessian |
IQ1_M SciCode, imatrix → local_hessian | KL vs BF16, IQ1_S / IQ1_M,
imatrix → local_hessian |
|---|---|---|---|
| Qwen3.8-Flash-Next (routed experts' `gate_up`) | 8.96 → 3.03 (**−5.9 ±
0.6**) | 20.08 → 12.06 (**−8.0 ± 0.9**) | 0.543 → 0.597 / 0.447 → 0.473
|
| GLM-5.3-Flash (all routed experts) | 0.0 → 0.0 (1 run each) | 0.0 →
0.0 (1 run each) | 1.495 → 1.537 / 1.253 → 1.300 |
| Qwen3.8-27B (dense MLP) | 0.0 → 0.0 (1 run each) | 1.74 → 1.74 (±0.16)
| 1.107 → 1.157 / 0.624 → 0.683 |

- **Flash-Next is worse with local_hessian:** it is the only model that
stays usable at IQ1, and local_hessian scores lower at both formats. It
does not loop more; its answers are worse.
- **KL agrees:** local_hessian's KL is higher in all six IQ1 pairs.
- **Damping is not the cause:** on Flash-Next IQ1_M, `perc_damp` 1, 3
and 10 give KL 0.471, 0.474 and 0.467, all still above imatrix's 0.447.
- **Working hypothesis:** at IQ1's coarse grid, imatrix's
`sqrt(E[x²])`-weighted squared error is a better proxy for the network's
output than the exact layer-output error local_hessian minimizes.

**Cost.** Calibration on `main` (914e9abcb4, with the fused
choice-search kernel #3218): IQ2_XXS, 1,024 × 512 samples, batch 16, 4×
GB300, CUDA extension compiled ahead. Time is `mtq.quantize`, including
the calibration forward pass. Memory is the peak above the loaded model,
summed over GPUs.

| Model, quantized weights | Time, imatrix → local_hessian | GPU memory,
imatrix → local_hessian |
|---|---|---|
| GLM-5.3-Flash, all routed experts (this recipe's weights) | 494 s →
1,229 s (2.5×) | 207 → 279 GiB (+72 GiB, ≈18 GiB/GPU) |
| Qwen3.8-Flash-Next, routed experts' `gate_up` | 302 s → 674 s (2.2×) |
21 → 70 GiB on 2 GPUs (+49 GiB) |

- **Extra memory:** the Hessians, `in_features` KiB per expert weight,
held on the GPU until that weight is encoded. They match the estimate
from the model configs: 71 GiB for GLM.
- **Host memory:** unchanged, about 5.5 GiB RSS.
- **Flash-Next with the shipped recipe:** it fails before calibrating,
with imatrix on `main` as well as with this change. The recipe also
quantizes the experts' `down_proj`, whose 640-wide input is not a
multiple of IQ2's 256-column block. That's why the Flash-Next arms above
quantized `gate_up` only.
- **When the Hessians don't fit:** override the algorithm with `{method:
imatrix}`, as `ptq.md` now says. Layerwise calibration holds one layer's
Hessians at a time, but it is not a memory fallback here. On
GLM-5.3-Flash at batch 16 with `layerwise: {enable: true}`,
local_hessian calibrated all 45 layers in 2,028 s, 1.65× slower. Its
peak GPU memory above the model was 422 GiB, against 279 GiB without
layerwise, because layerwise's own activation caching outweighs the
Hessians it saves.

### Usage

```bash
python examples/hf_ptq/hf_ptq.py --pyt_ckpt_path <MoE model> --recipe general/ptq/iq2_xxs_experts_only ...
```

To keep imatrix, override the algorithm with `algorithm: {method:
imatrix}`.

### Testing

- `tests/unit/recipe/test_presets.py`: the experts-only recipe test now
expects `local_hessian` for the three IQ2 formats and imatrix for the
two IQ1 formats.
- `tests/unit/torch/quantization/test_ggml_imatrix.py`:
- The per-expert imatrix test now sets `algorithm: imatrix` on the
recipe's quantizers, keeping its coverage of imatrix.
- The fused-expert HF export test runs the recipe's quantizers with both
imatrix and local_hessian, which pin differently: imatrix without a
source fingerprint, local_hessian with one.
- On GB200 (oci-jhb), in the calibration container:
- `tests/unit/recipe`, `test_ggml_imatrix.py`, `test_ggml_gptq.py`,
`test_local_hessian.py`: 657 passed.
  - `test_local_hessian_gpu.py`, `test_ggml_imatrix_gpu.py`: 12 passed.
- The GGML/experts case of `tests/gpu/torch/export/test_export.py`: 1
passed.
- After the review fixes, with the fused-expert HF export test run for
both imatrix and local_hessian: `tests/unit/recipe`,
`test_ggml_imatrix.py`, `test_local_hessian.py`, `test_ggml_gptq.py`:
663 passed.
- The end-to-end runs in the tables above. IQ1 run IDs and recipes are
in the campaign workspace; the IQ1 SciCode runs used 8 runs per arm
except where marked.

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

- Is this change backward compatible?: ✅ The recipes are new in 0.49.0,
and existing configs and checkpoints are unaffected.
- 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?: ✅ (updated the existing recipe
tests)
- Did you update
[Changelog](https://github.com/NVIDIA/Model-Optimizer/blob/main/CHANGELOG.rst)?:
✅ (the 0.49.0 entries that introduced these recipes now say which
recipes use which algorithm)
- Did you get Claude approval on this PR?: ❌ (pending)

### Additional Information

Follows the GGML local-Hessian series: #3158, #3159, #3209, #3218.

🤖 Generated with [Claude Code](https://claude.com/claude-code)


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

<!-- coderabbit-ai-generated:v1 -->

## Summary by CodeRabbit

- **New Features**
- IQ2 experts-only quantization recipes now use local-Hessian
calibration. IQ1 recipes continue to use imatrix calibration.
- Added guidance on GPU memory requirements for IQ2 calibration and an
imatrix fallback when expert Hessians do not fit.
- Expanded quantization changelog coverage for weighted imatrix
calibration and AutoQuantize support for GGML formats.

- **Documentation**
- Updated calibration guidance, including recommendations for layerwise
calibration and batch size 1 during amax search.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Signed-off-by: Chenjie Luo <chenjiel@nvidia.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-12 12:48:46 -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 Getting started Examples
Post Training Quantization Compress model size by 2x-4x, speeding up inference while preserving model quality! [Start here] [HF LLMs / VLMs] [Megatron-Bridge LLMs / VLMs] [Diffusers] [ONNX] [Windows]
Quantization Aware Training / Distillation Refine accuracy of quantized models even further with a few training steps! [Start here] [Hugging Face] [Megatron-Bridge]
Pruning Reduce your model parameters or memory footprint and accelerate inference by removing unnecessary weights! [Start here] [General] [Megatron-Bridge]
Distillation Reduce deployment model size by teaching small models to behave like larger models! [Start here] [Hugging Face] [Megatron-Bridge] [Megatron-LM]
Speculative Decoding Train draft modules to predict extra tokens during inference! [Start here] [Hugging Face] [Megatron-LM]
Sparsity Efficiently compress your model by storing only its non-zero parameter values and their locations [Start here] [Hugging Face]

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