当我在 pytorch 中使用 os.environ['CUDA_VISIBLE_DEVICES'] 时,我收到以下消息
Warning: Device on which events/metrics are configured are different than the device on which it is being profiled. One of the possible reason is setting CUDA_VISIBLE_DEVICES inside the application.
这实际上意味着什么?如何通过使用“CUDA_VISIBLE_DEVICES”(不是 torch.cuda.set_device())来避免这种情况?
这是 pytorch test.py 中的代码
import torch
import os
os.environ['CUDA_VISIBLE_DEVICES'] = '1'
g = 1
c1 = 512
c2 = 512
input = torch.randn(64, c1, 28, 28).cuda()
model = nn.Sequential(
nn.Conv2d(c1,c2,1,groups=g),
nn.ReLU(),
nn.Conv2d(c1,c2,1,groups=g),
nn.ReLU(),
nn.Conv2d(c1,c2,1,groups=g),
nn.ReLU(),
nn.Conv2d(c1,c2,1,groups=g),
nn.ReLU(),
nn.Conv2d(c1,c2,1,groups=g),
nn.ReLU(),
).cuda()
out = model(input)
和命令:
nvprof --analysis-metrics -o metrics python test.py