NVIDIA / TensorRT

NVIDIA® TensorRT™ is an SDK for high-performance deep learning inference on NVIDIA GPUs. This repository contains the open source components of TensorRT.
https://developer.nvidia.com/tensorrt
Apache License 2.0
10.72k stars 2.12k forks source link

AttributeError: 'tensorrt_bindings.tensorrt.ICudaEngine' object has no attribute 'num_bindings' #4216

Open metehanozdeniz opened 6 days ago

metehanozdeniz commented 6 days ago

Description

I encounter this error when I try to extract results from the TensorRT engine.

Environment

TensorRT Version: 10.5.0

NVIDIA GPU: RTX 3050

NVIDIA Driver Version: 565.90

CUDA Version: 12.7

CUDNN Version:

Operating System: Ubuntu 24.04.1 LTS

Python Version (if applicable): 3.10.9

Tensorflow Version (if applicable): 2.15.0

PyTorch Version (if applicable):

Baremetal or Container (if so, version):

Relevant Files

Model link:

Steps To Reproduce

Commands or scripts:

# Infer TensorRT Engine
Binding = namedtuple('Binding', ('name', 'dtype', 'shape', 'data', 'ptr'))
logger = trt.Logger(trt.Logger.INFO)
trt.init_libnvinfer_plugins(logger, namespace="")
with open(w, 'rb') as f, trt.Runtime(logger) as runtime:
    model = runtime.deserialize_cuda_engine(f.read())
bindings = OrderedDict()
for index in range(model.num_bindings):
    name = model.get_binding_name(index)
    dtype = trt.nptype(model.get_binding_dtype(index))
    shape = tuple(model.get_binding_shape(index))
    data = torch.from_numpy(np.empty(shape, dtype=np.dtype(dtype))).to(device)
    bindings[name] = Binding(name, dtype, shape, data, int(data.data_ptr()))
binding_addrs = OrderedDict((n, d.ptr) for n, d in bindings.items())
context = model.create_execution_context()

output:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[10], line 8
      6     model = runtime.deserialize_cuda_engine(f.read())
      7 bindings = OrderedDict()
----> 8 for index in range(model.num_bindings):
      9     name = model.get_binding_name(index)
     10     dtype = trt.nptype(model.get_binding_dtype(index))

AttributeError: 'tensorrt_bindings.tensorrt.ICudaEngine' object has no attribute 'num_bindings'

Have you tried the latest release?:

Can this model run on other frameworks? For example run ONNX model with ONNXRuntime (polygraphy run <model.onnx> --onnxrt):

lix19937 commented 5 days ago

Use num_io_tensors. @metehanozdeniz

yuanyao-nv commented 32 minutes ago

Please refer to the python API guide: https://docs.nvidia.com/deeplearning/tensorrt/api/python_api/infer/Core/Engine.html#tensorrt.ICudaEngine