Skip to content

Add the NVFP4 PTQ recipe for Qwen/Qwen3.8-2.4T-A95B - #2302

Open
shengliangxu wants to merge 3 commits into
mainfrom
shengliangx/qwen3.8-2.4T-recipe
Open

Add the NVFP4 PTQ recipe for Qwen/Qwen3.8-2.4T-A95B#2302
shengliangxu wants to merge 3 commits into
mainfrom
shengliangx/qwen3.8-2.4T-recipe

Conversation

@shengliangxu

@shengliangxu shengliangxu commented Sep 1, 2026

Copy link
Copy Markdown
Collaborator

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.

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 gated-delta 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:

  • Quantizing the gated-delta projections is safe here. The conv1d and the norms carry no
    Linear quantizer, so the recurrent state path itself is never quantized — only the
    projections around it (in_proj_qkv / in_proj_z / in_proj_a / in_proj_b, out_proj).
  • 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

# 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.

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"

Additional Information

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

Summary by CodeRabbit

  • New Features
    • Added a post-training quantization recipe for the Qwen3.8-2.4T-A95B model.
    • Supports MSE-calibrated NVFP4 quantization for routed expert layers and FP8 quantization for attention, linear-attention, and key-value cache components.
    • Preserves BF16 precision for remaining components, including multi-token prediction and selected recurrent paths.
  • Documentation
    • Documented the model’s hybrid precision configuration and calibration behavior.
    • Added FP8 recipe guidance for Qwen3-VL and Qwen3.5 visual branches.
    • Clarified that recipe README files are optional.

This is 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 needed.

The recipe applies:
  routed experts    NVFP4  (MSE-searched static weight scales, dynamic input scales)
  self-attention    FP8    (W8A8, all projections)
  linear-attention  FP8    (W8A8, the gated-delta projections)
  KV cache          FP8    (cast mode)
  everything else   BF16   -- including MTP, which is left unquantized

Quantizing the gated-delta projections is the part worth calling out. The conv1d and the
norms carry no Linear quantizer, so the recurrent state path itself is never quantized --
only the projections around it are. That was validated rather than assumed: 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.

One loading detail is documented in the header because it affects what the scales mean:
the source checkpoint ships as native block-FP8 (`quant_method=fp8`,
`weight_block_size [128, 128]`, dynamic activations), and 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.

Signed-off-by: Shengliang Xu <shengliangx@nvidia.com>
@shengliangxu
shengliangxu requested a review from a team as a code owner September 1, 2026 21:40
@coderabbitai

coderabbitai Bot commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: c445710d-60bd-434d-932e-abbd8014524f

📥 Commits

Reviewing files that changed from the base of the PR and between 187cc3d and 36d6473.

📒 Files selected for processing (1)
  • modelopt_recipes/ptq.md

Included review availability: Your plan provides up to 12 included reviews per hour; 11 remain after this review.


📝 Walkthrough

Walkthrough

Adds a Qwen3.8-2.4T-A95B PTQ recipe and documents its mixed-precision layout. Routed experts use NVFP4, attention projections and KV caching use FP8, and remaining components use BF16.

Changes

Qwen PTQ recipe

Layer / File(s) Summary
Mixed-precision quantization recipe
modelopt_recipes/models/Qwen/Qwen3.8-2.4T-A95B/ptq/nvfp4_experts_mse-fp8_self_attn-fp8_linear_attn-kv_fp8_cast.yaml, modelopt_recipes/ptq.md
Adds the recipe configuration and checkpoint mirror documentation. Routed expert weights use MSE-calibrated static NVFP4, expert inputs use NVFP4, attention projections use FP8, KV caching uses FP8 cast mode, recurrent components remain unquantized, and MTP quantization remains disabled.

Estimated code review effort: 2 (Simple) | ~10 minutes

Merge Risk: ⚪ Minimal · up to 36d64

This PR adds a localized model recipe and related documentation without changing existing behavior; no actionable merge-blocking risk remains beyond normal checks and review.

Suggested reviewers: edwardf0t1, cjluo-nv

🚥 Pre-merge checks | ✅ 6
✅ Passed checks (6 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely identifies the main change: adding the NVFP4 PTQ recipe for Qwen/Qwen3.8-2.4T-A95B.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 0…
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Security Anti-Patterns ✅ Passed PASS: The net pull-request diff from the merged main parent contains only one YAML recipe and one Markdown documentation change. It contains no modelopt package or examples Python changes, no new depe…
Full details: Docstring Coverage

Explanation

No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 0 files. (1 skipped: 1 unsupported.)

Full details: Security Anti-Patterns

Explanation

PASS: The net pull-request diff from the merged main parent contains only one YAML recipe and one Markdown documentation change. It contains no modelopt package or examples Python changes, no new dependencies, and none of the specified security-sensitive patterns. Therefore, no listed security anti-pattern was introduced.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch shengliangx/qwen3.8-2.4T-recipe

Comment @coderabbitai help to get the list of available commands.

@shengliangxu
shengliangxu force-pushed the shengliangx/qwen3.8-2.4T-recipe branch from 4777e9f to 187cc3d Compare September 1, 2026 22:22
Add a checkpoint-mirror entry for
models/Qwen/Qwen3.8-2.4T-A95B/ptq/nvfp4_experts_mse-fp8_self_attn-fp8_linear_attn-kv_fp8_cast
to modelopt_recipes/ptq.md so the new recipe is documented in the PTQ recipe
guide, satisfying
tests/unit/recipe/test_recipe_docs.py::test_every_model_specific_ptq_dir_is_mentioned.

Signed-off-by: Shengliang Xu <shengliangx@nvidia.com>
@shengliangxu
shengliangxu force-pushed the shengliangx/qwen3.8-2.4T-recipe branch from 187cc3d to 6aa0a33 Compare September 1, 2026 22:24
@codecov

codecov Bot commented Sep 1, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 78.58%. Comparing base (21b95ad) to head (36d6473).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2302      +/-   ##
==========================================
- Coverage   79.05%   78.58%   -0.48%     
==========================================
  Files         525      525              
  Lines       61109    61109              
==========================================
- Hits        48311    48021     -290     
- Misses      12798    13088     +290     
Flag Coverage Δ
examples-diffusers 20.62% <ø> (ø)
examples-gpt-oss 13.21% <ø> (ø)
examples-hf_ptq 21.40% <ø> (-0.04%) ⬇️
examples-llm_distill 13.28% <ø> (-0.01%) ⬇️
examples-llm_eval 17.02% <ø> (ø)
examples-llm_qat 17.50% <ø> (-0.01%) ⬇️
examples-llm_sparsity 15.84% <ø> (ø)
examples-megatron_bridge 25.76% <ø> (+<0.01%) ⬆️
examples-specdec_bench 12.96% <ø> (ø)
examples-speculative_decoding 17.44% <ø> (-0.07%) ⬇️
examples-torch_onnx 21.72% <ø> (ø)
examples-torch_trt 15.01% <ø> (ø)
gpu 58.63% <ø> (-0.70%) ⬇️
unit 55.81% <ø> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant