Browse Source

!11677 add isfinite grad

From: @jiangzg001
Reviewed-by: @liangchenghui,@c_34
Signed-off-by: @liangchenghui
tags/v1.2.0-rc1
mindspore-ci-bot Gitee 5 years ago
parent
commit
58b8d8cd02
2 changed files with 14 additions and 0 deletions
  1. +10
    -0
      mindspore/ops/_grad/grad_math_ops.py
  2. +4
    -0
      tests/ut/python/ops/test_ops.py

+ 10
- 0
mindspore/ops/_grad/grad_math_ops.py View File

@@ -778,6 +778,16 @@ def get_bprop_reduce_mean(self):
return bprop


@bprop_getters.register(P.IsFinite)
def get_bprop_isfinite(self):
"""Grad definition for `IsFinite` operation."""

def bprop(x, out, dout):
return (zeros_like(x),)

return bprop


@bprop_getters.register(P.Equal)
def get_bprop_equal(self):
"""Grad definition for `Equal` operation."""


+ 4
- 0
tests/ut/python/ops/test_ops.py View File

@@ -1401,6 +1401,10 @@ test_case_math_ops = [
'block': P.RealDiv(),
'desc_inputs': [[4, 5], [2, 3, 4, 5]],
'desc_bprop': [[2, 3, 4, 5]]}),
('IsFinite', {
'block': P.IsFinite(),
'desc_inputs': [Tensor(np.random.random((3, 4, 5)).astype(np.float32))],
'desc_bprop': [Tensor(np.random.random((3, 4, 5)).astype(np.bool))]}),
('Div', {
'block': P.Div(),
'desc_inputs': [[4, 5], [2, 3, 4, 5]],


Loading…
Cancel
Save