RuntimeError: Input type (torch.cuda.FloatTensor) and weight type (torch.FloatTensor) should be the same

在初始化后的model后添加代码model.cuda()即可

RuntimeError: cuda runtime error (59) : device-side assert triggered at xxx

使用如下flag重新运行python脚本:

CUDA_LAUNCH_BLOCKING=1 python your_script.py

并根据assertion fail信息进行debug

a if condition else b + c if condition else d == a if condition else (b + c if condition else d)

因此一定要在if else表达式外面加括号

Key error 是因为字典的key找不到引起的

pytorch默认复制索引,因此用一个tensor记录历史值不能直接用等号,要用clone()

a=torch.zeros((2,3))
a_old = a[1,1] # 0
a[1,1] = 1
print(a_old) # 1

标签: none

评论已关闭