Shengliang Xu 3f4b95e8a4 Add the NVFP4 PTQ recipe for Qwen/Qwen3.8-2.4T-A95B (#2302)
### What does this PR do?

Type of change: new feature (model recipe)

Adds the NVFP4 PTQ recipe for **Qwen/Qwen3.8-2.4T-A95B** — the recipe
used to produce

[**nvidia/Qwen3.8-2.4T-A95B-NVFP4**](https://huggingface.co/nvidia/Qwen3.8-2.4T-A95B-NVFP4).

Qwen/Qwen3.8-2.4T-A95B is a `qwen3_5_moe_text` MoE: 92 layers, 512
routed experts (top-10)
plus a shared expert, with **hybrid attention** — gated-delta
(linear-attention) layers
interleaved with full-attention layers. It is transformers-native from
>= 5.9 and its config
ships `base_model_ep_plan`, so no ModelOpt plugin is required.

The recipe applies:

| component | precision |
|---|---|
| routed experts | NVFP4 (MSE-searched static weight scales, dynamic
input scales) |
| self-attention | FP8 (W8A8, all projections) |
| linear-attention | FP8 (W8A8, the full gated-delta path — `conv1d` +
all in/out projections) |
| KV cache | FP8 (cast mode) |
| everything else | BF16 — including MTP, left unquantized |

Two things are documented in the file header because they affect how the
recipe should be
read:

- **The full gated-delta path is FP8, and that was validated
end-to-end.** The `conv1d` and
the in/out projections (`in_proj_qkv` / `in_proj_z` / `in_proj_a` /
`in_proj_b`, `out_proj`)
are all FP8; only the norms stay BF16. `nn.Conv1d` is a registered
ModelOpt quant module, so
the recipe's broad `*linear_attn*` rules reach `linear_attn.conv1d` too
— this is intentional
and matches the published `nvidia/Qwen3.8-2.4T-A95B-NVFP4`, whose
`hf_quant_config.json` lists
`linear_attn.conv1d` as FP8 on every gated-delta layer (the interleaved
full-attention layers
have no `conv1d`). (An earlier revision of the file header / ptq.md
wrongly stated the
  recurrent path is never quantized; corrected in this PR.)
- **The source ships as native block-FP8** (`quant_method=fp8`,
`weight_block_size [128,128]`,
dynamic activations). The loader dequantizes it to BF16 before
quantizers are inserted, so
the calibrated scales are against BF16 weights, not against the shipped
FP8.

Filed under `modelopt_recipes/models/` per the split introduced in #2219
(per-`model_type`
recipes vs model-hub checkpoint recipes); this one targets a published
checkpoint, alongside
`deepseek-ai/DeepSeek-V4-Pro-0813` and the Nemotron-3 entries.

### Usage

```bash
# The recipe is consumed by the PTQ entrypoint the same way as the other
# modelopt_recipes/models/ entries:
python examples/hf_ptq/hf_ptq.py \
    --pyt_ckpt_path <Qwen/Qwen3.8-2.4T-A95B checkpoint> \
    --recipe models/Qwen/Qwen3.8-2.4T-A95B/ptq/nvfp4_experts_mse-fp8_self_attn-fp8_linear_attn-kv_fp8_cast \
    --export_path <output>
```

### Testing

The exported checkpoint was evaluated against the BF16 baseline on
**GPQA, AA-LCR, SciCode,
IFBench and Terminal-Bench 2.1**, with no meaningful accuracy regression
on any of them. The
published `nvidia/Qwen3.8-2.4T-A95B-NVFP4` checkpoint is the artifact
this recipe produces —
its `hf_quant_config.json` is the ground truth for which modules are
quantized (routed experts
NVFP4; self-attention, all linear-attention projections **and**
`conv1d`, and KV cache FP8).

No new unit tests: this is a declarative recipe composed entirely of
existing units
(`base_disable_all`, `nvfp4`, `nvfp4_static`, `fp8`, `kv_fp8_cast`), all
already covered.

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

- Is this change backward compatible?: ✅ (new file only; no existing
behaviour touched)
- 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?: N/A — declarative recipe over
existing, tested units
- Did you update
[Changelog](https://github.com/NVIDIA/Model-Optimizer/blob/main/CHANGELOG.rst)?:
N/A — consistent with the recent recipe additions (#2219, #2269, #2287),
which did not add entries
- Did you get Claude approval on this PR?: ❌ — not yet run

### Additional Information

Model card: https://huggingface.co/nvidia/Qwen3.8-2.4T-A95B-NVFP4


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

* **New Features**
* Added a post-training quantization recipe for the Qwen3.8-2.4T-A95B
model.
* Supports MSE-searched NVFP4 quantization for routed expert layers and
FP8 quantization across self-attention and gated-delta linear-attention
paths.
* Supports FP8 cast-mode key-value caching while retaining BF16
precision for multi-token prediction and gated-delta normalization
layers.

* **Documentation**
* Clarified the model’s hybrid precision configuration, including FP8
treatment of the gated-delta convolution path and the scope of broad
linear-attention patterns.
  * Documented source-checkpoint dequantization and validation behavior.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Signed-off-by: Shengliang Xu <shengliangx@nvidia.com>
2026-09-08 16:41:01 -07: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%