Mix CUDA versions between PyTorch and LibTorch?

username: mmitjans
cooked: <p>Hi,</p>
<p>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.</p>
<p>However, when trying to build the C++ app linking the LibTorch libraries I’m getting some compilation errors:</p>
<pre><code class="lang-auto">/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
</code></pre>
<p>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?</p>
<p>Thank you,<br>
Marc</p>

username: eqy
cooked: <p>How are you installing pytorch? e.g., would a command like<br>
<code>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</code> work?</p>

username: mmitjans
cooked: <p>I’m installing it with conda. I did it with <code>conda install pytorch==1.7.1 torchvision==0.8.2 torchaudio==0.7.2 cudatoolkit=11.0 -c pytorch</code> because I couldn’t find cudatoolkit 11.1.</p>
<p>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?</p>

username: eqy
cooked: <p>Would 1.8.0 also work for you e.g.,<br>
<code>conda install pytorch==1.8.0 torchvision==0.9.0 torchaudio==0.8.0 cudatoolkit=11.1 -c pytorch -c conda-forge</code> ?</p>
<p>Another alternative would be to just build torch from source on a system with the correct cuda toolkit version.</p>

username: mmitjans
cooked: <p>Ah, this command worked to install Pytorch with CUDAtoolkit 11.1.  Where can I find all the working combinations between the package versions?</p>
<p>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!</p>

username: eqy
cooked: <p>For the former, see: <a href="https://pytorch.org/get-started/previous-versions/" rel="noopener nofollow ugc">Previous PyTorch Versions | PyTorch</a></p>

username: mmitjans
cooked: <p>Very helpful, thank you!</p>