以下一段代码:
import torch
x=torch.tensor([-1.2, 0.6], requires_grad=True)
y=1+x
y[0]=torch.abs(y[0])
y.sum().backward()
给出错误说:
RuntimeError:梯度计算所需的变量之一已被就地操作修改:[torch.FloatTensor []],它是 AsStridedBackward0 的输出 0,版本为 1;预期版本 0 代替。
但是,如果您将第四行更改为
y[0]=torch.abs_(y[0])
,一切都会再次起作用。但是根据文档,abs_
是 abs
的原位版本。为什么它有效而abs
不会?
• 如何使用 NVIDIA GeForce RTX 3080 在 CUDA 11.7 上配置 PyTorch
• 如何修复“ValueError:预期输入 batch_size (6) 以匹配目标 batch_size (1)。”在 PyTorch 中
• PyTorch 安装错误 [SSL: DECRYPTION_FAILED_OR_BAD_RECORD_MAC]
• 我在使用 PyTorch 时遇到此错误:RuntimeError: gather_out_cpu(): Expected dtype int64 for index
• FCN-ResNet50 架构上的 Pytorch 前向钩子
• 我觉得没有inplace操作,但是出现了inplace操作错误
• 我收到错误 Input Tensor is not an XLA tensor
• pytorch 中 mps 设备的 manual_seed
• 火炬张量的 .get_device() 返回 -1 是什么意思?
• Errno 13 Permission denied: '/files' while trying to execute pytorch script
• 当 torch 找不到 cuda 时如何修复,错误:版本 libcublasLt.so.11 未在具有链接时间参考的文件 libcublasLt.so.11 中定义?