pytorch-book icon indicating copy to clipboard operation
pytorch-book copied to clipboard

第三章 Tensor和autograd第90页代码bug

Open Gamkiu opened this issue 4 years ago • 1 comments

文章代码运行错误,(第三段代码) x = V(t.arange(-2,4),requires_grad = True). 运行时出现“only Tensor of floating point type can require grad.”错误

Gamkiu avatar Jul 31 '20 12:07 Gamkiu

改成t.arange(-2,4).float()就可以了 老版本的pytorch用arange创建默认是FloatTensor类型的 新版本arange创建时dtype默认是LongTensor

QAQEthan avatar Oct 22 '20 02:10 QAQEthan