Device = 'cuda', but code running on CPU

aagirre92: <p>Hello there,</p>
<p>I have setup pytorch and cuda in my windows 11 laptop that has anaconda installed.</p>
<p>It seems that it’s working, as <code>torch.cuda.is_available()</code> returns <code>True</code></p>
<p>On top of that, my code ensures to move the model and tensors to the default device (I have coded device agnostic code, using <code>device = "cuda" if torch.cuda.is_available() else "cpu"</code>. This same code is running fine (in GPU) in google colab</p>
<p>Even though I see this, when I train the model I see my laptop’s CPU utilization near 100% and the GPU utilization barely vary…</p>
<p>Any idea why could be?</p>

ptrblck: <p>I guess you are using the task manager to check the GPU util. which is misleading on Windows as it shows the video (and other resources) instead of the compute. Select the right “compute” view or use <code>nvidia-smi</code> to check the memory usage as well as the GPU util. If it’s still low, profile your code and check where the bottleneck is as your CPU might block the GPU execution.</p>

aagirre92: <p>Hi! Thanks a lot for the response</p>
<p>Indeed I was using task manager to check the GPU util. Sorry but what do you mean with the right “compute” view? I would like to see its utilization in real time (with <code>nvidia-smi</code> util I only obtain a “screenshot” of it)</p>
<p>By the way, I guess it works (tried the same training with the cpu and it takes more than twice long…)!</p>
<p><div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/8/1/813989c5600fd2919c06d3a6517e3df267d49e08.png" data-download-href="https://discuss.pytorch.org/uploads/default/813989c5600fd2919c06d3a6517e3df267d49e08" title="image"><img src="https://discuss.pytorch.org/uploads/default/original/3X/8/1/813989c5600fd2919c06d3a6517e3df267d49e08.png" alt="image" data-base62-sha1="iraRR4f7P2EKvAjlPeSrwbyVHEQ" width="690" height="250" data-dominant-color="1B1B1A"><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">739×268 8.54 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>Before closing this topic, how do you monitor the GPU usage? I don’t know what you mean with the right “compute” view.</p>
<p>Thanks a lot</p>

ptrblck: <p>I’m not using Windows, but <a href="https://discuss.pytorch.org/t/unet-training-is-not-executed-on-gpu/76850/4">this post</a> might be helpful.</p>

aagirre92: <p>Thanks a lot for the post! Unfortunately I cannot see that <img src="https://discuss.pytorch.org/images/emoji/apple/frowning.png?v=12" title=":frowning:" class="emoji" alt=":frowning:" loading="lazy" width="20" height="20"></p>
<p><div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/7/1/719adcf019b6d35f9847dd540a61d86184dc5c8d.png" data-download-href="https://discuss.pytorch.org/uploads/default/719adcf019b6d35f9847dd540a61d86184dc5c8d" title="image"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/7/1/719adcf019b6d35f9847dd540a61d86184dc5c8d_2_690x323.png" alt="image" data-base62-sha1="gcZKihkuaFPiMaK1tMNxgYI1Scl" width="690" height="323" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/7/1/719adcf019b6d35f9847dd540a61d86184dc5c8d_2_690x323.png, https://discuss.pytorch.org/uploads/default/optimized/3X/7/1/719adcf019b6d35f9847dd540a61d86184dc5c8d_2_1035x484.png 1.5x, https://discuss.pytorch.org/uploads/default/optimized/3X/7/1/719adcf019b6d35f9847dd540a61d86184dc5c8d_2_1380x646.png 2x" data-dominant-color="242426"><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">1679×786 28.9 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>

ptrblck: <p>Unfortunately, I don’t have an idea about Windows so you would need to use <code>nvidia-smi</code> and/or wait for Windows experts to chime in.</p>