Skip to content

[6915426] Fix ONNX AutoTune benchmark initialization on TensorRT 11 - #2795

Merged
ajrasane merged 2 commits into
mainfrom
ajrasane/fix-onnx-autotune-trt11
Oct 16, 2026
Merged

ajrasane merged 2 commits into
mainfrom
ajrasane/fix-onnx-autotune-trt11

Conversation

@ajrasane

@ajrasane ajrasane commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

What does this PR do?

Type of change: Bug fix

ONNX AutoTune's TensorRT Python benchmark fails during initialization on TensorRT 11 because it accesses the removed NetworkDefinitionCreationFlag.EXPLICIT_BATCH enum. Create the network with STRONGLY_TYPED alone: explicit batching is already implicit in TensorRT 10 and 11, and strong typing remains enabled on both versions.

Add a parametrized GPU regression test that constructs the real benchmark, verifies its network creation flags, and builds and measures tiny INT8 and FP8 Q/DQ MatMul candidates. Update the AutoTune guide's TensorRT Python example to use the same supported network flags, and document the integration-test fixture. The same constructor exists in ModelOpt 0.47, so this also includes a changelog entry. BuilderFlag.DIRECT_IO remains available in the tested versions and needs no change.

Usage

from modelopt.onnx.quantization.autotune import TensorRTPyBenchmark

benchmark = TensorRTPyBenchmark(warmup_runs=1, timing_runs=2)
latency_ms = benchmark.run("model.onnx")

Testing

  • Before the fix, both new regression cases fail at the real constructor with the missing EXPLICIT_BATCH AttributeError.
  • TensorRT 11.1.0.106, RTX 6000 Ada: pytest tests/gpu/onnx/quantization/autotune/test_benchmark.py -q — 36 passed, including INT8/FP8 candidate builds and measurements, Python benchmark bytes/path/callable cases, and trtexec smoke tests.
  • TensorRT 10.13.3.9, RTX 6000 Ada: pytest tests/gpu/onnx/quantization/autotune/test_benchmark.py -k TestTensorRTPyBenchmark -q — 5 passed.
  • Re-ran the original minimal constructor reproduction on TensorRT 11: initialization succeeds.
  • Repository pre-commit checks on the changed files pass, including Ruff, mypy, and Bandit.
  • Verified the corrected guide's network creation on TensorRT 11.1.0.106 and 10.13.3.9; both initialize successfully with strong typing enabled.

Full standalone AutoTune searches and quantization CLI accuracy evaluations were not run. Candidate measurements here validate the shared benchmark path, not model accuracy.

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?: ✅
  • Did you get Claude approval on this PR?: N/A

Additional Information

TensorRT 10-to-11 migration guide

Summary by CodeRabbit

  • New Features
    • Added imatrix calibration for GGML formats, including weighted calibration using per-column and per-expert statistics. Existing final codes remain unchanged, allowing calibration of weights skipped by GPTQ.
  • Bug Fixes
    • Fixed ONNX AutoTune benchmark initialization with TensorRT 11 while retaining strongly typed network support for TensorRT 10.
    • Fixed LayerNorm input quantization in presets and recipes that enable input quantizers.
  • Documentation
    • Updated the TensorRT Python API example to use strongly typed network configuration.
  • Tests
    • Added GPU integration coverage for INT8 and FP8 quantized MatMul benchmarks, including finite, positive latency checks. FP8 coverage is skipped on unsupported GPUs.

@copy-pr-bot

copy-pr-bot Bot commented Oct 14, 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 Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: NVIDIA/Model-Optimizer/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Enterprise
  • Run ID: 66124d70-7bf8-4bf4-a036-6264ea2c5213
📥 Commits

Reviewing files that changed from the base of the PR and between 0fc4792 and d2b55c3.

📒 Files selected for processing: 1
  • CHANGELOG.rst
🚧 Files skipped from review as they are similar to previous changes: 1
  • CHANGELOG.rst

Included review availability: This review used your included allowance. Your plan provides up to 12 included reviews per hour; 11 remain after this review.

📝 Walkthrough

The ONNX AutoTune benchmark and guide now create TensorRT networks with only the STRONGLY_TYPED flag. An integration test checks INT8 and FP8 quantized MatMul models. The changelog records the TensorRT 11 benchmark initialization fix.

Changes: AutoTune Network Initialization

Layer / File(s) Summary
Strongly typed network creation and quantized-model validation
modelopt/onnx/quantization/autotune/benchmark.py, tests/gpu/onnx/quantization/autotune/test_benchmark.py, docs/source/guides/9_autotune.rst, CHANGELOG.rst
The benchmark and guide remove EXPLICIT_BATCH and retain STRONGLY_TYPED. The integration test validates INT8 and FP8 quantized MatMul models, checks that the network is strongly typed, and asserts finite positive latency. The FP8 case skips GPUs below compute capability 8.9. The changelog records the TensorRT 11 initialization fix.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested reviewers: gcunhase

Merge Risk: ⚪ Minimal · up to d2b55

The TensorRT 11 initialization fix has no identified merge-blocking issue; merge after normal checks.

Pre-merge checks: Passed 6
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main change: fixing ONNX AutoTune benchmark initialization for TensorRT 11.
Docstring Coverage Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 4 functions across 2 files. (1 skipped: 1 …
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Security Anti-Patterns Passed No listed security anti-pattern was introduced. The only changed modelopt Python line sets the TensorRT STRONGLY_TYPED flag. No examples Python files or dependency files changed. Added lines con…
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

@github-actions

github-actions Bot commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor
PR Preview Action v1.8.1
Preview removed because the pull request was closed.
2026-10-16 13:16 UTC

@ajrasane
ajrasane marked this pull request as ready for review October 14, 2026 18:01
@ajrasane
ajrasane requested review from a team as code owners October 14, 2026 18:01

@cjluo-nv cjluo-nv left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bot review (bedrock-claude-opus-5-5) — DM the bot to share feedback.

The code fix is correct and has a good GPU regression test, but the Autotune guide still has the same EXPLICIT_BATCH snippet that breaks on TensorRT 11.

Needs action:

  • Update the "Using TensorRT Python API" example in docs/source/guides/9_autotune.rst to use only 1 << int(trt.NetworkDefinitionCreationFlag.STRONGLY_TYPED). As written, the snippet raises the same AttributeError this PR fixes.

No action needed:

  • benchmark.py was the only code path still using EXPLICIT_BATCH. The change is right for TensorRT 10 and 11, since explicit batch is implicit on both and STRONGLY_TYPED is kept.
  • The new parametrized test runs the real constructor, checks the STRONGLY_TYPED flag, and builds and measures INT8 and FP8 Q/DQ MatMul engines. It skips FP8 below SM89. No existing tests were changed.
  • The changelog entry is under 0.49.0 Bug Fixes, which is the right place.

@ajrasane

Copy link
Copy Markdown
Contributor Author

Addressed the review in 9a5a621: the “Using TensorRT Python API” example now creates the network with STRONGLY_TYPED alone, matching the benchmark implementation. Verified the corrected network creation on TensorRT 11.1.0.106 and 10.13.3.9; both succeed with strong typing enabled. Pre-commit checks pass.

Also added a concise docstring to the integration-test class's TensorRT/CUDA fixture in response to the docstring coverage warning. The PR description now includes the documentation change and its validation. Full AutoTune searches and CLI accuracy evaluation remain explicitly untested.

@codecov

codecov Bot commented Oct 14, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 78.67%. Comparing base (f3678b6) to head (d2b55c3).
⚠️ Report is 3 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2795      +/-   ##
==========================================
+ Coverage   69.33%   78.67%   +9.33%     
==========================================
  Files         654      655       +1     
  Lines       72665    72776     +111     
==========================================
+ Hits        50385    57256    +6871     
+ Misses      22280    15520    -6760     
Flag Coverage Δ
examples-diffusers 20.17% <0.00%> (-0.06%) ⬇️
examples-gpt-oss 13.53% <0.00%> (+0.01%) ⬆️
examples-hf_ptq 23.32% <0.00%> (-0.02%) ⬇️
examples-llm_distill 13.61% <0.00%> (+0.01%) ⬆️
examples-llm_eval 17.31% <0.00%> (+0.03%) ⬆️
examples-llm_qat 17.56% <0.00%> (-0.04%) ⬇️
examples-llm_sparsity 15.83% <0.00%> (-0.01%) ⬇️
examples-megatron_bridge 26.64% <0.00%> (-0.15%) ⬇️
examples-specdec_bench 13.31% <0.00%> (+0.02%) ⬆️
examples-speculative_decoding 17.55% <0.00%> (-0.08%) ⬇️
examples-torch_onnx 21.54% <0.00%> (-0.08%) ⬇️
examples-torch_trt 15.28% <0.00%> (-0.01%) ⬇️
examples-vllm_serve 15.02% <0.00%> (+0.10%) ⬆️
gpu 59.54% <100.00%> (+37.71%) ⬆️
unit 59.93% <0.00%> (+0.05%) ⬆️

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.

@ajrasane
ajrasane force-pushed the ajrasane/fix-onnx-autotune-trt11 branch from 9a5a621 to 0fc4792 Compare October 14, 2026 21:07

@gcunhase gcunhase left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This matches TrtExecBenchmark with --stronglyTyped enabled.

LGTM.

TensorRT 11 removed EXPLICIT_BATCH. Use STRONGLY_TYPED alone to preserve typing on TensorRT 10 and 11. Add real INT8 and FP8 benchmark regression coverage.

Signed-off-by: ajrasane <131806219+ajrasane@users.noreply.github.com>
Remove the stale EXPLICIT_BATCH access from the TensorRT Python example and document the GPU integration-test fixture.

Signed-off-by: ajrasane <131806219+ajrasane@users.noreply.github.com>
@ajrasane
ajrasane force-pushed the ajrasane/fix-onnx-autotune-trt11 branch from 0fc4792 to d2b55c3 Compare October 15, 2026 19:03
@ajrasane
ajrasane merged commit 35c4142 into main Oct 16, 2026
75 of 84 checks passed
@ajrasane
ajrasane deleted the ajrasane/fix-onnx-autotune-trt11 branch October 16, 2026 13:16
@rohansjoshi rohansjoshi added the cherry-pick-done Added by bot once PR is cherry-picked to the release branch label Oct 16, 2026
rohansjoshi added a commit that referenced this pull request Oct 17, 2026
#2769 #2770 #2719 #2796 #2801 #2794 #2787 #2682 #2793 #2791 #2792 #2766 #2823 #2777 #2773 #2813 #2832 #2795 #2684 #2822 #2838 #2807 #2772 #2837 #2820 (#2843)

## Cherry-picked PRs

- #2647
- #2700
- #2718
- #2578
- #2580
- #2711
- #2731
- #2726
- #2697
- #2769
- #2770
- #2719
- #2796
- #2801
- #2794
- #2787
- #2682
- #2793
- #2791
- #2792
- #2766
- #2823
- #2777
- #2773
- #2813
- #2832
- #2795
- #2684
- #2822
- #2838
- #2807
- #2772
- #2837
- #2820

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

* **New Features**
* Expanded quantized model export support for MXFP4, MXFP8, FP8, and
additional block-quantization formats.
* Added quantization support for GPT-OSS and Step-family models, plus
export support for native FP8 experts.
* Added chat JSONL data preparation for Megatron workflows and an option
to freeze the student MTP head during distillation.
* Added model recipes for Kimi, Gemma, DiffusionGemma, and GLM variants.
* **Bug Fixes**
* Improved ONNX quantization and export compatibility, distributed
calibration consistency, and handling of packed attention caches.
  * Improved safe model loading and low-precision quantization accuracy.
* **Documentation**
* Updated the 0.48.0 changelog and guidance for data preparation and
quantization recipes.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->

Also includes a partial backport of #2656 (only the
`_validate_fold_weight` hook and the `mtq.fold_weight` pre-check), which
#2820 depends on.

---------

Signed-off-by: Shengliang Xu <shengliangx@nvidia.com>
Signed-off-by: Rohan Joshi <rohjoshi@nvidia.com>
Signed-off-by: Juhi Mittal <juhim@nvidia.com>
Signed-off-by: Fridah-nv <201670829+Fridah-nv@users.noreply.github.com>
Signed-off-by: Chenjie Luo <chenjiel@nvidia.com>
Signed-off-by: yingguo-trt <244492186+yingguo-trt@users.noreply.github.com>
Signed-off-by: weimingc <17592131+meenchen@users.noreply.github.com>
Signed-off-by: Yue <yueshen@nvidia.com>
Signed-off-by: joe-nv <222375587+joe-nv@users.noreply.github.com>
Signed-off-by: ajrasane <131806219+ajrasane@users.noreply.github.com>
Signed-off-by: Ajinkya Rasane <131806219+ajrasane@users.noreply.github.com>
Signed-off-by: ColinM-sys <cmcdonough@50words.com>
Signed-off-by: Keval Morabia <28916987+kevalmorabia97@users.noreply.github.com>
Signed-off-by: Meng Xin <164952785+mxinO@users.noreply.github.com>
Signed-off-by: gcunhase <4861122+gcunhase@users.noreply.github.com>
Signed-off-by: Chad Voegele <cvoegele@nvidia.com>
Co-authored-by: Shengliang Xu <106840466+shengliangxu@users.noreply.github.com>
Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
Co-authored-by: Juhi Mittal <39641197+juhi10071998@users.noreply.github.com>
Co-authored-by: Frida Hou <201670829+Fridah-nv@users.noreply.github.com>
Co-authored-by: Chenjie Luo <108829653+cjluo-nv@users.noreply.github.com>
Co-authored-by: yingguo-trt <244492186+yingguo-trt@users.noreply.github.com>
Co-authored-by: Wei-Ming Chen <17592131+meenchen@users.noreply.github.com>
Co-authored-by: yueshen2016 <39203804+yueshen2016@users.noreply.github.com>
Co-authored-by: joe <222375587+joe-nv@users.noreply.github.com>
Co-authored-by: Ajinkya Rasane <131806219+ajrasane@users.noreply.github.com>
Co-authored-by: Colin McDonough <cmcdonough@50words.com>
Co-authored-by: Keval Morabia <28916987+kevalmorabia97@users.noreply.github.com>
Co-authored-by: mxinO <164952785+mxinO@users.noreply.github.com>
Co-authored-by: Gwena Cunha <4861122+gcunhase@users.noreply.github.com>
Co-authored-by: Chad Voegele <chadvoegele@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cherry-pick-0.48.0 cherry-pick-done Added by bot once PR is cherry-picked to the release branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants