Skip to content

[6919103] Fix custom-op plugin compilation with TensorRT 11 - #2801

Merged
ajrasane merged 1 commit into
mainfrom
ajrasane/fix-custom-plugin-trt11
Oct 14, 2026
Merged

ajrasane merged 1 commit into
mainfrom
ajrasane/fix-custom-plugin-trt11

Conversation

@ajrasane

@ajrasane ajrasane commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

What does this PR do?

Type of change: Bug fix

The ONNX PTQ custom-op plugin fails to compile with TensorRT 11 because isOutputBroadcastAcrossBatch and canBroadcastInputAcrossBatch no longer override methods in the base interface. Guard their declarations and definitions with NV_TENSORRT_MAJOR < 11, preserving the legacy callbacks for older TensorRT versions.

Add a regression in the existing TensorRT example test lane that runs the real CMake build and checks that it produces libidentity_conv_plugin.so.

Usage

cmake -S examples/onnx_ptq/custom_op_plugin/plugin -B /tmp/identity-plugin-build
cmake --build /tmp/identity-plugin-build --parallel 2

Testing

  • Confirmed the new build regression fails before the fix with both callback override errors on TensorRT 11.1.
  • Ran python -m pytest --noconftest -o addopts= tests/examples/torch_trt/test_custom_op_plugin.py -q: passed with TensorRT 11.1 and TensorRT 10.13.3. This isolates the C++ build test from unrelated Python suite fixtures and options.
  • Reran the documented CMake configure/build commands on the 0.48.0rc0 source with only this fix applied: passed.
  • All applicable pre-commit checks passed for the three changed files.
  • No GPU inference, engine building, or INT8 calibration was run. Validation covers plugin compilation and linking.

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 — minor example build compatibility fix; no critical stable-release regression or public API change.
  • Did you get Claude approval on this PR?: N/A — small compatibility fix.

Summary by CodeRabbit

  • Bug Fixes

    • Improved compatibility of the custom operation plugin with TensorRT 11 and later.
  • Tests

    • Added an automated build check for the custom operation plugin when the required build tools are available.

TensorRT 11 removes the legacy batch-broadcast virtual methods. Guard both callback declarations and definitions by TensorRT major version, preserving older interfaces. Add a real CMake build regression for the example plugin.

Signed-off-by: ajrasane <[email protected]>
@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: af839302-c7af-4c84-b00a-8f48a5bf74ef
📥 Commits

Reviewing files that changed from the base of the PR and between 40ca6c7 and 0f7afd6.

📒 Files selected for processing: 3
  • examples/onnx_ptq/custom_op_plugin/plugin/IdentityConvPlugin.cpp
  • examples/onnx_ptq/custom_op_plugin/plugin/IdentityConvPlugin.h
  • tests/examples/torch_trt/test_custom_op_plugin.py

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

📝 Walkthrough

The plugin’s batch-broadcast overrides are declared and compiled only for TensorRT versions below 11. A pytest test builds the plugin when CMake and nvcc are available and checks for the shared library.

Changes: Plugin compatibility

Layer / File(s) Summary
TensorRT version guards and build test
examples/onnx_ptq/custom_op_plugin/plugin/IdentityConvPlugin.h, examples/onnx_ptq/custom_op_plugin/plugin/IdentityConvPlugin.cpp, tests/examples/torch_trt/test_custom_op_plugin.py
The two batch-broadcast overrides are declared and defined only when NV_TENSORRT_MAJOR < 11. The test skips when CMake or nvcc is unavailable; otherwise, it configures and builds the plugin, then checks that libidentity_conv_plugin.so exists.

Priority: ⬇️ Low

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

Change: Bug fix

Merge Risk: ⚪ Minimal · up to 0f7af

This change fixes plugin compilation with TensorRT 11 and adds a build regression test. No concrete merge-blocking risk remains. A local environment that has CMake and nvcc but no TensorRT may fail the new test instead of skipping it.

Pre-merge checks: Passed 5 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 20.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 5 functions across 3 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 5 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly identifies the main change: fixing custom-op plugin compilation with TensorRT 11.
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 PASS. The PR changes only two C++ plugin files and adds one Python test. The added Python test uses shutil, subprocess, Path, and pytest; it adds no torch.load, `numpy.load(..., allow_pickle…
  • Fix all pre-merge checks with AI
✨ Finishing Touches: 💡 2
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
🛠️ Fix failing CI checks: 💡
  • 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.

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

@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 (gpt-6.1-sol) — DM the bot to share feedback.

Approve: the matching TensorRT version guards preserve older callbacks, and the real CMake build regression covers compilation and linking.

No action needed.

@ajrasane
ajrasane enabled auto-merge (squash) October 14, 2026 18:20
@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 71.97%. Comparing base (39bf04e) to head (0f7afd6).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2801      +/-   ##
==========================================
- Coverage   71.97%   71.97%   -0.01%     
==========================================
  Files         648      648              
  Lines       71793    71793              
==========================================
- Hits        51676    51670       -6     
- Misses      20117    20123       +6     
Flag Coverage Δ
examples-torch_onnx 21.65% <ø> (+<0.01%) ⬆️
examples-torch_trt 15.30% <ø> (+<0.01%) ⬆️
unit 59.93% <ø> (-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.

@ajrasane
ajrasane merged commit 6133ad1 into main Oct 14, 2026
49 of 53 checks passed
@ajrasane
ajrasane deleted the ajrasane/fix-custom-plugin-trt11 branch October 14, 2026 19:57
@github-actions

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

@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 <[email protected]>
Signed-off-by: Rohan Joshi <[email protected]>
Signed-off-by: Juhi Mittal <[email protected]>
Signed-off-by: Fridah-nv <[email protected]>
Signed-off-by: Chenjie Luo <[email protected]>
Signed-off-by: yingguo-trt <[email protected]>
Signed-off-by: weimingc <[email protected]>
Signed-off-by: Yue <[email protected]>
Signed-off-by: joe-nv <[email protected]>
Signed-off-by: ajrasane <[email protected]>
Signed-off-by: Ajinkya Rasane <[email protected]>
Signed-off-by: ColinM-sys <[email protected]>
Signed-off-by: Keval Morabia <[email protected]>
Signed-off-by: Meng Xin <[email protected]>
Signed-off-by: gcunhase <[email protected]>
Signed-off-by: Chad Voegele <[email protected]>
Co-authored-by: Shengliang Xu <[email protected]>
Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
Co-authored-by: Juhi Mittal <[email protected]>
Co-authored-by: Frida Hou <[email protected]>
Co-authored-by: Chenjie Luo <[email protected]>
Co-authored-by: yingguo-trt <[email protected]>
Co-authored-by: Wei-Ming Chen <[email protected]>
Co-authored-by: yueshen2016 <[email protected]>
Co-authored-by: joe <[email protected]>
Co-authored-by: Ajinkya Rasane <[email protected]>
Co-authored-by: Colin McDonough <[email protected]>
Co-authored-by: Keval Morabia <[email protected]>
Co-authored-by: mxinO <[email protected]>
Co-authored-by: Gwena Cunha <[email protected]>
Co-authored-by: Chad Voegele <[email protected]>
ajrasane added a commit that referenced this pull request Oct 28, 2026
### What does this PR do?

Type of change: Bug fix

TensorRT inference fails during session initialization on TensorRT 11
because `IExecutionContext.all_shape_inputs_specified` was removed.
Replace that legacy check with `infer_shapes()` after input values are
available, including when `io_shapes` is supplied.

Select the optimization profile before setting input dimensions, honor
TensorRT's host/device buffer locations, and reject missing inputs and
invalid dimensions. Host input copies finish before shape inference
reads their values. Add real-engine regression coverage and a changelog
entry.

The 0.48.0 changelog also records the already merged TensorRT plugin
compatibility fixes from
[#2796](#2796) and
[#2801](#2801).

### Usage

```bash
pytest -o addopts= tests/gpu/torch/deploy/_runtime/test_trt_client.py -k test_trt_session_inference
```

### Testing

- Four real-engine cases pass on TensorRT 11.1.0.106 and 10.13.3.9:
static shapes, inferred static shapes, dynamic dimensions, and a
shape-tensor reshape. They compare actual inference outputs and check
missing inputs, invalid profile dimensions, and invalid reshape values.
- Reverting the production fix makes all four cases fail on TensorRT 11
with the removed-property error. The minimal identity-engine
reproduction completes inference with the fix.
- Full test module: 4 passed, 11 skipped per environment. Four existing
compile/profile tests require an ORT TensorRT provider library that
cannot load `libcublas.so.12`; seven manual vision tests were not
selected. Full ImageNet accuracy and FP8/INT8 evaluation were not run.
- Focused pre-commit hooks and `git diff --check` pass.
- A 100-iteration identity-engine sample on TensorRT 10 with `[16, 3,
224, 224]` buffers showed unchanged peak allocated GPU memory
(67,436,544 bytes). Median inference time was 40.3 μs before and 43.4 μs
after validation.

### Before your PR is "*Ready for review*"

Make sure you read and follow [Contributor
guidelines](https://github.com/NVIDIA/Model-Optimizer/blob/main/CONTRIBUTING.md)
and your commits are signed (`git commit -s -S`).

Make sure you read and follow the [Security Best
Practices](https://github.com/NVIDIA/Model-Optimizer/blob/main/SECURITY.md#security-coding-practices-for-contributors)
(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](https://github.com/NVIDIA/Model-Optimizer/blob/main/CHANGELOG.rst)?:
✅


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

* **Bug Fixes**
* Improved TensorRT inference initialization for static, dynamic, and
shape-tensor inputs.
* Improved handling of inputs stored on the host or GPU during
inference.
* Added validation for supplied inputs and shapes. Missing inputs,
invalid shapes, and dynamic shapes outside the supported profile now
produce errors.
* Fixed preprocessing for custom TensorRT plugin libraries and corrected
the custom plugin example build process.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Signed-off-by: ajrasane <[email protected]>
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.

3 participants