My GPU is not being utilized while using Pytorch 1.7?

kapildavi: <p>I have 16gb ram, MSI 1050ti graphics card, intel 4770 processor.</p>
<p>though I have already installed</p>
<ol>
<li>CUDA=11.0</li>
<li>CUDNN=8.0.5</li>
<li>PYTORCH= 1.7</li>
<li>Windows=10</li>
</ol>
<pre><code class="lang-auto">import torch
import sys
print('__Python VERSION:', sys.version)
print('__pyTorch VERSION:', torch.__version__)
print('__CUDA VERSION', )
from subprocess import call
# call(["nvcc", "--version"]) does not work
! nvcc --version
print('__CUDNN VERSION:', torch.backends.cudnn.version())
print('__Number CUDA Devices:', torch.cuda.device_count())
print('__Devices')
# call(["nvidia-smi", "--format=csv", "--query-gpu=index,name,driver_version,memory.total,memory.used,memory.free"])
print('Active CUDA Device: GPU', torch.cuda.current_device())
print ('Available devices ', torch.cuda.device_count())
print ('Current cuda device ', torch.cuda.current_device())

output:
__Python VERSION: 3.8.3 (default, Jul  2 2020, 17:30:36) [MSC v.1916 64 bit (AMD64)]
__pyTorch VERSION: 1.7.1
__CUDA VERSION
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2020 NVIDIA Corporation
Built on Thu_Jun_11_22:26:48_Pacific_Daylight_Time_2020
Cuda compilation tools, release 11.0, V11.0.194
Build cuda_11.0_bu.relgpu_drvr445TC445_37.28540450_0
__CUDNN VERSION: 8004
__Number CUDA Devices: 1
__Devices
Active CUDA Device: GPU 0
Available devices  1
Current cuda device  0
​
</code></pre>
<p>The code I’m running is:</p>
<pre><code class="lang-auto">device = torch.device('cuda')


criterion = nn.NLLLoss()
# Only train the classifier parameters, feature parameters are frozen
optimizer = optim.Adam(model.classifier.parameters(), lr=0.001)

model.to(device)
epochs = 1
steps = 0
running_loss = 0
print_every = 1

for epoch in range(epochs):
    for inputs, labels in trainloader:
        start_time=time.time()
        steps += 1
        # Move input and label tensors to the default device
        inputs, labels = inputs.to(device), labels.to(device)

        optimizer.zero_grad()

        logps = model.forward(inputs.to(device))
        loss = criterion(logps, labels)
        loss.backward()
        optimizer.step()

        running_loss += loss.item()


    if steps % print_every == 0:
        test_loss = 0
        accuracy = 0
        model.eval()
        with torch.no_grad():
            for inputs, labels in testloader:
                inputs, labels = inputs.to(device), labels.to(device)
                logps = model.forward(inputs).to(device)
                batch_loss = criterion(logps, labels)

                test_loss += batch_loss.item()

                # Calculate accuracy
                ps = torch.exp(logps)
                top_p, top_class = ps.topk(1, dim=1)
                equals = top_class == labels.view(*top_class.shape)
                accuracy += torch.mean(equals.type(torch.FloatTensor)).item()

        print(f"Device = {device};"
              f"Epoch {epoch+1}/{epochs}.. "
              f"Train loss: {running_loss/print_every:.3f}.. "
              f"Test loss: {test_loss/len(testloader):.3f}.. "
              f"Test accuracy: {accuracy/len(testloader):.3f}")
        print(time.time()-start_time)
        running_loss = 0
        model.train()
</code></pre>
<p>the stats when i run my nvidia-smi and task manger:<br>
<div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/e/5/e5e5b0914e30c6d3e9c0a6f24e3fb5ef75e10a88.png" data-download-href="https://discuss.pytorch.org/uploads/default/e5e5b0914e30c6d3e9c0a6f24e3fb5ef75e10a88" title="task"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/e/5/e5e5b0914e30c6d3e9c0a6f24e3fb5ef75e10a88_2_690x388.png" alt="task" data-base62-sha1="wNLrOJyMrC82qVnO5iJT0L3Fzeg" width="690" height="388" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/e/5/e5e5b0914e30c6d3e9c0a6f24e3fb5ef75e10a88_2_690x388.png, https://discuss.pytorch.org/uploads/default/optimized/3X/e/5/e5e5b0914e30c6d3e9c0a6f24e3fb5ef75e10a88_2_1035x582.png 1.5x, https://discuss.pytorch.org/uploads/default/optimized/3X/e/5/e5e5b0914e30c6d3e9c0a6f24e3fb5ef75e10a88_2_1380x776.png 2x" data-dominant-color="EFF2F4"><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">task</span><span class="informations">1600×900 92.7 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><br>
<div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/9/e/9e544fa48392d2dfc0e28a2c95f10e8d1968d917.png" data-download-href="https://discuss.pytorch.org/uploads/default/9e544fa48392d2dfc0e28a2c95f10e8d1968d917" title="nre nvi"><img src="https://discuss.pytorch.org/uploads/default/original/3X/9/e/9e544fa48392d2dfc0e28a2c95f10e8d1968d917.png" alt="nre nvi" data-base62-sha1="mAE4Ii2SjwO9vAf2NWokezdI6H5" width="690" height="384" data-dominant-color="1F1F1F"><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">nre nvi</span><span class="informations">1143×637 33.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>

user_123454321: <p>I think your gpu is utilized. Have you started training and the gpu has not been utilized. Did you check the nvidia-smi while training?</p>

kapildavi: <p>Thank you <a class="mention" href="/u/user_123454321">@user_123454321</a>. I have edited the description. Could you read it back please.</p>

user_123454321: <p>I think the last process in the list is the one for training. So, I guess the GPU is being utilized but the utilization is low.</p>

kapildavi: <p>What should I do to utilize it fast?</p>

user_123454321: <p>Can you check if the loading is the bottleneck by giving random inputs to the model for training?</p>

kapildavi: <p>Thanks <a class="mention" href="/u/user_123454321">@user_123454321</a>. I followed these steps in this video listed below and now my GPU is getting utilized well.</p><div class="youtube-onebox lazy-video-container" data-video-id="PlW9zAg4cx8" data-video-title="Install TensorFlow GPU and PyTorch with CUDA on Windows 10 Anaconda | CUDA 10.1 cuDNN 7.6" data-provider-name="youtube">
  <a href="https://www.youtube.com/watch?v=PlW9zAg4cx8" target="_blank" rel="noopener nofollow ugc">
    <img class="youtube-thumbnail" src="https://img.youtube.com/vi/PlW9zAg4cx8/maxresdefault.jpg" title="Install TensorFlow GPU and PyTorch with CUDA on Windows 10 Anaconda | CUDA 10.1 cuDNN 7.6" width="690" height="388">
  </a>
</div>