[ONNX PTQ] trt_plugins_precision keeps only the last fp16/fp32 entry when several custom op types are listed

Đang mở
#3,514 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

@uditstocks đang làm issue này rồi.

Từ ngày 22/11/2026.

  • #3523 của @uditstocks — đang mở

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
25/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
python
Lĩnh vực
machine-learning

Hướng nghiên cứu

Start in modelopt/onnx/trt_utils.py at interpret_trt_plugins_precision_flag, where both the op:precision and op:[...]:[...] branches overwrite the per-precision dict, and the per-I/O branch only creates casts when inp_precision_cast is set. Check modelopt/onnx/autocast/graphsanitizer.py ensure_custom_ops_precision, which calls the same function. Done means the issue's repro returns both op types under fp16 and the output-only [fp32]:[fp16] case keeps its fp16 output cast. A linked open pull request (#3523) already exists, so check it before starting.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

bug

Describe the bug

  • With modelopt.onnx.quantization.quantize(..., trt_plugins_precision=[...]), listing two or more custom op types with fp16 or fp32 applies the precision to the last op type only. The earlier entries are silently dropped and no warning is logged.
  • Cause: in interpret_trt_plugins_precision_flag (modelopt/onnx/trt_utils.py), each entry assigns custom_ops_to_cast[precision] = {op_type: ...}. That replaces the whole per-precision dict instead of adding to it. The same thing happens in both the <op>:<precision> and <op>:[...]:[...] forms (lines 518 and 565 at that commit; 514 and 561 in 0.48.0). int8/fp8 entries aren't affected, because custom_ops_to_quantize[op_type] is keyed per op type.
  • Also affected: AutoCast. convert_to_mixed_precision(trt_plugins_precision=...) calls the same function through GraphSanitizer.ensure_custom_ops_precision (modelopt/onnx/autocast/graphsanitizer.py).
  • Related: in the per-I/O form, cast entries are only created if inp_precision_cast:. A request for output-only casts, such as Op:[fp32]:[fp16], therefore loses its fp16 output cast.
  • Impact (should have): you can't set FP16/FP32 I/O for more than one plugin type in the same model. We hit this setting per-plugin precisions for a TensorRT model with multiple plugin types.
  • End to end: with quantize() and two TensorRT plugin op types both listed as fp16, the output ONNX has Cast nodes only around the last-listed op type. Reversing the list order reverses which op type gets them.
Steps/Code to reproduce bug

No plugin library is needed; this is pure graph processing.

from onnx import TensorProto, helper
from modelopt.onnx.trt_utils import interpret_trt_plugins_precision_flag

nodes = [
    helper.make_node("PluginA", ["x"], ["a"], name="plugin_a", domain="custom"),
    helper.make_node("PluginB", ["a"], ["y"], name="plugin_b", domain="custom"),
]
graph = helper.make_graph(
    nodes, "repro",
    [helper.make_tensor_value_info("x", TensorProto.FLOAT, [1, 8])],
    [helper.make_tensor_value_info("y", TensorProto.FLOAT, [1, 8])],
    value_info=[helper.make_tensor_value_info("a", TensorProto.FLOAT, [1, 8])],
)
model = helper.make_model(graph, opset_imports=[helper.make_opsetid("", 17), helper.make_opsetid("custom", 1)])

for flags in (["PluginA:fp16", "PluginB:fp16"],
              ["PluginA:[fp16]:[fp16]", "PluginB:[fp16]:[fp16]"],
              ["PluginA:[fp32]:[fp16]"]):
    to_cast, _ = interpret_trt_plugins_precision_flag(model, flags, "int8")
    print(flags, "->", to_cast)

Output (0.48.0):

['PluginA:fp16', 'PluginB:fp16'] -> {'fp16': {'PluginB': {'inp': [0], 'out': [0]}}}
['PluginA:[fp16]:[fp16]', 'PluginB:[fp16]:[fp16]'] -> {'fp16': {'PluginB': {'inp': [0], 'out': [0]}}}
['PluginA:[fp32]:[fp16]'] -> {'fp32': {'PluginA': {'inp': [0], 'out': []}}}

The same code is present in 0.49.0rc0 and on main.

Expected behavior
['PluginA:fp16', 'PluginB:fp16'] -> {'fp16': {'PluginA': {...}, 'PluginB': {...}}}
['PluginA:[fp16]:[fp16]', 'PluginB:[fp16]:[fp16]'] -> {'fp16': {'PluginA': {...}, 'PluginB': {...}}}
['PluginA:[fp32]:[fp16]'] -> {'fp32': {'PluginA': {'inp': [0], 'out': []}}, 'fp16': {'PluginA': {'inp': [], 'out': [0]}}}

Suggested fix: custom_ops_to_cast.setdefault(precision, {})[op_type] = {...} in both places, and if inp_precision_cast or out_precision_cast: in the per-I/O branch. With these changes, all three cases above give the expected result.

Who can help?
  • @NVIDIA/modelopt-onnx-codeowners

System information

  • Container used (if applicable): none
  • OS: Ubuntu 24.04.4 LTS (Jetson Linux R39.2.1)
  • CPU architecture: aarch64
  • GPU name: NVIDIA Jetson AGX Thor
  • GPU memory size: unified memory (Jetson)
  • Number of GPUs: 1
  • Library versions:
    • Python: 3.12.3
    • ModelOpt version or commit hash: 0.48.0 (also checked 0.49.0rc0 and main source)
    • CUDA: 13.2
    • PyTorch: 2.15.0+cu132
    • Transformers: n/a
    • TensorRT-LLM: n/a
    • ONNXRuntime: 1.24.0
    • TensorRT: 10.16.2.10
  • Any other details that may help: onnx 1.21.0, onnx-graphsurgeon 0.6.1. The bug is independent of the platform.
Ngôn ngữ chính
Python
Star
5.6k
Fork
819
Merge trung bình
2 ngày 21 giờ
Pull request đã merge (30 ngày)
191

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của NVIDIA/Model-Optimizer

Tất cả issue của NVIDIA/Model-Optimizer

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.