pytorch 1.9 报错:
RuntimeError: one of the variables needed for gradient computation has been modified by an inplace operation: [torch.cuda.FloatTensor [4, 512, 16, 16]], which is output 0 of ConstantPadNdBackward, is at version 1; expected version 0 instead. Hint: enable anomaly detection to find the operation that failed to compute its gradient, with torch.autograd.set_detect_anomaly(True). #23
开始还以为是输入的 z = torch.randn(batch_size, 128,1,1).to(device) 。
解决办法:
pip install torch == 1.4 torchvision = 0.05
博客介绍了在使用PyTorch 1.9时遇到的RuntimeError,该错误涉及到在梯度计算过程中变量被不当的Inplace操作修改。解决方案是回退到torch 1.4和torchvision 0.5版本。通过这个修复,用户可以避免遇到计算梯度的问题。

2615

被折叠的 条评论
为什么被折叠?



