Skip to content

[6466805] Add Dynamo ONNX export support for quantized models - #2321

Draft
ajrasane wants to merge 1 commit into
mainfrom
fix/dynamo-onnx-export
Draft

[6466805] Add Dynamo ONNX export support for quantized models#2321
ajrasane wants to merge 1 commit into
mainfrom
fix/dynamo-onnx-export

Conversation

@ajrasane

@ajrasane ajrasane commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

Type of change: new feature

  • Adds Dynamo ONNX export support for FP8, INT8, INT4 AWQ, MXFP8, NVFP4, and mixed AutoQuant models with ONNX opset 21 or newer.
  • Emits quantization nodes directly during normal Dynamo capture and provides get_dynamo_onnx_translation_table() for strict capture.
  • Integrates strict translations and block-weight postprocessing into the ModelOpt ONNX helper.
  • Preserves the legacy TorchScript exporter and existing defaults.
  • Adds CLI options, documentation, changelog coverage, and CPU/GPU regression tests.

Usage

import torch

from modelopt.torch._deploy.utils import get_onnx_bytes_and_metadata
from modelopt.torch.quantization.export_onnx import get_dynamo_onnx_translation_table

onnx_bytes, metadata = get_onnx_bytes_and_metadata(
    model,
    (sample_input,),
    dynamo_export=True,
    onnx_opset=24,
)

exported_program = torch.export.export(model, (sample_input,), strict=True)
torch.onnx.export(
    exported_program,
    (),
    "model.onnx",
    dynamo=True,
    opset_version=24,
    custom_translation_table=get_dynamo_onnx_translation_table(),
)

Testing

  • CUDA-hidden unit coverage passed across supported PyTorch 2.8–2.13 environments.
  • Final MXFP8 metadata regression passed on PyTorch 2.8 and 2.13.
  • GPU Dynamo exports passed for FP8, INT8, and MXFP8.
  • NVFP4 opset 21/24 exports and TensorRT builds passed on Blackwell.
  • The FP8 CLI smoke passed with --dynamo_export --onnx_opset=24 --trt_build.
  • All changed-file pre-commit hooks and git diff --check passed.

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?: ✅ — Dynamo export is opt-in; existing exporter and opset defaults are unchanged.
  • 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?: ✅
  • Did you update Changelog?: ✅

🤖 Generated by Codex (AI agent).

Add export-safe quantization paths and ONNXScript translations for FP8, INT8, INT4 AWQ, MXFP8, and NVFP4.

Wire Dynamo export through the ModelOpt helper and example workflows, including strict capture and block-weight postprocessing, while preserving the legacy exporter defaults.

Add CPU, GPU, and end-to-end export coverage and update the documentation and changelog.

Co-authored-by: Codex <codex@openai.com>
Signed-off-by: ajrasane <131806219+ajrasane@users.noreply.github.com>
@copy-pr-bot

copy-pr-bot Bot commented Sep 3, 2026

Copy link
Copy Markdown

Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually.

Contributors can view more details about this message here.

@coderabbitai

coderabbitai Bot commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true

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

@github-actions

github-actions Bot commented Sep 3, 2026

Copy link
Copy Markdown
Contributor
PR Preview Action v1.8.1

QR code for preview link

🚀 View preview at
https://NVIDIA.github.io/Model-Optimizer/pr-preview/pr-2321/

Built to branch gh-pages at 2026-09-03 02:11 UTC.
Preview will be ready when the GitHub Pages deployment is complete.

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