首页 > 解决方案 > 在 Windows 上使用带有 PyTorch 的 CUDA 时,GPU 使用率显示为零

问题描述

我有 pytorch 脚本。

import torch

torch.cuda.is_available() 
# True

device=torch.device('cuda:0') 
# I moved my tensors to device

但是,当 pytorch 脚本运行时,Windows 任务管理器显示零 GPU(NVIDIA GTX 1050TI)使用情况 我的脚本速度很好,如果我将 torch.device 更改为 CPU 而不是 GPU,速度会变慢,因此 cuda(GPU)正在工作。为什么 Windows 任务管理器不显示 GPU 使用情况?

我的代码示例:

device=torch.device("cuda:0")
model=torch.load('mymodel.pth', map_location=torch.device(device))
image=Image.open('picture.png').convert('RGB')
transform=transforms.Compose([
            transforms.Resize(224),
            transforms.CenterCrop(224),
            transforms.ToTensor(),
            transforms.Normalize([0.485, 0.456, 0.406], [0.229, 0.224, 0.225])
        ])
input=transform(image)
input=torch.unsqueeze(input, 0)
input=input.to(device)
output=model(input)

标签: windowspytorchgpu

解决方案


Windows 任务管理器的整体利用率似乎不包括 cuda 的使用。确保在图中选择 cuda 选项。

详情见:https ://medium.com/@michaelceber/gpu-monitoring-on-windows-10-for-machine-learning-cuda-41088de86d65


推荐阅读