GPU Error with PyTorch in Virtual Machine

Daniel1234: <p>I am trying to use GPU in a virtual machine with PyTorch.</p>
<p><strong>Setup:</strong><br>
Running following PyTorch functions to check the availability of the GPU:</p>
<pre><code class="lang-auto">print(torch.cuda.current_device())
print(torch.cuda.get_device_name())
print(torch.cuda.is_available())
print(torch.cuda.device_count())
print(torch.cuda.device(0))
print(torch.cuda.get_device_name(0))
</code></pre>
<p>results in the following output:<br>
0<br>
GRID V100S-16C<br>
True<br>
1<br>
&lt;torch.cuda.device object at 0x7f7e596bdb80&gt;<br>
GRID V100S-16C</p>
<p>Furthermore, Nvidia-smi prints the following:</p>
<pre><code class="lang-auto">Sun Sep  3 17:00:29 2023       
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 450.142.00   Driver Version: 450.142.00   CUDA Version: 11.0     |
|-------------------------------+----------------------+----------------------+
| 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  GRID V100S-16C      On   | 00000000:02:02.0 Off |                  N/A |
| N/A   N/A    P0    N/A /  N/A |   1104MiB / 16384MiB |      0%      Default |
|                               |                      |                  N/A |
+-------------------------------+----------------------+----------------------+
                                                                               
+-----------------------------------------------------------------------------+
| Processes:                                                                  |
|  GPU   GI   CI        PID   Type   Process name                  GPU Memory |
|        ID   ID                                                   Usage      |
|=============================================================================|
|  No running processes found                                                 |
+-----------------------------------------------------------------------------+
</code></pre>
<p><strong>Problem:</strong><br>
Running the following code:</p>
<pre><code class="lang-auto">import torch

torch.ones((1, 1)).to('cuda')
</code></pre>
<p>results in the following error message:</p>
<hr>
<p>RuntimeError                              Traceback (most recent call last)<br>
Cell In[3], line 3<br>
1 import torch<br>
----&gt; 3 torch.ones((1, 1)).to(‘cuda’)</p>
<p>RuntimeError: CUDA error: CUDA-capable device(s) is/are busy or unavailable<br>
CUDA kernel errors might be asynchronously reported at some other API call, so the stacktrace below might be incorrect.<br>
For debugging consider passing CUDA_LAUNCH_BLOCKING=1.<br>
Compile with <code>TORCH_USE_CUDA_DSA</code> to enable device-side assertions.</p>
<p>I tried to set CUDA_LAUNCH_BLOCKING=1 but the error still occurs and the error message remains the same.</p>
<p>Do you have any idea what the problem might be and how I can fix it? Please let me know if further information is required to be able to understand my problem. Thanks in advance, Daniel.</p>