Mix CUDA versions between PyTorch and LibTorch?

Hi,

In my computer I have CUDA 11.1 installed as a requirement for a certain project. In parallel, I’m developing a PyTorch model in a conda environment using cudatoolkit==11.0 (because I couldn’t find pytorch for 11.1), and so far it’s working well. Now I need to export the trained network to use in C++ using LibTorch (which I’m familiar with from another project in another computer), but from the website there’s only the option for CUDA 10.2 and 11.3, so I downloaded the later.

However, when trying to build the C++ app linking the LibTorch libraries I’m getting some compilation errors:

/usr/bin/ld: /opt/libtorch/lib/libtorch_cuda_cpp.so: undefined reference to `cudaStreamUpdateCaptureDependencies@libcudart.so.11.0'
/usr/bin/ld: /opt/libtorch/lib/libtorch_cuda_cpp.so: undefined reference to `cudaStreamGetCaptureInfo_v2@libcudart.so.11.0'
/usr/bin/ld: /opt/libtorch/lib/libtorch_cuda_cu.so: undefined reference to `cudaFreeAsync@libcudart.so.11.0'
/usr/bin/ld: /opt/libtorch/lib/libtorch_cuda_cu.so: undefined reference to `cudaMallocAsync@libcudart.so.11.0'
/usr/bin/ld: /opt/libtorch/lib/libtorch_cuda_cpp.so: undefined reference to `cudaGraphRetainUserObject@libcudart.so.11.0'
/usr/bin/ld: /opt/libtorch/lib/libtorch_cuda_cpp.so: undefined reference to `cudaUserObjectCreate@libcudart.so.11.0

My limited knowledge tells me that it’s because of the mismatch between the used and installed CUDA versions. Is there a way to make it work without changing the installed CUDA 11.1?

Thank you,
Marc

How are you installing pytorch? e.g., would a command like
pip install torch==1.10.1+cu111 torchvision==0.11.2+cu111 torchaudio==0.10.1 -f https://download.pytorch.org/whl/torch_stable.html work?

I’m installing it with conda. I did it with conda install pytorch==1.7.1 torchvision==0.8.2 torchaudio==0.7.2 cudatoolkit=11.0 -c pytorch because I couldn’t find cudatoolkit 11.1.

However, regardless of the Python PyTorch version, I believe the issue is with the fact that LibTorch is not available for CUDA 11.1 but for 11.3 instead? How can I make both work together?

Would 1.8.0 also work for you e.g.,
conda install pytorch==1.8.0 torchvision==0.9.0 torchaudio==0.8.0 cudatoolkit=11.1 -c pytorch -c conda-forge ?

Another alternative would be to just build torch from source on a system with the correct cuda toolkit version.

Ah, this command worked to install Pytorch with CUDAtoolkit 11.1. Where can I find all the working combinations between the package versions?

What remains now is adapting LibTorch to CUDA 11.1, I hadn’t thought about building it from source. I’ll give it a try. Thanks for your help!

For the former, see: Previous PyTorch Versions | PyTorch

Very helpful, thank you!