提交 f981e773 编写于 作者: G gongchen

Change C.grad_with_sens.

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