AttributeError: 'tensorrt_bindings.tensorrt.ICudaEngine' object has no attribute 'num_bindings'
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 13.4k
- Forks
- 2.4k
- Avg merge
- 5d 3h
- Merged PRs (30d)
- 2
Description
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):
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the provided TensorRT 10.5.0 reproduction, especially the loop over model.num_bindings and the calls to get_binding_name, get_binding_dtype, and get_binding_shape. Check the current TensorRT engine API and run the script again; done means the engine can be inspected and results extracted without this AttributeError.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- machine-learning
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 30/100