Paddle assign 操作巨大bug!!!!!!!!!!!!

unftdfkk  于 2021-11-29  发布在  Java
关注(0)|答案(3)|浏览(408)

paddle版本:paddlepaddle-gpu 2.1.0
问题:使用assign操作后,被赋值的tensor 直接丢失grad!!!!!!


## paddle 代码

import paddle
import numpy as np
ori_a = paddle.to_tensor(np.array([0,0], dtype='float32'), stop_gradient=False)
a = ori_a + 1
b = paddle.to_tensor(np.array([0], dtype='float32'), stop_gradient=False)
a[0] = b
loss = paddle.sum(a*2)
loss.backward()
print(ori_a.grad)
print(b.grad)

结果:ori_a的grad = None了。


## torch 代码

import torch
import numpy as np

ori_a = torch.tensor(np.array([0,0], dtype='float32'))
ori_a.requires_grad = True
a = ori_a + 1
b = torch.tensor(np.array([0], dtype='float32'))
b.requires_grad = True
a[0] = b
loss = torch.sum(a*2)
loss.backward()
print(ori_a.grad)
print(b.grad)

结果:ori_a 的grad 依然存在。

请fix!!!!!!!!!!

z5btuh9x

z5btuh9x1#

您好,我们已经收到了您的问题,会安排技术人员尽快解答您的问题,请耐心等待。请您再次检查是否提供了清晰的问题描述、复现代码、环境&版本、报错信息等。同时,您也可以通过查看官网API文档常见问题历史IssueAI社区来寻求解答。祝您生活愉快~

Hi! We've received your issue and please be patient to get responded. We will arrange technicians to answer your questions as soon as possible. Please make sure that you have posted enough message to demo your request. You may also check out the APIFAQGithub Issue and AI community to get the answer.Have a nice day!

n8ghc7c1

n8ghc7c12#

感谢反馈,问题已复现,会尽快修复

1u4esq0p

1u4esq0p3#

最新develop和2.2分支已经修复了 @sys1874

相关问题