小编PPh*_*Pho的帖子

Pytorch 修改解压张量时出​​错

修改解包张量时出现错误。

import torch
a1, a2 = torch.tensor([1,2], dtype = torch.float64)
b = torch.rand(2, requires_grad = True)

a1 += b.sum()
Run Code Online (Sandbox Code Playgroud)

此代码产生以下错误:

RuntimeError: A view was created in no_grad mode and is being modified inplace with grad mode enabled. This view is the output of a function that returns multiple views. Such functions do not allow the output views to be modified inplace. You should replace the inplace operation by an out-of-place one.
Run Code Online (Sandbox Code Playgroud)

但是,当我分别创建 a1 和 a2 时,没有收到该错误,如下所示:

a1 = torch.tensor([1], dtype …
Run Code Online (Sandbox Code Playgroud)

python pytorch tensor

3
推荐指数
1
解决办法
3421
查看次数

标签 统计

python ×1

pytorch ×1

tensor ×1