Pytorch 属性错误:模块';火炬';“没有属性”;设备“;
我99%确定这是因为我没有将Pytork从0.31升级到0.4,但是我现在无法升级Pytork 我需要将.device(0.4)转换为在0.31中工作的东西 我检查了,但是它没有提供如何在retrospect中转换torch.device。请帮忙Pytorch 属性错误:模块';火炬';“没有属性”;设备“;,pytorch,Pytorch,我99%确定这是因为我没有将Pytork从0.31升级到0.4,但是我现在无法升级Pytork 我需要将.device(0.4)转换为在0.31中工作的东西 我检查了,但是它没有提供如何在retrospect中转换torch.device。请帮忙 torch.cuda.device()是一个上下文管理器 ---> 13 device = torch.device({"cuda"} if torch.cuda.is_available() else {"cpu"}) 14
torch.cuda.device()
是一个上下文管理器
---> 13 device = torch.device({"cuda"} if torch.cuda.is_available() else {"cpu"})
14
15
AttributeError: module 'torch' has no attribute 'device'
以上内容在0.2版本中起作用。在1.5版本中
torch.cuda.set_device(0)
# On device 0
with torch.cuda.device(1):
print("Inside device is 1")
# On device 1
print("Outside is still 0")
# On device 0
if torch.cuda.is_available():
device = torch.device("cuda:0")
print("running on the GPU")
else:
device = torch.device("cpu")
print("running on the CPU")