TRT 11.3: Attention does not compile inside If, even with decomposable=True
Maintainer thường phản hồi trong vòng 6 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 48/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Khá rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Lĩnh vực
- compilers, machine-learning
Hướng nghiên cứu
Start with repro_attention_in_if_trt.py and run the failing If cases alongside --no-if and --decomposed controls. Trace parsing through trt.OnnxParser, ATTENTION_INPUT handling, and builder.build_serialized_network to isolate the If-specific failure. Done means the If model builds successfully with and without --decomposable while the existing controls remain successful.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Description
ONNX model in opset 23 of shape If { Attention } leads to internal Myelin error
[TRT] [E] Error Code: 9: Skipping tactic 0x0000000000000000 due to exception [ir_op_builder.cpp:249: myelinOpSetInput] Called with unknown input tensor or sequence name "(Unnamed Layer* 9) [ElementWise]_output". In createMyelinOp at /_src/optimizer/myelin/codeGenerator.h:1478
[TRT] [E] IBuilder::buildSerializedNetwork: Error Code 10: Internal Error (Could not find any implementation for node {ForeignNode[ONNXTRT_convertToScalar...node_of_Y_OutputLayer]}. In computeCosts at /_src/optimizer/common/tactic/optimizer.cpp:4211)
Plain Attention builds fine, only needing decomposable=True sometimes.
Environment
TensorRT Version: 11.3.0.99
NVIDIA GPU: RTX PRO 6000 Blackwell Server Edition
NVIDIA Driver Version: 580.173.02
CUDA Version: CUDA runtime 12.9 (nvidia-cuda-runtime-cu12==12.9.79, libcudart.so.12); driver libcuda.so.580.173.02
CUDNN Version: -
Operating System: Ubuntu 20.04.6 pod on kernel 6.18
Python Version (if applicable): 3.11.16
Tensorflow Version (if applicable): -
PyTorch Version (if applicable): -
Steps To Reproduce
import argparse
import sys
import numpy as np
import onnx
from onnx import TensorProto, helper
try:
import tensorrt as trt
except ImportError:
import tensorrt_bindings as trt
ap = argparse.ArgumentParser()
ap.add_argument("--decomposable", action="store_true")
ap.add_argument("--else", dest="else_op", default="identity", choices=["identity", "mul"])
ap.add_argument("--no-if", action="store_true", help="control: Attention at top level, no If")
ap.add_argument("--decomposed", action="store_true", help="control: opset-18 MatMul/Softmax form instead of Attention")
ap.add_argument("--dtype", default="fp32", choices=["fp32", "fp16"])
ap.add_argument("--shape", default="1,1,4,8")
args = ap.parse_args()
elem = TensorProto.FLOAT if args.dtype == "fp32" else TensorProto.FLOAT16
np_dtype = np.float32 if args.dtype == "fp32" else np.float16
shape = [int(s) for s in args.shape.split(",")]
opset = 18 if args.decomposed else 23
def attention_nodes(out: str) -> list:
if not args.decomposed:
return [helper.make_node("Attention", ["Q", "K", "V"], [out])]
return [
helper.make_node("Transpose", ["K"], ["KT"], perm=[0, 1, 3, 2]),
helper.make_node("MatMul", ["Q", "KT"], ["S"]),
helper.make_node("Mul", ["S", "scale"], ["SS"]),
helper.make_node("Softmax", ["SS"], ["P"], axis=-1),
helper.make_node("MatMul", ["P", "V"], [out]),
]
initializers = [helper.make_tensor("scale", elem, [], np.array([1.0 / np.sqrt(shape[-1])], dtype=np_dtype).tolist()),
helper.make_tensor("two", elem, [], np.array([2.0], dtype=np_dtype).tolist())]
qkv = [helper.make_tensor_value_info(n, elem, shape) for n in ("Q", "K", "V")]
y = helper.make_tensor_value_info("Y", elem, shape)
if args.no_if:
graph = helper.make_graph(attention_nodes("Y"), "attn", qkv, [y], initializer=initializers)
else:
cond = helper.make_tensor_value_info("cond", TensorProto.BOOL, [1])
then_g = helper.make_graph(attention_nodes("Yt"), "then", [], [helper.make_tensor_value_info("Yt", elem, shape)])
else_node = (helper.make_node("Identity", ["Q"], ["Ye"]) if args.else_op == "identity"
else helper.make_node("Mul", ["Q", "two"], ["Ye"]))
else_g = helper.make_graph([else_node], "else", [], [helper.make_tensor_value_info("Ye", elem, shape)])
if_node = helper.make_node("If", ["cond"], ["Y"], then_branch=then_g, else_branch=else_g)
graph = helper.make_graph([if_node], "attn_in_if", [cond, *qkv], [y], initializer=initializers)
model = helper.make_model(graph, opset_imports=[helper.make_opsetid("", opset)], ir_version=10)
onnx.checker.check_model(model)
logger = trt.Logger(trt.Logger.WARNING)
builder = trt.Builder(logger)
network = builder.create_network(0)
parser = trt.OnnxParser(network, logger)
if not parser.parse(model.SerializeToString(), "attention_in_if.onnx"):
sys.exit("\n".join(str(parser.get_error(i)) for i in range(parser.num_errors)))
n_attn = 0
for i in range(network.num_layers):
layer = network.get_layer(i)
if layer.type == trt.LayerType.ATTENTION_INPUT:
n_attn += 1
if args.decomposable:
layer.__class__ = trt.IAttentionInputLayer
layer.attention.decomposable = True
config = builder.create_builder_config()
config.clear_flag(trt.BuilderFlag.TF32)
plan = builder.build_serialized_network(network, config)
print(f"tensorrt {trt.__version__} if={not args.no_if} else={args.else_op} decomposed_onnx={args.decomposed} "
f"dtype={args.dtype} shape={shape} attention_layers={n_attn} decomposable={args.decomposable}: "
+ ("BUILD OK" if plan is not None else "BUILD FAILED"), flush=True)
sys.exit(0 if plan is not None else 1)
Commands or scripts:
Save provided script as repro_attention_in_if_trt.py
Bug is reproduced when you run it with and without --decomposable
Controls:
pre-decomposed --decomposed works fine (opset 18 does not have Attention)
without if --no-if works fine, maybe requiring --decomposable
Have you tried the latest release?: yes
Can this model run on other frameworks? For example run ONNX model with ONNXRuntime (polygraphy run <model.onnx> --onnxrt):
- Ngôn ngữ chính
- C++
- Star
- 13.5k
- Fork
- 2.4k
- Merge trung bình
- 6 ngày 21 giờ
- Pull request đã merge (30 ngày)
- 3
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không 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/TensorRT
-
Module:Polygraphy
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 77/100
Maintainer thường phản hồi trong vòng 6 ngày
-
Polygraphy NumPy Top-K sorts unsigned and minimum signed integers incorrectlyCó thể đã có người làm @0z5a đã nhận 16 ngày trước. Đang mởModule:Polygraphy
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 6 ngày
-
Polygraphy INT32 comparison can overflow and falsely pass at zero toleranceCó thể đã có người làm @0z5a đã nhận 16 ngày trước. Đang mởModule:Polygraphy
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 6 ngày
-
onnx-graphsurgeon: Graph.toposort() hits RecursionError when a graph has a local function and an If/Loop nodeCó thể đã có người làm @gabortar đã nhận 39 ngày trước. Đang mởModule:GraphSurgeon
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
Maintainer thường phản hồi trong vòng 6 ngày
-
Polygraphy parse_meta accepts a shape with a missing bracketCó thể đã có người làm @SashaMIT đã nhận 51 ngày trước. Đang mởModule:Polygraphy
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 86/100
Maintainer thường phản hồi trong vòng 6 ngày
Tất cả issue của NVIDIA/TensorRT
Issue tương tự
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 91/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 69/100
maplibre/maplibre-native#5072 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[UBSan] spawn_simulator passes null child_options.args to uv_spawn (execvp nonnull violation)Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 79/100
tenstorrent/tt-umd#4017 ·
Maintainer thường phản hồi trong vòng 3 ngày
-
difficulty:easy func:gui prio:low type:bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
NatronGitHub/Natron#1538 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
hyprwm/hyprsunset#103 · 1 bình luận ·