提交 dc0a5a2d 编写于 作者: M mindspore-ci-bot 提交者: Gitee

!170 doc(custom_op): fix custom op tutorial

Merge pull request !170 from gongchen/fix_custom_op3
......@@ -223,14 +223,15 @@ class CusSquare(PrimitiveWithInfer):
return bprop
```
`test_square.py`文件中定义反向用例。其中,`grad_with_sens``GradOperation`类的实例化对象。
`test_square.py`文件中定义反向用例。
```python
from mindspore.ops import composite as C
def test_grad_net():
x = np.array([1.0, 4.0, 9.0]).astype(np.float32)
sens = np.array([1.0, 1.0, 1.0]).astype(np.float32)
square = Net()
dx = C.grad_with_sens(square)(Tensor(x), Tensor(sens))
grad = C.GradOperation('grad_with_sens', sens_param=True)
dx = grad(square)(Tensor(x), Tensor(sens))
print("x: ", x)
print("dx: ", dx)
```
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册