question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

'Tensor' object has no attribute '_trt'

See original GitHub issue

I get error AttributeError: 'Tensor' object has no attribute '_trt' when I meet MaxPool2d

/usr/local/lib/python3.6/dist-packages/torch2trt-0.0.0-py3.6.egg/torch2trt/torch2trt.py in wrapper(*args, **kwargs) 95 96 #print(‘%s : %s’ % (method.qualname, converter.name)) —> 97 converter(ctx) 98 99 # convert to None so conversion will fail for unsupported layers

/usr/local/lib/python3.6/dist-packages/torch2trt-0.0.0-py3.6.egg/torch2trt/converters/MaxPool2d.py in convert_MaxPool2d(ctx) 21 22 layer = ctx.network.add_pooling( —> 23 input=input._trt, type=trt.PoolingType.MAX, window_size=kernel_size) 24 layer.stride = stride 25 layer.padding = padding

AttributeError: ‘Tensor’ object has no attribute ‘_trt’

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:3
  • Comments:12 (4 by maintainers)

github_iconTop GitHub Comments

6reactions
vfdev-5commented, Jul 25, 2019

HI @jaybdub ,

I’m trying to reproduce image segmentation example of this tutorial (Deeplabv3 model) and I have the following issue as in this topic.

Click to see the log

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-8-7f1400d9157d> in <module>
----> 1 model_trt = torch2trt.torch2trt(model_w, [data], fp16_mode=True)

~/miniconda3/envs/py35/lib/python3.5/site-packages/torch2trt-0.0.0-py3.5.egg/torch2trt/torch2trt.py in torch2trt(module, inputs, input_names, output_names, log_level, max_batch_size, fp16_mode, max_workspace_size)
    250         ctx.add_inputs(inputs, input_names)
    251 
--> 252         outputs = module(*inputs)
    253 
    254         if not isinstance(outputs, tuple):

~/miniconda3/envs/py35/lib/python3.5/site-packages/torch/nn/modules/module.py in __call__(self, *input, **kwargs)
    491             result = self._slow_forward(*input, **kwargs)
    492         else:
--> 493             result = self.forward(*input, **kwargs)
    494         for hook in self._forward_hooks.values():
    495             hook_result = hook(self, input, result)

<ipython-input-5-405ea0677ccc> in forward(self, x)
      4         self.model = model
      5     def forward(self, x):
----> 6         return model(x)['out']

~/miniconda3/envs/py35/lib/python3.5/site-packages/torch/nn/modules/module.py in __call__(self, *input, **kwargs)
    491             result = self._slow_forward(*input, **kwargs)
    492         else:
--> 493             result = self.forward(*input, **kwargs)
    494         for hook in self._forward_hooks.values():
    495             hook_result = hook(self, input, result)

~/miniconda3/envs/py35/lib/python3.5/site-packages/torchvision/models/segmentation/_utils.py in forward(self, x)
     20         result = OrderedDict()
     21         x = features["out"]
---> 22         x = self.classifier(x)
     23         x = F.interpolate(x, size=input_shape, mode='bilinear', align_corners=False)
     24         result["out"] = x

~/miniconda3/envs/py35/lib/python3.5/site-packages/torch/nn/modules/module.py in __call__(self, *input, **kwargs)
    491             result = self._slow_forward(*input, **kwargs)
    492         else:
--> 493             result = self.forward(*input, **kwargs)
    494         for hook in self._forward_hooks.values():
    495             hook_result = hook(self, input, result)

~/miniconda3/envs/py35/lib/python3.5/site-packages/torch/nn/modules/container.py in forward(self, input)
     90     def forward(self, input):
     91         for module in self._modules.values():
---> 92             input = module(input)
     93         return input
     94 

~/miniconda3/envs/py35/lib/python3.5/site-packages/torch/nn/modules/module.py in __call__(self, *input, **kwargs)
    491             result = self._slow_forward(*input, **kwargs)
    492         else:
--> 493             result = self.forward(*input, **kwargs)
    494         for hook in self._forward_hooks.values():
    495             hook_result = hook(self, input, result)

~/miniconda3/envs/py35/lib/python3.5/site-packages/torchvision/models/segmentation/deeplabv3.py in forward(self, x)
     90         for conv in self.convs:
     91             res.append(conv(x))
---> 92         res = torch.cat(res, dim=1)
     93         return self.project(res)

~/miniconda3/envs/py35/lib/python3.5/site-packages/torch2trt-0.0.0-py3.5.egg/torch2trt/torch2trt.py in wrapper(*args, **kwargs)
     95 
     96             #print('%s : %s' % (method.__qualname__, converter.__name__))
---> 97             converter(ctx)
     98 
     99             # convert to None so conversion will fail for unsupported layers

~/miniconda3/envs/py35/lib/python3.5/site-packages/torch2trt-0.0.0-py3.5.egg/torch2trt/converters/cat.py in convert_cat(ctx)
     12 
     13     output = ctx.method_return
---> 14     trt_inputs = [i._trt for i in inputs]
     15 
     16     layer = ctx.network.add_concatenation(inputs=trt_inputs)

~/miniconda3/envs/py35/lib/python3.5/site-packages/torch2trt-0.0.0-py3.5.egg/torch2trt/converters/cat.py in <listcomp>(.0)
     12 
     13     output = ctx.method_return
---> 14     trt_inputs = [i._trt for i in inputs]
     15 
     16     layer = ctx.network.add_concatenation(inputs=trt_inputs)

AttributeError: 'Tensor' object has no attribute '_trt'

Any ideas why it does not work ?

Packages Versions

``` # packages in environment at /root/miniconda3/envs/py35: # # Name Version Build Channel _libgcc_mutex 0.1 main attrs 19.1.0 pypi_0 pypi backcall 0.1.0 pypi_0 pypi blas 1.0 mkl bleach 3.1.0 pypi_0 pypi ca-certificates 2019.5.15 0 certifi 2018.8.24 py35_1 cffi 1.11.5 py35he75722e_1 cudatoolkit 10.0.130 0 decorator 4.4.0 pypi_0 pypi defusedxml 0.6.0 pypi_0 pypi entrypoints 0.3 pypi_0 pypi freetype 2.9.1 h8a8886c_1 intel-openmp 2019.4 243 ipykernel 5.1.1 pypi_0 pypi ipython 7.6.1 pypi_0 pypi ipython-genutils 0.2.0 pypi_0 pypi ipywidgets 7.5.0 pypi_0 pypi jedi 0.14.1 pypi_0 pypi jinja2 2.10.1 pypi_0 pypi jpeg 9b h024ee3a_2 jsonschema 3.0.1 pypi_0 pypi jupyter 1.0.0 pypi_0 pypi jupyter-client 5.3.1 pypi_0 pypi jupyter-console 6.0.0 pypi_0 pypi jupyter-core 4.5.0 pypi_0 pypi libedit 3.1.20181209 hc058e9b_0 libffi 3.2.1 hd88cf55_4 libgcc-ng 9.1.0 hdf63c60_0 libgfortran-ng 7.3.0 hdf63c60_0 libpng 1.6.37 hbc83047_0 libstdcxx-ng 9.1.0 hdf63c60_0 libtiff 4.0.10 h2733197_2 markupsafe 1.1.1 pypi_0 pypi mistune 0.8.4 pypi_0 pypi mkl 2019.4 243 nbconvert 5.5.0 pypi_0 pypi nbformat 4.4.0 pypi_0 pypi ncurses 6.1 he6710b0_1 ninja 1.8.2 py35h6bb024c_1 notebook 6.0.0 pypi_0 pypi numpy 1.14.2 py35hdbf6ddf_0 olefile 0.46 py35_0 openssl 1.0.2s h7b6447c_0 pandocfilters 1.4.2 pypi_0 pypi parso 0.5.1 pypi_0 pypi pexpect 4.7.0 pypi_0 pypi pickleshare 0.7.5 pypi_0 pypi pillow 5.2.0 py35heded4f4_0 pip 10.0.1 py35_0 prometheus-client 0.7.1 pypi_0 pypi prompt-toolkit 2.0.9 pypi_0 pypi ptyprocess 0.6.0 pypi_0 pypi pycparser 2.19 py35_0 pygments 2.4.2 pypi_0 pypi pyrsistent 0.15.3 pypi_0 pypi python 3.5.6 hc3d631a_0 python-dateutil 2.8.0 pypi_0 pypi pytorch 1.1.0 py3.5_cuda10.0.130_cudnn7.5.1_0 pytorch pyzmq 18.0.2 pypi_0 pypi qtconsole 4.5.2 pypi_0 pypi readline 7.0 h7b6447c_5 send2trash 1.5.0 pypi_0 pypi setuptools 40.2.0 py35_0 six 1.11.0 py35_1 sqlite 3.29.0 h7b6447c_0 terminado 0.8.2 pypi_0 pypi testpath 0.4.2 pypi_0 pypi tk 8.6.8 hbc83047_0 torch2trt 0.0.0 pypi_0 pypi torchvision 0.3.0 py35_cu10.0.130_1 pytorch tornado 6.0.3 pypi_0 pypi traitlets 4.3.2 pypi_0 pypi wcwidth 0.1.7 pypi_0 pypi webencodings 0.5.1 pypi_0 pypi wheel 0.31.1 py35_0 widgetsnbextension 3.5.0 pypi_0 pypi xz 5.2.4 h14c3975_4 zlib 1.2.11 h7b6447c_3 zstd 1.3.7 h0b5b093_0 ```
2reactions
jaybdubcommented, Jul 11, 2019

Hi All,

This is most likely because there Is a layer converter that has not been implemented. It is likely the layer before the one that threw the error (because the _trt was not set by the previous converter).

We’re focused on supporting the models in the README, but the coverage may increase over time.

@gavrin-s are you able to share the model you’re attempting to convert?

FYI, You can see the list of registered converters by typing

‘’’python import torch2trt

print(torch2trt.CONVERTERS) ‘’’

It may be possible to add support for the unsupported layers by using the ‘’@tensorrt_converter’’ method described in the README.md.

Please let me know if this helps or you have any other questions.

Best, John

Read more comments on GitHub >

github_iconTop Results From Across the Web

AttributeError: 'Tensor' object has no attribute 'close'
The object that you are calling close on is actually a tensor , not a file. You need to review how that object...
Read more >
Object has no attribute 'parameters' - Hugging Face Forums
I am running the following code:- from tqdm.auto import tqdm progress_bar = tqdm(range(num_training_steps)) model.train() for epoch in range(num_epochs): ...
Read more >
PYTHON : AttributeError: 'Tensor' object has no attribute 'numpy'
PYTHON : AttributeError: ' Tensor ' object has no attribute 'numpy' [ Gift : Animated Search Engine : https://www.hows.tech/p/recommended.html ] ...
Read more >
TF-TRT breaking on simple MNIST model - Jetson AGX Xavier
import tensorflow as tf import tensorflow_datasets as tfds (ds_train, ... AttributeError: '_UserObject' object has no attribute 'add_slot'.
Read more >
'nonetype' object has no attribute 'create_execution_context'
TensorRT 推理AttributeError: 'NoneType' object has no attribute 'create_execution_context'出错原因与解决 在出错的这一行打个断点,发现`engine = runtime.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found