[ONNX PTQ] remove_input_dq_and_output_q produces an invalid graph when one INT8 custom op feeds another
Maintainer thường phản hồi trong vòng 1 ngày
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- 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
- Sôi nổi
- Công nghệ
- python
- Lĩnh vực
- machine-learning
Hướng nghiên cứu
Start in modelopt/onnx/quantization/qdq_utils.py at remove_input_dq_and_output_q, and follow how tensor_consumers is built once and then used by the input-DQ and output-Q passes. Run the reproduction script from the issue, which chains PluginA and PluginB through Q/DQ pairs, and check that both custom nodes survive and onnx.checker passes. Note that PR #3518 is already open against this issue, so review or coordinate with it before starting a parallel fix.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Describe the bug
- When two custom ops both requested as
int8intrt_plugins_precisionare connected directly (PluginA -> PluginB),remove_input_dq_and_output_q(modelopt/onnx/quantization/qdq_utils.py; line 799 in 0.48.0) returns an invalid model. The upstream custom op (and the nodes before it) disappear, and the downstream op's input refers to a tensor that nothing produces. - Expected for TensorRT:
Q -> PluginA -> PluginB -> DQ, orQ -> PluginA -> (DQ->Q) -> PluginB -> DQ, with each plugin consuming and producing INT8. - Impact (should have): models where an INT8 plugin's output feeds another INT8 plugin can't be quantized. Through
quantize(), the output ONNX lost the first plugin node.quantize()still wrote the model and logged only a generic checker warning ("ONNX model checker failed"), which is hidden atlog_level="ERROR". - With a standard op between the two plugins (tested with
Relu), the result is correct. - Cause:
tensor_consumersis built once and not updated while rewiring. The DQ pass rewiresPluginBto reada_qand deletesa_DQ. The Q pass then treatsa_QasPluginA's output Q, uses the stale entry to point the deleteda_DQatPluginA's output, and deletesa_Q. Nothing producesa_qany more andPluginA's output has no consumer, sograph.cleanup()removesPluginAandx_Q.
Steps/Code to reproduce bug
No plugin library is needed. The input is the Q/DQ graph quantize() builds before calling this function.
import numpy as np
import onnx
from onnx import TensorProto, helper, numpy_helper
from modelopt.onnx.quantization.qdq_utils import remove_input_dq_and_output_q
inits, nodes = [], []
def qdq(t):
s, z = f"{t}_scale", f"{t}_zp"
inits.extend([numpy_helper.from_array(np.array(0.1, np.float32), s),
numpy_helper.from_array(np.array(0, np.int8), z)])
nodes.append(helper.make_node("QuantizeLinear", [t, s, z], [f"{t}_q"], name=f"{t}_Q"))
nodes.append(helper.make_node("DequantizeLinear", [f"{t}_q", s, z], [f"{t}_dq"], name=f"{t}_DQ"))
return f"{t}_dq"
nodes.append(helper.make_node("PluginA", [qdq("x")], ["a"], name="plugin_a", domain="custom"))
nodes.append(helper.make_node("PluginB", [qdq("a")], ["b"], name="plugin_b", domain="custom"))
nodes.append(helper.make_node("Identity", [qdq("b")], ["y"], name="out"))
graph = helper.make_graph(nodes, "chain", [helper.make_tensor_value_info("x", TensorProto.FLOAT, [1, 8])],
[helper.make_tensor_value_info("y", TensorProto.FLOAT, [1, 8])], inits)
model = helper.make_model(graph, opset_imports=[helper.make_opsetid("", 19), helper.make_opsetid("custom", 1)])
out = remove_input_dq_and_output_q(
model, {"PluginA": {"inp": [0], "out": [0]}, "PluginB": {"inp": [0], "out": [0]}})
for n in out.graph.node:
print(n.op_type, n.name, list(n.input)[:1], list(n.output))
onnx.checker.check_model(out)
Output (0.48.0):
PluginB plugin_b ['a_q'] ['b']
DequantizeLinear b_DQ ['b'] ['b_dq']
Identity out ['b_dq'] ['y']
onnx.onnx_cpp2py_export.checker.ValidationError: Nodes in a graph must be topologically sorted, however input 'a_q' of node:
name: plugin_b OpType: PluginB
is not output of any previous nodes.
x_Q, PluginA and a_Q are gone; PluginB reads the dangling tensor a_q. The function logic is unchanged in 0.49.0rc0 and on main.
Expected behavior
A valid graph in which both custom ops remain, each consuming INT8 (a QuantizeLinear output) and producing INT8 (consumed by a DequantizeLinear, or directly by the next INT8 custom op).
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 (function logic identical in 0.49.0rc0 and on
main) - 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. Independent of 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
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- 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.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của NVIDIA/Model-Optimizer
-
ExternalDraftConfig accepts tvd_ce weights that produce zero or infinite lossCó thể đã có người làm @adimalkar đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
NVIDIA/Model-Optimizer#3524 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[BUG] MSE histogram calibration: wrong amax for INT, TypeError for FP8 (args passed in the bias slot)Có thể đã có người làm @0z5a đã nhận 8 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
NVIDIA/Model-Optimizer#3261 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[Bug] modelopt-mcp: all launcher subprocesses hang when the server runs as a stdio MCP server — missing stdin=DEVNULLCó thể đã có người làm @ChenhanYu đã nhận 51 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
NVIDIA/Model-Optimizer#2551 · 1 bình luận · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Puzzletron Progress 6/8 (calculating one block scores) takes 10 to 20 times more than in tutorialCó thể làm lại được @tejasng053 đã nhận 58 ngày trước và không có pull request nào đang mở. Đang mởbug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
NVIDIA/Model-Optimizer#1667 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[ONNX PTQ] trt_plugins_precision keeps only the last fp16/fp32 entry when several custom op types are listedCó thể đã có người làm @uditstocks đã nhận hôm nay. Đang mởbug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 25/100
NVIDIA/Model-Optimizer#3514 ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của NVIDIA/Model-Optimizer
Issue tương tự
-
bot-triaged module: correctness (silent) module: fft triage review
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Remove Python pin in recipeĐang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 78/100
conda-forge/zarpaint-feedstock#8 · 1 bình luận · 1 reaction ·
-
plot_prediction colorbar shows a 0-1 range instead of the data rangeCó thể đã có người làm @nikhil3495 đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
mllam/neural-lam#902 ·
Maintainer thường phản hồi trong vòng 2 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
didi/helixharness#28 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
【文档错误】创建镜像空间步骤中的截图标注与文字描述不一致Đang mởenhancement
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 62/100
DaoCloud/DaoCloud-docs#7839 ·
Maintainer thường phản hồi trong vòng 1 ngày