Skip to content

[6648996] Fix NVFP4 ONNX packed-weight scale rounding - #2243

Draft
ajrasane wants to merge 1 commit into
mainfrom
arasane/fix_nvfp4_scale_ordering
Draft

[6648996] Fix NVFP4 ONNX packed-weight scale rounding#2243
ajrasane wants to merge 1 commit into
mainfrom
arasane/fix_nvfp4_scale_ordering

Conversation

@ajrasane

Copy link
Copy Markdown
Contributor

What does this PR do?

Type of change: Bug fix

This PR updates nvfp4_exporter.py so NVFP4 ONNX weight compression quantizes FP4 weights with the same FP8-rounded per-block scales serialized in the exported graph. It aligns quant_utils.py scale arithmetic with eager ModelOpt's FP32 operation ordering and applies the same behavior to the deprecated fp4qdq_to_2dq compatibility path in qdq_utils.py.

test_onnx_export_cpu.py adds regression coverage comparing exported FP8 scale bytes and packed FP4 weights against NVFP4QTensor at FP8-rounding, per-tensor arithmetic, and per-block arithmetic boundaries. CHANGELOG.rst documents the fix.

Usage

from modelopt.onnx.export import NVFP4QuantExporter

converted_model = NVFP4QuantExporter.process_model(model)

Testing

Ran:

CUDA_VISIBLE_DEVICES="" python -m pytest -q \
  tests/unit/torch/quantization/test_onnx_export_cpu.py \
  tests/unit/torch/quantization/test_nvfp4_tensor.py \
  tests/unit/onnx/quantization/test_qdq_utils.py \
  tests/unit/onnx/quantization/test_quant_utils.py

All 89 tests passed. All applicable pre-commit hooks passed. Additionally verified exact FP8-scale and packed-FP4 parity against eager quantization for 8,000 randomized tensors.

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?: ✅
  • 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).

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 Aug 25, 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 Aug 25, 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

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-2243/

Built to branch gh-pages at 2026-08-25 00:13 UTC.
Preview will be ready when the GitHub Pages deployment is complete.

@codecov

codecov Bot commented Aug 25, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.00000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 79.01%. Comparing base (73d7784) to head (93174f5).

Files with missing lines Patch % Lines
modelopt/onnx/export/nvfp4_exporter.py 92.85% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2243   +/-   ##
=======================================
  Coverage   79.01%   79.01%           
=======================================
  Files         523      523           
  Lines       60695    60705   +10     
=======================================
+ Hits        47960    47969    +9     
- Misses      12735    12736    +1     
Flag Coverage Δ
unit 55.67% <95.00%> (+<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