Skip to content

[6421642][ONNX][Quantization] Fix NVFP4 exporter node ordering#1984

Closed
gcunhase wants to merge 0 commit into
NVIDIA:mainfrom
gcunhase:dev/agent/6421642_nvfp4_toposort_export
Closed

[6421642][ONNX][Quantization] Fix NVFP4 exporter node ordering#1984
gcunhase wants to merge 0 commit into
NVIDIA:mainfrom
gcunhase:dev/agent/6421642_nvfp4_toposort_export

Conversation

@gcunhase

Copy link
Copy Markdown
Contributor

What does this PR do?

Type of change: Bug fix

  • Adds a stable tensor-dependency sort before NVFP4QuantExporter.post_process() returns.
  • Ensures newly inserted DequantizeLinear and Cast producer nodes appear before the Transpose / MatMul nodes that consume them.
  • Adds CPU Torch ONNX export regression coverage for NVFP4 static weight export.

Usage

# Internal NVFP4 export path:
# 1. Quantize a torch model with an NVFP4 config.
# 2. Export it to ONNX so torch emits TRT_FP4QDQ nodes.
# 3. Lower those nodes with NVFP4QuantExporter.process_model(...).

import onnx

from modelopt.onnx.export import NVFP4QuantExporter

onnx_model = onnx.load("model_with_trt_fp4qdq.onnx")
onnx_model = NVFP4QuantExporter.process_model(onnx_model)
onnx.checker.check_model(onnx_model)

Testing

  • Reproduced the issue before the fix on a small NVFP4 ONNX export graph and on main before this patch.
  • Verified the fixed exporter returns producer_after_consumer_edges=0, onnx.checker.check_model(converted) passes, and the repro exits with rc=0.
  • Ran python -m pytest tests/unit/torch/quantization/test_nvfp4_onnx_export_cpu.py::test_nvfp4_exported_onnx_is_topologically_sorted -q.

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?: N/A

@copy-pr-bot

copy-pr-bot Bot commented Jul 16, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@coderabbitai

coderabbitai Bot commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: be49b69d-35b2-4a81-8fc3-d1b5a1b92cbf

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

@gcunhase
gcunhase force-pushed the dev/agent/6421642_nvfp4_toposort_export branch from 5fd9aba to 7384415 Compare July 16, 2026 20:51
@gcunhase gcunhase closed this Jul 16, 2026
@gcunhase
gcunhase force-pushed the dev/agent/6421642_nvfp4_toposort_export branch from 7384415 to 21d0069 Compare July 16, 2026 20:54
@copy-pr-bot

copy-pr-bot Bot commented Jul 16, 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.

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