TRT 11.3: Attention does not compile inside If, even with decomposable=True

オープン
#4,860 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 6 日以内に返信

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
48/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
活発
技術スタック
cpp, python

調査の方向性

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.

索引モデルが issue の本文から書いたものです。

説明

Module:ONNX

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):

主要言語
C++
スター
13.5k
フォーク
2.4k
平均マージ
6日 21時間
マージ済み PR(30日)
3

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

NVIDIA/TensorRT のほかの issue

NVIDIA/TensorRT の issue をすべて見る

似ている issue

C++ の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。