代码拉取完成,页面将自动刷新
Users can customize backpropagation (calculation) function of the nn.Cell object, thus control the process of the nn.Cell object gradient calculation, locating gradient problems.
Custom bprop functions are used by: adding a user-defined bprop function to the defined nn. Cell object. The training process uses user-defined bprop functions to generate reverse graphs.
The sample code is as follows:
ms.set_context(mode=ms.PYNATIVE_MODE)
class Net(nn.Cell):
def construct(self, x, y):
z = x * y
z = z * y
return z
def bprop(self, x, y, out, dout):
x_dout = x + y
y_dout = x * y
return x_dout, y_dout
grad_all = ops.GradOperation(get_all=True)
output = grad_all(Net())(ms.Tensor(1, ms.float32), ms.Tensor(2, ms.float32))
print(output)
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。