[ONNX PTQ] trt_plugins_precision keeps only the last fp16/fp32 entry when several custom op types are listed
维护者通常 1 天内回复
评估
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 新手友好度
- 25/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 停滞
- 技术栈
- python
调研方向
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.
由索引模型根据 Issue 内容生成。
描述
Describe the bug
- With
modelopt.onnx.quantization.quantize(..., trt_plugins_precision=[...]), listing two or more custom op types withfp16orfp32applies 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 assignscustom_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/fp8entries aren't affected, becausecustom_ops_to_quantize[op_type]is keyed per op type. - Also affected: AutoCast.
convert_to_mixed_precision(trt_plugins_precision=...)calls the same function throughGraphSanitizer.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 asOp:[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 asfp16, 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
mainsource) - 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.
- 主要语言
- Python
- 星标
- 5.6k
- 派生
- 819
- 平均合并
- 2 天 21 小时
- 30 天内合并 PR
- 191
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
NVIDIA/Model-Optimizer 的其他 Issue
-
ExternalDraftConfig accepts tvd_ce weights that produce zero or infinite loss可能已有人在做 @adimalkar 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 70/100
NVIDIA/Model-Optimizer#3524 · 1 条评论 ·
维护者通常 1 天内回复
-
[BUG] MSE histogram calibration: wrong amax for INT, TypeError for FP8 (args passed in the bias slot)可能已有人在做 @0z5a 于 8 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 82/100
NVIDIA/Model-Optimizer#3261 ·
维护者通常 1 天内回复
-
[Bug] modelopt-mcp: all launcher subprocesses hang when the server runs as a stdio MCP server — missing stdin=DEVNULL可能已有人在做 @ChenhanYu 于 51 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 88/100
NVIDIA/Model-Optimizer#2551 · 1 条评论 · 已指派 1 人 ·
维护者通常 1 天内回复
-
Puzzletron Progress 6/8 (calculating one block scores) takes 10 to 20 times more than in tutorial可能重新可做 @tejasng053 于 58 天前认领,目前没有进行中的 PR。 未关闭bug
难度 2/5 1-3 小时 新手友好度 68/100
NVIDIA/Model-Optimizer#1667 ·
维护者通常 1 天内回复
-
[ONNX PTQ] remove_input_dq_and_output_q produces an invalid graph when one INT8 custom op feeds another可能已有人在做 @orshih6 于 1 天前认领。 未关闭bug
难度 3/5 1-2 天 新手友好度 25/100
NVIDIA/Model-Optimizer#3515 · 1 条评论 ·
维护者通常 1 天内回复
查看 NVIDIA/Model-Optimizer 的全部 Issue
相似的 Issue
-
bot-triaged module: correctness (silent) module: fft triage review
难度 2/5 1-3 小时 新手友好度 75/100
维护者通常 1 天内回复
-
难度 1/5 1 小时以内 新手友好度 78/100
conda-forge/zarpaint-feedstock#8 · 1 条评论 · 1 个 reaction ·
-
plot_prediction colorbar shows a 0-1 range instead of the data range可能已有人在做 @nikhil3495 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 68/100
mllam/neural-lam#902 ·
维护者通常 2 天内回复
-
难度 2/5 1-3 小时 新手友好度 62/100
didi/helixharness#28 ·
维护者通常 1 天内回复
-
enhancement
难度 1/5 1 小时以内 新手友好度 62/100
DaoCloud/DaoCloud-docs#7839 ·
维护者通常 1 天内回复