Skip to content

[6529944] Fix dynamic NVFP4 TensorRT compatibility - #2333

Draft
ajrasane wants to merge 1 commit into
mainfrom
pull-request/6529944-dynamic-nvfp4-trt-compat
Draft

[6529944] Fix dynamic NVFP4 TensorRT compatibility#2333
ajrasane wants to merge 1 commit into
mainfrom
pull-request/6529944-dynamic-nvfp4-trt-compat

Conversation

@ajrasane

@ajrasane ajrasane commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

Type of change: Bug fix

This PR improves TensorRT compatibility for dynamic NVFP4 ONNX exports:

  • Preserves the W4A4 ONNX graph and requires TensorRT 11.0 or newer only when compiling dynamic NVFP4 models.
  • Adds an early, actionable diagnostic for TensorRT 10 with the explicit --quantize_mode=nvfp4 --recipe=w4a16_nvfp4 fallback.
  • Applies the same compatibility check to the ONNX evaluation entry point.
  • Fixes weight-only NVFP4 detection, initializer metadata placement, FP16 conversion, nested operator detection, and TensorRT 11 execution-context compatibility.
  • Moves the torch_onnx CI lane to TensorRT 11 while keeping diffusers and torch_trt on TensorRT 10.
  • Adds CPU unit coverage and Blackwell integration coverage for W4A4 and W4A16 builds.

Usage

# Dynamic W4A4 NVFP4 with TensorRT 11.0+
python examples/torch_onnx/torch_quant_to_onnx.py \
    --timm_model_name=vit_small_patch16_224 \
    --quantize_mode=nvfp4 \
    --onnx_save_path=vit_small_patch16_224.nvfp4.onnx \
    --trt_build

# Weight-only W4A16 fallback for TensorRT 10.16
python examples/torch_onnx/torch_quant_to_onnx.py \
    --timm_model_name=vit_small_patch16_224 \
    --quantize_mode=nvfp4 \
    --recipe=w4a16_nvfp4 \
    --onnx_save_path=vit_small_patch16_224.w4a16_nvfp4.onnx \
    --trt_build

Testing

  • Ran the affected CPU unit suite with CUDA_VISIBLE_DEVICES="": 113 passed.
  • Ran all applicable pre-commit hooks.
  • Ran the complete tests/examples/torch_onnx suite on Blackwell with TensorRT 11.0: 25 passed.
  • Verified the full W4A4 and W4A16 ViT TensorRT builds.
  • Verified TensorRT 10.16 rejects dynamic W4A4 before model or calibration work and successfully builds and deserializes the documented W4A16 fallback.
  • Verified the pretrained NVFP4 export, 512-sample calibration, TensorRT 11 build, 100-image evaluation, and engine deserialization workflow.

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

Additional Information

Tracking: [6529944].

🤖 Generated by Codex (AI agent).

Require TensorRT 11.0 or newer for dynamic NVFP4 engine builds and provide an actionable weight-only fallback for TensorRT 10.

Fix NVFP4 export metadata, FP16 graph conversion, and TensorRT 11 runtime compatibility. Add CPU and Blackwell regression coverage and route the torch ONNX example lane to TensorRT 11.

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

copy-pr-bot Bot commented Sep 4, 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 4, 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 4, 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-2333/

Built to branch gh-pages at 2026-09-04 16:00 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