Description
I fail to build the TRT Engine of a 2-GatherND-GEMM model when maxShape’s first dim >= 16043:
The onnx model can be generated via follow torch code:
import torch
import torch.nn as nn
class GatherNDModel(nn.Module):
def __init__(self, depth=2, channels=36):
super().__init__()
self.depth = depth
self.channels = channels
self.proj = nn.Linear(channels, channels)
def forward(self, x, order):
y = x
for _ in range(self.depth):
y = y[order] # this will cause TRT Engine build failed
# y = torch.index_select(y, 0, order)
y = self.proj(y)
return y
def generate_input(self, device="cuda"):
num_points = 1000
x = torch.randn(num_points, self.channels, device=device)
order = torch.randint(0, num_points, (num_points,), device=device)
return x, order
def input_names(self):
return ["x", "order"]
def output_names(self):
return ["y"]
def dynamic_shapes(self):
return {
"x": {0: "num_points"},
"order": {0: "num_points"}
}
if __name__ == "__main__":
model = GatherNDModel()
model.cuda()
model.eval()
x, order = model.generate_input()
y = model(x, order)
print(y.shape)
# export onnx
inputs = (x, order)
input_names = model.input_names()
output_names = model.output_names()
dynamic_shapes = model.dynamic_shapes()
custom_translation_table = {}
onnx_path = "gathernd_model.onnx"
torch.onnx.export(
model,
inputs,
onnx_path,
input_names=input_names,
output_names=output_names,
dynamo=True,
report=True,
dynamic_shapes=dynamic_shapes,
custom_translation_table=custom_translation_table,
)
import onnx
try:
onnx.checker.check_model(onnx_path, full_check=True)
print(f"[onnx.checker] {onnx_path} passed structural + shape checks.")
except onnx.checker.ValidationError as e:
print(f"[onnx.checker] validation failed: {e}")
I use following command to build TRT Engine:
trtexec \
--onnx=gathernd_model.onnx \
--minShapes=x:1x36,order:1 \
--optShapes=x:1145x36,order:1145 \
--maxShapes=x:16043x36,order:16043 \
--saveEngine=gathernd_model.engine \
--fp16 \
--skipInference --builderOptimizationLevel=0 --verbose > trt_build.log 2>&1
log output:
[05/01/2026-19:31:06] [V] [TRT] Set number of tactics to 1 at optimization level 0
Internal Error: MyelinCheckException: nvrtc_compile.cpp:1118: CHECK(success) failed. NVRTC Compilation failure
[05/01/2026-19:31:09] [E] Error[9]: Error Code: 9: Skipping tactic 0x0000000000000000 due to exception [myelin_graph.h:1182: attachExceptionMsgToGraph] MyelinCheckException: nvrtc_compile.cpp:1118: CHECK(success) failed. NVRTC Compilation failure In compileGraph at /_src/optimizer/myelin/codeGenerator.cpp:1548
[05/01/2026-19:31:09] [V] [TRT] {ForeignNode[node_Unsqueeze_5...y_castOut]} (Myelin[0x80000023]) profiling completed in 2.75539 seconds. Fastest Tactic: 0xd15ea5edd15ea5ed Time: inf
[05/01/2026-19:31:09] [E] Error[10]: IBuilder::buildSerializedNetworkToStream: Error Code 10: Internal Error (Could not find any implementation for node {ForeignNode[node_Unsqueeze_5...y_castOut]}. In computeCosts at /_src/optimizer/common/tactic/optimizer.cpp:4143)
[05/01/2026-19:31:09] [I] Created engine with size: 0 MiB
[05/01/2026-19:31:09] [I] Engine built in 3.01337 sec.
[05/01/2026-19:31:09] [E] Assertion failure: false && "Attempting to access an empty engine!"
[gathernd\_issue.zip|attachment](upload://miumjuBDDQflV2mcQpz0YmJ77Pf.zip) (13.6 KB)
Let x be in shape [num_pts, 36]. Something observation:
- If
self.depth>1, the maximal successful num_pts is always 16042 (increasing depth will not decrease the num_pts). - If
self.depth=1, num_pts can be larger than 16042 (e.g.: 16043, 160420). - If
self.proj(GEMM ONNX node) is removed from the forward function, num_pts can be larger than 16042 for any depth. - If
y = y[order](GatherND ONNX node) is replaced byy = torch.index_select(y, 0, order)(Gather ONNX node), num_pts can be larger than 16042 for any depth.
I am wondering whether this issue is caused by TRT support for GatherND ONNX node.
The 2-depth onnx model and logs are attached. Thanks for help!
Environment
TensorRT Version: 10.14.1.48
GPU Type: NVIDIA RTX PRO 6000 Blackwell Server Edition
Nvidia Driver Version: 580.105.08
CUDA Version: 13.0
CUDNN Version: 9.14.0
Operating System + Version: ubuntu 22.04
Python Version (if applicable): 3.13.12
TensorFlow Version (if applicable):
PyTorch Version (if applicable): 2.11.0+cu130
Baremetal or Container (if container which image + tag): nvcr.io/nvidia/cuda:13.0.2-cudnn-devel-ubuntu22.04
ONNX related Version:
$ pip list | grep onnx
onnx 1.21.0
onnx-ir 0.2.0
onnxruntime 1.24.4
onnxscript 0.6.2
Relevant Files
Please attach or include links to any models, data, files, or scripts necessary to reproduce your issue. (Github repo, Google Drive, Dropbox, etc.)
Steps To Reproduce
Please include:
- Exact steps/commands to build your repro
- Exact steps/commands to run your repro
- Full traceback of errors encountered
gathernd_issue.zip (13.6 KB)
