Hi there, I am working on a project called dog_app.py, within conda
environment and a Windows 10 machine.
Although I have (apparently) configured everything to use GPU, its usage barely goes above 2%. I am moving the model to cuda()
, as well as my data. Why GPU is not being used at all? How do I debug that?
use_cuda = torch.cuda.is_available()
model_scratch = Net()
if use_cuda:
model_scratch.cuda()
print("Let's use", torch.cuda.device_count(), "GPU(s)!")
# Prints "Let's use 1 GPU(s)!"
...
def train(n_epochs, loaders, model, optimizer, criterion, use_cuda, save_path):
...
model.train()
for batch_idx, (data, target) in enumerate(loaders['train']):
if use_cuda:
data, target = data.cuda(), target.cuda()
I found this test on another thread on the subject, but allocating memory on the GPU worked just fine:
import torch
a = torch.cuda.FloatTensor(10000)
print("Allocated:", round(torch.cuda.memory_allocated(0)/10243,1), "GB")
b = torch.cuda.FloatTensor(20000)
print("Allocated:", round(torch.cuda.memory_allocated(0)/10243,1), "GB")
#Output:
# Allocated: 3.9 GB
# Allocated: 11.8 GB