Solved by ptrblck in post #6 
              
              
                It should be alright. You could put the net creation, datasets, and loaders into main, but this shouldn’t yield this error. 
However, it looks like you’re not pushing the data and target onto the GPU in your eval loops: 
with torch.no_grad():
    for data in testloader:
        images, labels = data…