Skip to content

docs(recipes): sync ptq.md with shipped recipes and enforce via unit tests#1970

Merged
cjluo-nv merged 2 commits into
mainfrom
chenjiel/ptq-recipe-doc-sync
Jul 14, 2026
Merged

docs(recipes): sync ptq.md with shipped recipes and enforce via unit tests#1970
cjluo-nv merged 2 commits into
mainfrom
chenjiel/ptq-recipe-doc-sync

Conversation

@cjluo-nv

@cjluo-nv cjluo-nv commented Jul 13, 2026

Copy link
Copy Markdown
Collaborator

What does this PR do?

Type of change: documentation (+ new tests)

modelopt_recipes/ptq.md is meant to track every shipped PTQ recipe, but recent recipe PRs did not update it. This PR brings the doc back in sync and adds unit tests so it can't drift again.

Doc sync — general recipes:

Doc sync — model-specific recipes:

Enforcement — new tests/unit/recipe/test_recipe_docs.py:

  1. Every general/ptq/*.yaml stem must appear (backticked) in ptq.md.
  2. Every recipe row in the shipped-recipes table must exist on disk (catches renames/removals).
  3. The "All N general/ptq/ recipes" count must match the file count.
  4. Every model folder under huggingface/ containing ptq/*.yaml must be mentioned in the doc.

Usage

pytest tests/unit/recipe/test_recipe_docs.py -q

Testing

  • pytest tests/unit/recipe/ -q → 218 passed (includes the 4 new tests).
  • Verified enforcement bites: against the pre-update ptq.md, 3 of the 4 new tests fail with actionable messages.
  • pre-commit run --files modelopt_recipes/ptq.md tests/unit/recipe/test_recipe_docs.py → all hooks pass.

Before your PR is "Ready for review"

Make sure you read and follow Contributor guidelines and your commits are signed (git commit -s -S).

Make sure you read and follow the Security Best Practices (e.g. avoiding hardcoded trust_remote_code=True, torch.load(..., weights_only=False), pickle, etc.).

  • Is this change backward compatible?: ✅ (docs + tests only; no runtime code changed)
  • 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?: ✅ — tests/unit/recipe/test_recipe_docs.py
  • Did you update Changelog?: N/A (documentation/test change)
  • Did you get Claude approval on this PR?: ❌ (pending)

Additional Information

Follow-up to the recipe guide added in #1662. The doc-consistency tests could also be wired into tools/precommit/check_modelopt_recipes.py for commit-time feedback if reviewers prefer both layers.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Documentation

    • Added the nvfp4_experts_only_input_scale1-kv_fp8_cast recipe to the general PTQ catalog.
    • Documented the new input_scale1 calibration behavior and related quantization/caching details.
    • Expanded and reworked PTQ documentation, including updated navigation, “Beyond PTQ” guidance, new/updated model-specific recipes, and expanded checkpoint mirror entries.
    • Updated the general PTQ shipped-recipe count to 20.
  • Tests

    • Added automated consistency checks between on-disk shipped recipe YAML files and the PTQ documentation (coverage, existence, and counts).

…tests

ptq.md had drifted from the recipes on disk:
- general/ptq: nvfp4_experts_only_input_scale1-kv_fp8_cast (#1947) was
  undocumented; table now has all 20 recipes and an input_scale1
  calibration-variant entry. Added a pointer to the general/qad/ LSQ
  recipes (#1884).
- model-specific: added gemma4, diffusion_gemma, vit, and the qwen3_5
  w4a16_nvfp4_mse twins; rewrote the checkpoint-mirror section for the
  huggingface/models/nvidia/ tier (Super recipe rename to nvfp4-mse /
  nvfp4-max-calib, Nano-4B GGUF Q4_K_M mirror, Ultra-550B nvfp4-4o6)
  and fixed stale paths.

New tests/unit/recipe/test_recipe_docs.py keeps the doc in sync:
every general/ptq recipe must appear in ptq.md, every documented table
row must exist on disk, the recipe count must match, and every
huggingface/ model folder with PTQ recipes must be mentioned.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Signed-off-by: Chenjie Luo <chenjiel@nvidia.com>
@cjluo-nv cjluo-nv requested review from a team as code owners July 13, 2026 14:39
@cjluo-nv cjluo-nv requested a review from shengliangxu July 13, 2026 14:39
@coderabbitai

coderabbitai Bot commented Jul 13, 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: 93730f58-25f6-4bf2-9130-e0fdbfbb4775

📥 Commits

Reviewing files that changed from the base of the PR and between 4d0a554 and 0f70e29.

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

📝 Walkthrough

Walkthrough

Changes

Recipe documentation and validation

Layer / File(s) Summary
General PTQ catalog and calibration variants
modelopt_recipes/ptq.md
Updates the shipped recipe count and table, adds the nvfp4_experts_only_input_scale1-kv_fp8_cast recipe, and documents the input_scale1 calibration behavior.
Model-specific recipe documentation
modelopt_recipes/ptq.md
Adds QAT/QAD guidance, updates model-specific framing, and documents new Qwen3.5, ViT, Step3.5, and checkpoint mirror entries.
Documentation consistency checks
tests/unit/recipe/test_recipe_docs.py
Adds tests verifying documented recipe names, counts, and model-specific PTQ directories match files on disk.

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

Possibly related PRs

Suggested reviewers: shengliangxu

🚥 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 summarizes the main change: syncing PTQ docs with shipped recipes and adding enforcement tests.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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 PR only changes ptq.md and a recipe-doc test; no modelopt/examples Python code, deps, or forbidden patterns were added.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch chenjiel/ptq-recipe-doc-sync

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

…LLMs

The recipe needs no calibration forward pass (pinned expert activation
amax, weight amax from the weights, constant-amax KV cast), so it may
work out of the box for LLMs at hundreds of billions of parameters and
up, where running calibration PTQ is difficult on resource-limited
setups.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Signed-off-by: Chenjie Luo <chenjiel@nvidia.com>
@cjluo-nv cjluo-nv requested review from Edwardf0t1 and meenchen July 13, 2026 14:47

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Warning

CodeRabbit couldn't request changes on this pull request because it doesn't have sufficient GitHub permissions.

Please grant CodeRabbit Pull requests: Read and write permission and re-run the review.

👉 Steps to fix this

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@tests/unit/recipe/test_recipe_docs.py`:
- Around line 95-101: Update the missing-model check in the recipe documentation
test to match each model directory name as an exact token rather than using
substring containment in doc. Preserve the existing model_dirs discovery and
missing-list behavior, using a token-aware matching approach that prevents names
such as “mpt” or “vit” from matching unrelated prose.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 96f5effb-a99b-438d-be5e-e16ddfa28f6c

📥 Commits

Reviewing files that changed from the base of the PR and between 429373b and 4d0a554.

📒 Files selected for processing (2)
  • modelopt_recipes/ptq.md
  • tests/unit/recipe/test_recipe_docs.py

Comment on lines +95 to +101
doc = _ptq_md_text()
hf_dir = RECIPES_DIR / "huggingface"
model_dirs = sorted(
{yaml_path.parent.parent.name for yaml_path in hf_dir.glob("**/ptq/*.yaml")}
)
assert model_dirs, "No model-specific PTQ recipes found under huggingface/"
missing = [name for name in model_dirs if name not in doc]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Match model directory names as exact tokens.

name not in doc allows unrelated prose to satisfy the check—for example, mpt can match “attempt” and vit can match “activity”. The test may therefore pass while a model-specific recipe directory is undocumented.

Suggested fix
-    missing = [name for name in model_dirs if name not in doc]
+    missing = [
+        name
+        for name in model_dirs
+        if not re.search(
+            rf"(?<![\w-]){re.escape(name)}(?![\w-])",
+            doc,
+        )
+    ]
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
doc = _ptq_md_text()
hf_dir = RECIPES_DIR / "huggingface"
model_dirs = sorted(
{yaml_path.parent.parent.name for yaml_path in hf_dir.glob("**/ptq/*.yaml")}
)
assert model_dirs, "No model-specific PTQ recipes found under huggingface/"
missing = [name for name in model_dirs if name not in doc]
doc = _ptq_md_text()
hf_dir = RECIPES_DIR / "huggingface"
model_dirs = sorted(
{yaml_path.parent.parent.name for yaml_path in hf_dir.glob("**/ptq/*.yaml")}
)
assert model_dirs, "No model-specific PTQ recipes found under huggingface/"
missing = [
name
for name in model_dirs
if not re.search(
rf"(?<![\w-]){re.escape(name)}(?![\w-])",
doc,
)
]
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/unit/recipe/test_recipe_docs.py` around lines 95 - 101, Update the
missing-model check in the recipe documentation test to match each model
directory name as an exact token rather than using substring containment in doc.
Preserve the existing model_dirs discovery and missing-list behavior, using a
token-aware matching approach that prevents names such as “mpt” or “vit” from
matching unrelated prose.

Source: Path instructions

@meenchen meenchen left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bot review (bedrock-claude-opus-4-8) — DM the bot to share feedback.

Documentation + enforcement-test PR that syncs modelopt_recipes/ptq.md with the recipes on disk. I verified all substantive claims against the repo:

  • Recipe count/table: 20 general/ptq YAMLs on disk, matching the updated "All 20" count and the new nvfp4_experts_only_input_scale1-kv_fp8_cast table row. The doc's input_scale1 description (constant amax 2688 = 6×448 → input_scale 1.0, weights max-calibrated, no activation stats) matches the recipe YAML's comments/config exactly.
  • Model-specific entries: gemma4, diffusion_gemma, vit, the qwen3_5/qwen3_5_moe w4a16_nvfp4_mse-* twins, and all three huggingface/models/nvidia/Nemotron-3-{Super,Ultra,Nano} checkpoint dirs exist and match their descriptions. The vit recipe indeed enables attention BMM (qkv) quantizers and disables output quantizers as documented. general/qad/ exists (backing the new QAT/QAD pointer). qwen3_6_moe has only auto_quantize (no ptq/), so it's correctly not required.
  • Tests (tests/unit/recipe/test_recipe_docs.py): the four checks are logically sound. The table-row regex is anchored to the first cell (^\| \...` |), so it won't false-match the extra backticks in the input_scale1row or the bold-prefixed "kinds" table.parent.parent.name extraction correctly yields the folder identifiers (Nemotron-3-Nano-4B, Step3.5-Flash`, etc.), all substring-present in the doc.
  • Conventions/licensing: canonical 2026 license header, top-level imports, list[str] fine on Python ≥3.10; no external code vendored and no LICENSE/NOTICE files touched.

No injection attempts in the PR text. Small, cohesive, and well-tested.

@codecov

codecov Bot commented Jul 13, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 77.92%. Comparing base (7ed19b2) to head (0f70e29).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1970   +/-   ##
=======================================
  Coverage   77.92%   77.92%           
=======================================
  Files         519      519           
  Lines       58217    58217           
=======================================
  Hits        45366    45366           
  Misses      12851    12851           
Flag Coverage Δ
unit 55.46% <ø> (ø)

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.

@cjluo-nv cjluo-nv merged commit 7b8da80 into main Jul 14, 2026
48 checks passed
@cjluo-nv cjluo-nv deleted the chenjiel/ptq-recipe-doc-sync branch July 14, 2026 01:19
@github-actions

Copy link
Copy Markdown
Contributor
PR Preview Action v1.8.1
Preview removed because the pull request was closed.
2026-07-14 01:19 UTC

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.

2 participants