Repository navigation
Closed
Labels
bugSomething isn't working
Description
Bug Description
After installing the TensorRT with the pip wheel installation, which is among the dependencies listed in the installation guide, and then installing torch_tensorrt from the python package, I get an error when I import torch_tensorrt.
This is somewhat simmilar to Issue #887. But I dont think the LD_LIBRARY_PATH solutiuon applies to a pip installation.
To Reproduce
Steps to reproduce the behavior:
- Create new anaconda environment.
conda install pytorch torchvision cudatoolkit=11.3 -c pytorch- Install TensorRT via pip wheel as in section 2.3 of the Quick Start Guide with
python -m pip install --upgrade nvidia-tensorrt - Acknowledge this sencence from the Quick Start Guide "The above pip command will pull in all the required CUDA libraries and cuDNN in Python wheel format because they are dependencies of the TensorRT Python wheel"
- Verify TensorRT installation
python3
import tensorrt
print(tensorrt.__version__)
assert tensorrt.Builder(tensorrt.Logger())
- Install torch-tensorrt
pip install torch-tensorrt -f https://github.com/NVIDIA/Torch-TensorRT/releases - Import torch_tensorrt in python
>>> import torch
>>> torch.version.cuda
'11.3'
>>> import torch_tensorrt
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/lennux/anaconda3/envs/omct/lib/python3.7/site-packages/torch_tensorrt/__init__.py", line 11, in <module>
from torch_tensorrt._compile import *
File "/home/lennux/anaconda3/envs/omct/lib/python3.7/site-packages/torch_tensorrt/_compile.py", line 2, in <module>
from torch_tensorrt import _enums
File "/home/lennux/anaconda3/envs/omct/lib/python3.7/site-packages/torch_tensorrt/_enums.py", line 1, in <module>
from torch_tensorrt._C import dtype, DeviceType, EngineCapability, TensorFormat
ImportError: libnvinfer_plugin.so.8: cannot open shared object file: No such file or directory
Expected behavior
Environment
Build information about Torch-TensorRT can be found by turning on debug messages
- Torch-TensorRT Version (e.g. 1.0.0): 1.0.0
- PyTorch Version (e.g. 1.0): 1.11.0
- CPU Architecture: x86_64
- OS (e.g., Linux): Ubuntu 20.4
- How you installed PyTorch (
conda,pip,libtorch, source):conda install pytorch torchvision cudatoolkit=11.3 -c pytorch - Build command you used (if compiling from source): -
- Are you using local sources or building from archives: -
- Python version: 3.7.7
- CUDA version: Came with pytorch, so (11.3)
- GPU models and configuration: RTX 2060
Additional context
I know about the contained solution for torch_tensorrt. It works great and I'm building an application meant for deployment inside of the container. But for ease of debugging and general prototype development in a small dev team I need to get torch_tensorrt running locally.
Metadata
Metadata
Assignees
Labels
bugSomething isn't working
Activity
narendasan commentedon May 6, 2022
The TensorRT libraries need to be in your LD_LIBRARY_PATH
lennartmoritz commentedon May 6, 2022
Okay, I tried to make sense of what I expect the LD_LIBRARY_PATH needs to point to with this pip installation.
I believe it should be
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/lennux/anaconda3/envs/omct/lib/python3.7/site-packages/tensorrtin my case.Below I'll add a screenshot showing on the left what would be linked in the LD_LIBRARY_PATH for a tar file installation of TensorRT, and on the right what I could find in the folder of my pip installation.
After exporting that path i try to import torch_tensorrt again and I get a new error.
ImportError: (...)/lib/libtorchtrt.so: undefined symbol: _ZNK3c104Type14isSubtypeOfExtERKSt10shared_ptrIS0_EPSoThis is where I'm stuck now. Do you think the pip installation of TensorRT is incompatible for supporting Torch-TensorRT?
lennartmoritz commentedon May 6, 2022
Okay, I fixed the issue. Importing torch_tensorrt is now working but to load my model I had to update to Torch-TensorRT 1.1.0, the same as in the containered version. For future reades I will include a step by step guide on how to install Torch-TensorRT 1.0.0 on Ubuntu 20.4 in an easy way. This also works for version 1.1.0 if you change the version numbers in the guide to the currently supported ones.
In short:
I had to downgrade my pytorch version to 1.10 and the TensorRT version to 8.0.3.4. But I think it was only necessary to to downgrade pytorch.
Details:
After researching the ImportError I figured it was likely caused by a PyTorch version missmatch. To figure out which versions can be used I went to the Torch-TensorRT Release Notes, which state:
The confusing thing is that the Release Notes also state that:
But the public release of Torch-TensorRT 1.0.0 is never used in any container. Instead they use either 1.0.0a0 or 1.1.0a0 as of the time of my issue.
I got fooled and thought I can use the same dependencies as the NVIDIA Pytorch Container > PyTorch Container Release Notes > PyTorch Release 21.11 that uses Torch-TensorRT 1.0.0a0 for the public release of 1.0.0 which is not the case.
The most recent container with version 1.0.0a0 is PyTorch Release 21.11. The listed compatible versions are PyTorch 1.11.0a0+b6df043 and TensorRT 8.0.3.4 for x64 Linux.
So even though I got it to work with TensorRT 8.0.3.4 I could not use PyTorch 1.11.0.
How to easily install Torch-TensorRT 1.0.0 without docker on Ubuntu:
Prerequisites:
conda install pytorch==1.10.0 torchvision==0.11.0 torchaudio==0.10.0 cudatoolkit=11.3 -c pytorch -c conda-forgepython -m pip install --upgrade nvidia-tensorrtpip install torch-tensorrt==1.0.0 -f https://github.com/NVIDIA/Torch-TensorRT/releasesexport LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/lennux/anaconda3/envs/omct/lib/python3.7/site-packages/tensorrtin my case.import tensorrtbefore importing torch_tensorrtmahmoudhussein99 commentedon Jul 10, 2022
I have tried this and again it gives me the same old error
from torch_tensorrt._C import dtype, DeviceType, EngineCapability, TensorFormat ImportError: libcudnn.so.8: cannot open shared object file: No such file or directoryNot sure what to do to fix it. Your Help is appreciated!!
lennartmoritz commentedon Jul 10, 2022
Did you follow all the steps @mahmoudhussein99? This guide worked for me on Ubuntu 20.4, if you are not using Linux I am not sure if my guide will work for you.
In particular, you must export your LD_LIBRARY_PATH, as described in steps 6 and 7. Make sure the path acutally leads to your tensorrt installation. Can you confirm that libcudnn.so.8 is acutally present within the folder of the LD_LIBRARY_PATH that you are exporting. And can you confirm that the correct LD_LIBRARY_PATH is set from the terminal you use to start your python script eg by running
echo $LD_LIBRARY_PATHin it?And import tensorrt first in your code, before you import torch_tensorrt . Otherwise a necessary cudnn dependency may not be found.
I would also recommend you try it with TensorRT 1.1.0 instead of 1.0.0. for the new features.
mahmoudhussein99 commentedon Jul 14, 2022
Okay first of all thank you for your help that is really appreciated!
After several days trying turned out that there was a function call calling import torch_tensorrt before the import to tensorrt and that was the bug
Also to mention, I tried it without exporting the LD_LIBRARY_PATH as in steps 6 and 7 and works normally, the key is to import tensorrt before and then all the modules will be visible to the environment
if it helps sharing with others also the configuration that worked with me:
python 3.9.4
nvidia-cublas-cu11 2022.4.8
nvidia-cublas-cu117 11.10.1.25
nvidia-cuda-runtime-cu11 2022.4.25
nvidia-cuda-runtime-cu117 11.7.60
nvidia-cudnn-cu11 2022.5.19
nvidia-cudnn-cu116 8.4.0.27
nvidia-pyindex 1.0.9
nvidia-tensorrt 8.2.4.2
torch 1.11.0+cu113
torch-tensorrt 1.1.0
torchaudio 0.11.0+cu113
torchvision 0.12.0+cu113
Having this configuration without exporting the LD_LIBRARY_PATH works straight away but please make sure to import tensorrt before importing torch_tensorrt
jpalladino-fy commentedon Feb 25, 2023
Thank you so much @mahmoudhussein99! 🙌