PyTorch is not using CUDA

Nurtugan_Azatbekuly: <p>Hello. I have trouble while using PyTorch. CUDA is properly configured, <strong>but not using by PyTorch for some reason</strong>.<br>
Yes, problem is not new, I’ve seen a lot of discussions on that topic, but didn’t get the answer.<br>
I’ll be short.<br>
I’m learning PyTorch now, so basically I’m just rewriting this code, and having troubles with CUDA: <a href="https://www.learnpytorch.io/03_pytorch_computer_vision/" class="inline-onebox" rel="noopener nofollow ugc">03. PyTorch Computer Vision - Zero to Mastery Learn PyTorch for Deep Learning</a></p>
<p><em>PyTorch+CUDA version:</em></p>
<pre><code class="lang-auto">print(torch.__version__)
device = torch.device('cuda') if torch.cuda.is_available() else "cpu"
device
2.5.1+cu118
device(type='cuda')
</code></pre>
<p><em>Device is available:</em></p>
<pre><code class="lang-auto">torch.cuda.is_available(), torch.cuda.device_count()
(True, 1)
</code></pre>
<p><em>Also I specified device(cuda) in data and model:</em></p>
<pre><code class="lang-auto">print(next(model_0.parameters()).device) 
cuda:0

X, y = X.to(device), y.to(device)
</code></pre>
<p><em>So, in the model training pure CPU usage:</em><br>
<div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/c/c/ccb9163052b14d675f74e0f69cbca101560c8547.png" data-download-href="https://discuss.pytorch.org/uploads/default/ccb9163052b14d675f74e0f69cbca101560c8547" title="image"><img src="https://discuss.pytorch.org/uploads/default/original/3X/c/c/ccb9163052b14d675f74e0f69cbca101560c8547.png" alt="image" data-base62-sha1="td3WV7uG1omwRxQVUupo1Nz50l9" width="318" height="500" data-dominant-color="FAFAFB"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">image</span><span class="informations">547×858 16.1 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div></p>
<p><em>My GPU properties, on the model training time:</em></p>
<pre><code class="lang-auto">+-----------------------------------------------------------------------------------------+
| NVIDIA-SMI 561.00                 Driver Version: 561.00         CUDA Version: 12.6     |
|-----------------------------------------+------------------------+----------------------+
| GPU  Name                  Driver-Model | 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 4060 ...  WDDM  |   00000000:01:00.0 Off |                  N/A |
| N/A   64C    P8              3W /   42W |     205MiB /   8188MiB |      0%      Default |
|                                         |                        |                  N/A |
+-----------------------------------------+------------------------+----------------------+

+-----------------------------------------------------------------------------------------+
| Processes:                                                                              |
|  GPU   GI   CI        PID   Type   Process name                              GPU Memory |
|        ID   ID                                                               Usage      |
|=========================================================================================|
|    0   N/A  N/A     19996      C   ...rograms\Python\Python310\python.exe      N/A      |
+-----------------------------------------------------------------------------------------+
</code></pre>
<p><strong>Looking for your advices and thank you very much!</strong></p>

ptrblck: <p>PyTorch is using your GPU if CUDA is available, PyTorch is able to use the GPU (test it by creating a random tensor on the GPU), and if you’ve moved the input data as well as the model to the GPU. The Windows Task Manager is misleading as it doesn’t show the <code>compute</code> or <code>cuda</code> tabs by default (we have a few threads about it) so either enable it or use <code>nvidia-smi</code> to check the GPU utilization.</p>