PyTorch cannot find libcudnn

username: mbledkowski
cooked: <p>Hello,<br>
I am trying to use PyTorch with Poetry, on Fedora Linux. I have CUDA drivers installed on my system. I do not want to install CUDNN, or NCCL system-wide.<br>
From what I understand, PyTorch should work out of the box, on a system with CUDA, whether or not the CUDNN and NCCL are installed, as it ships them as a dependency.<br>
When I try to run code that uses PyTorch library, and requires Nvidia libraries, I get this or similar error:</p>
<pre><code class="lang-auto">/home/mble/.cache/pypoetry/virtualenvs/remove-background-H96ZRE0z-py3.12/lib64/python3.12/site-packages/torch/nn/modules/conv.py:456: UserWarning: Attempt to open cnn_infer failed: handle=0 error: libcudnn_cnn_infer.so.8: cannot open shared object file: No such file or directory (Triggered internally at ../aten/src/ATen/native/cudnn/Conv_v8.cpp:81.)
  return F.conv2d(input, weight, bias, self.stride,
</code></pre>
<p>Even though, the required libraries are in the virtual environment:</p>
<pre><code class="lang-auto">$ find /home/mble/.cache/pypoetry/virtualenvs/remove-background-H96ZRE0z-py3.12/ -type f -name libcudnn\*                                                                                                                                                                                                                
/home/mble/.cache/pypoetry/virtualenvs/remove-background-H96ZRE0z-py3.12/lib/python3.12/site-packages/nvidia/cudnn/lib/libcudnn.so.8
/home/mble/.cache/pypoetry/virtualenvs/remove-background-H96ZRE0z-py3.12/lib/python3.12/site-packages/nvidia/cudnn/lib/libcudnn_adv_infer.so.8
/home/mble/.cache/pypoetry/virtualenvs/remove-background-H96ZRE0z-py3.12/lib/python3.12/site-packages/nvidia/cudnn/lib/libcudnn_adv_train.so.8
/home/mble/.cache/pypoetry/virtualenvs/remove-background-H96ZRE0z-py3.12/lib/python3.12/site-packages/nvidia/cudnn/lib/libcudnn_cnn_infer.so.8
/home/mble/.cache/pypoetry/virtualenvs/remove-background-H96ZRE0z-py3.12/lib/python3.12/site-packages/nvidia/cudnn/lib/libcudnn_cnn_train.so.8
/home/mble/.cache/pypoetry/virtualenvs/remove-background-H96ZRE0z-py3.12/lib/python3.12/site-packages/nvidia/cudnn/lib/libcudnn_ops_infer.so.8
/home/mble/.cache/pypoetry/virtualenvs/remove-background-H96ZRE0z-py3.12/lib/python3.12/site-packages/nvidia/cudnn/lib/libcudnn_ops_train.so.8
</code></pre>
<p>In this example, the PyTorch is in version 2.3.1+cu121:</p>
<pre><code class="lang-auto">Python 3.12.3 (main, Apr 17 2024, 00:00:00) [GCC 14.0.1 20240411 (Red Hat 14.0.1-0)] on linux
Type "help", "copyright", "credits" or "license" for more information.
&gt;&gt;&gt; import torch
&gt;&gt;&gt; print('torch version', torch.__version__)
torch version 2.3.1+cu121
</code></pre>
<p>Best regards,<br>
Maciej Błędkowski</p>

username: ptrblck
cooked: <p>The issue seems to be specific to <code>poetry</code> and also described <a href="https://github.com/pytorch/pytorch/issues/104259">here</a>.</p>
<aside class="quote no-group" data-username="mbledkowski" data-post="1" data-topic="205696">
<div class="title">
<div class="quote-controls"></div>
<img loading="lazy" alt="" width="24" height="24" src="https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/mbledkowski/48/71171_2.png" class="avatar"> mbledkowski:</div>
<blockquote>
<p>From what I understand, PyTorch should work out of the box, on a system with CUDA, whether or not the CUDNN and NCCL are installed, as it ships them as a dependency.</p>
</blockquote>
</aside>
<p>Almost, but no locally installed CUDA toolkit is needed. Only a properly installed NVIDIA driver is necessary. However, I don’t know how exactly <code>poetry</code> works and why it’s unable to use the shipped dependencies.</p>

username: mbledkowski
cooked: <p>Thank you very much for your response.<br>
Do you know what could cause this behavior?</p>

username: ptrblck
cooked: <p>No, unfortunately not, as I’m not familiar with <code>poetry</code>.<br>
You could use another virtual env and install PyTorch via <code>pip</code> or <code>conda</code> as a workaround.</p>