Skip to content
Machine Learning
Skill

/modelopt-ptq

Use when the user asks to "quantize a model", "run PTQ", "post-training quantization", "NVFP4 quantization", "FP8 quantization", "INT8 quantization", "INT4 AWQ", "quantize LLM", "quantize MoE", "quantize VLM", or needs to produce a quantized HuggingFace checkpoint from a

From plugin
modelopt
5.6k31 skills6 agents

Claude Code

$ npx -y skills add nvidia/model-optimizer --skill modelopt-ptq --agent claude-code

SKILL.md

modelopt-ptq.SKILL.md
name: modelopt-ptq
description: >-
  Use when the user asks to "quantize a model", "run PTQ", "post-training
  quantization", "NVFP4 quantization", "FP8 quantization", "INT8
  quantization", "INT4 AWQ", "quantize LLM", "quantize MoE", "quantize VLM",
  or needs to produce a quantized HuggingFace checkpoint from a pretrained
  model using ModelOpt. Do NOT use for multi-candidate recipe
  exploration or optimization (use modelopt-quant-recipe-search).

ModelOpt Post-Training Quantization

Produce a quantized checkpoint from a pretrained model. **Read `examples/hf_ptq/README.md` first** — it has the support matrix, CLI flags, and accuracy guidance.

Use `modelopt-quant-recipe-search` for multi-candidate recipe exploration or optimization. Use this skill for each selected recipe's PTQ run.

Step 1 — Environment

Use the common skill's `environment-setup.md` and `workspace-management.md`. After completing them you should know:

  • ModelOpt source is available
  • Local or remote (+ cluster config if remote)
  • SLURM / Docker+GPU / bare GPU
  • Launcher available?
  • Which workspace to use

Step 2 — Is the model supported?

Check the support table in `examples/hf_ptq/README.md` for verified HF models.

  • **Listed** → supported, use `hf_ptq.py` (step 4A/4B)
  • **Not listed** → read `references/unsupported-models.md` to determine if `hf_ptq.py` can still work or if a custom script is needed (step 4C)

Step 2.5 — Check for model-specific dependencies

If the model uses `trust_remote_code` (check `config.json` for `auto_map`), inspect its custom Python files for imports not present in the container:

grep -h "^from \|^import " <model_path>/modeling_*.py | sort -u

**Known dependency patterns:**

| Import found | Packages to install | | --- | --- | | `from mamba_ssm` / `from causal_conv1d` | `mamba-ssm causal-conv1d` (Mamba/hybrid models: NemotronH, Jamba) |

If extra deps are needed:

  • **Launcher (4B)**: set `EXTRA_PIP_DEPS` in the task's `environment` section — `ptq.sh` installs them automatically
  • **Manual (4A)**: `unset PIP_CONSTRAINT && pip install <deps>` before running `hf_ptq.py`

Step 3 — Choose quantization format

**First**, check for a model-specific recipe:

ls modelopt_recipes/models/ 2>/dev/null
ls modelopt_recipes/model_type/<model_type>/ptq/ 2>/dev/null  # per-arch; <model_type> from local config.json (Hub ID: AutoConfig.from_pretrained)

If a model-specific recipe exists, prefer `--recipe <path>` — but **inspect its include/exclude patterns** rather than assuming (e.g. for VLMs, confirm the vision tower is actually excluded).

**If no model-specific recipe**, choose a format based on GPU (details in `examples/hf_ptq/README.md`):

  • **Blackwell** (B100/B200/GB200): `nvfp4` variants
  • **Hopper** (H100/H200) or older: `fp8` or `int4_awq`

Use `--qformat <name>` (e.g., `--qformat nvfp4`). Format definitions: `modelopt/torch/quantization/config.py`. General PTQ recipes in `modelopt_recipes/general/ptq/` correspond to the same formats — `--qformat` is the simpler way to use them.

Before running PTQ, sanity-check the selected qformat/recipe against the model structure. Inspect the recipe's include/exclude patterns and summarize which layer groups will be quantized and approximately how many modules/layers match (attention projections, MLP projections, experts, etc.). If the match count is 0, or far smaller than expected for the model, stop and fix the recipe or ask the user before launching calibration.

**VLMs:** generic `*mlp*`/`*experts*` recipes also match the vision tower (`model.visual.*`); quantizing the ViT silently breaks image benchmarks. Use the `model_type/<model_type>/ptq/` recipe or add `*visual*`/`*vision_tower*` excludes, then verify in Step 5 — see `references/checkpoint-validation.md`.

If the source checkpoint is already quantized and the requested recipe/config reduces quantization coverage, confirm that intent with the user before running. For example, if an FP8 checkpoint is used as input and the recipe excludes some layers so they would fall back to BF16 instead of staying quantized, call out the affected layer groups and ask whether that FP8-to-BF16 fallback is intended.

> NVFP4 can be calibrated on Hopper but requires Blackwell for inference.

Step 4 — Run PTQ

**Goal: checkpoint on disk** (`.safetensors` + `config.json`).

For **listed models** (4A/4B): run full calibration directly (`--calib_size 512`). For **unlisted models** (4C): run a smoke test first (`--calib_size 4`), wait for success, then full calibration.

Recommended calibration datasets

  • **Text-only LLM PTQ:** Prefer the representative `nemotron-post-training-v3` blend. `modelopt/torch/utils/dataset_utils.py` expands it to seven registered Nemotron SFT domains. Configure Hugging Face credentials where required.
  python examples/hf_ptq/hf_ptq.py ... \
      --dataset nemotron-post-training-v3
  • **VLM PTQ:** Include image-text calibration with `--calib_with_images`. This path uses `nemotron_vlm_dataset_v2` with the current default subsets `sparsetables`, `plotqa_cot`, and `wiki_en`; `examples/hf_ptq/hf_ptq.py` and `modelopt/torch/utils/vlm_dataset_utils.py` are the source of truth.
  python examples/hf_ptq/hf_ptq.py ... \
      --calib_with_images

`--dataset` selects text-only calibration and cannot substitute for multimodal examples. Use `--dataset cnn_dailymail` only as a fallback when representative data is unavailable, such as without gated-data access or with only a local public cache.

Which path?

In README table? ─→ YES ──→ SLURM (local or remote)? ──→ LAUNCHER (4B)
                  │          Local Docker + GPU? ────────→ LAUNCHER (4B)
                  │          Remote Docker (no SLURM)? ──→ MANUAL (4A)
                  │          Bare GPU (local or remote)? → MANUAL (4A)
                  │
                  └→ NOT LISTED ──→ UNLISTED MODEL (4C)

4A — Direct: supported model, manual

Read more
@nvidia
Ships withmodelopt

Documentation | Roadmap | 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

5.6k31 skills6 agents
Get the whole plugin

Stars on GitHub

Momentum

stars in total
5.6k
Star history of nvidia/model-optimizer on GitHub, a chart by star-history.com

Other skills on modelopt.

accessing-mlflow

accessing-mlflow

Compatibility name for modelopt-accessing-mlflow. Browse ModelOpt evaluation runs and artifacts in MLflow.

@nvidia@nvidiaInstall Skill
benchmark-model-kernels

benchmark-model-kernel…

Compatibility name for modelopt-benchmark-model-kernels. Inspect model shapes and benchmark GEMM or fused-MoE kernels.

@nvidia@nvidiaInstall Skill
common

common

Shared ModelOpt support files. Use only when another ModelOpt skill directs you here.

@nvidia@nvidiaInstall Skill
compare-results

compare-results

Compatibility name for modelopt-compare-results. Compare baseline and quantized evaluation results.

@nvidia@nvidiaInstall Skill
day0-release

day0-release

Compatibility name for modelopt-day0-release. Run the full ModelOpt day-0 quantization and validation workflow.

@nvidia@nvidiaInstall Skill
debug

debug

Compatibility name for modelopt-debug. Run commands through the remote Docker debugger relay.

@nvidia@nvidiaInstall Skill

More skills from other plugins.

analyze-ci

analyze-ci

Analyze failed GitHub Action jobs. Takes one or more GitHub URLs (job, workflow-run, or PR) and summarizes each failure with root…

mlflow4d29k
@mlflow@mlflowInstall Skill
hf-cli

hf-cli

Hugging Face Hub CLI (`hf`) for downloading, uploading, and managing models, datasets, spaces, buckets, repos, papers, jobs, and…

skills2w11k
@huggingface@huggingfaceInstall Skill
feast-architecture

feast-architecture

Internals of the Feast codebase — how each component works, where the key abstractions live, and the data flow through the…

feast8d7.4k
@feast-dev@feast-devInstall Skill
add-ecosystem

add-ecosystem

Add a new ecosystem and base model to basemodel.constants.ts. Use when onboarding a new model family from providers like Baidu,…

civitai5d7.3k
@civitai@civitaiInstall Skill

Questions about modelopt-ptq.

Which coding agents can use modelopt-ptq?
modelopt-ptq installs in Claude Code, Codex, Cursor, Gemini CLI, GitHub Copilot, OpenCode and Windsurf with the skills CLI, using each agent's flag shown on this page. Flowy's auto-invocation, which fires a skill when your prompt matches, runs in Claude Code only.