Cuda.is_available() return False on Docker image(WSL2)

HsinYuanHsieh0810: <p>Hi !<br>
I build docker image from PyTorch image <a href="https://hub.docker.com/layers/pytorch/pytorch/2.2.1-cuda12.1-cudnn8-devel/images/sha256-42204bca460bb77cbd524577618e1723ad474e5d77cc51f94037fffbc2c88c6f?context=explore" rel="noopener nofollow ugc">2.2.1-cuda12.1-cudnn8-devel</a> in WSL2<br>
And I’ve already installed <a href="https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/install-guide.html#installing-on-ubuntu-and-debian" rel="noopener nofollow ugc">NVIDIA Container Toolkit </a> and restart the Docker.</p>
<p>I can run <code>nvidia-smi</code> inside Docker container.</p>
<p>But when I run in container：<br>
<code>torch.cuda.is_available()</code> it return <strong>False</strong><br>
<code>torch.backends.cudnn.enabled</code> it return <strong>True</strong><br>
I also try <a href="https://hub.docker.com/layers/pytorch/pytorch/2.0.1-cuda11.7-cudnn8-devel/images/sha256-4f66166dd757752a6a6a9284686b4078e92337cd9d12d2e14d2d46274dfa9048?context=explore" rel="noopener nofollow ugc">2.0.1-cuda11.7-cudnn8-devel</a><br>
it still have same problem</p>
<p>However,  I try Pytorch image <a href="https://hub.docker.com/layers/pytorch/pytorch/latest/images/sha256-11691e035a3651d25a87116b4f6adc113a27a29d8f5a6a583f8569e0ee5ff897?context=explore" rel="noopener nofollow ugc">latest</a>. there is no problem,<br>
<code>torch.cuda.is_available()</code> and <code>torch.backends.cudnn.enabled</code> both return <strong>True</strong>.</p>
<p><strong>&gt; nvidia-smi</strong></p>
<pre data-code-wrap="Bash"><code class="lang-Bash">Fri Mar 22 11:04:15 2024
+-----------------------------------------------------------------------------------------+
| NVIDIA-SMI 550.40.07              Driver Version: 551.52         CUDA Version: 12.4     |
|-----------------------------------------+------------------------+----------------------+
| GPU  Name                 Persistence-M | Bus-Id          Disp.A | Volatile Uncorr. ECC |
| Fan  Temp   Perf          Pwr:Usage/Cap |           Memory-Usage | GPU-Util  Compute M. |
|                                         |                        |               MIG M. |
|=========================================+========================+======================|
|   0  NVIDIA GeForce RTX 4090        On  |   00000000:01:00.0  On |                    0 |
|  0%   47C    P8             13W /  450W |     719MiB /  23028MiB |      3%      Default |
|                                         |                        |                  N/A |
+-----------------------------------------+------------------------+----------------------+

+-----------------------------------------------------------------------------------------+
| Processes:                                                                              |
|  GPU   GI   CI        PID   Type   Process name                              GPU Memory |
|        ID   ID                                                               Usage      |
|=========================================================================================|
|    0   N/A  N/A        24      G   /Xwayland                                   N/A      |
|    0   N/A  N/A        35      G   /Xwayland                                   N/A      |
|    0   N/A  N/A       109      G   /Xwayland                                   N/A      |
+-----------------------------------------------------------------------------------------+
</code></pre>
<p><strong>&gt; nvcc --version</strong></p>
<pre><code class="lang-auto">nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2022 NVIDIA Corporation
Built on Wed_Jun__8_16:49:14_PDT_2022
Cuda compilation tools, release 11.7, V11.7.99
Build cuda_11.7.r11.7/compiler.31442593_0
</code></pre>
<p>I have no idea which part went wrong.<br>
Can anyone help me?</p>