From 0c6cf98db08469e5d3f1f590f5631c56216dfa3c Mon Sep 17 00:00:00 2001 From: buxue Date: Thu, 30 Apr 2020 10:42:31 +0800 Subject: [PATCH] fix bug of brpop of FloorMod --- mindspore/ops/_grad/grad_math_ops.py | 9 ++++----- tests/ut/python/ops/test_ops.py | 5 ++--- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/mindspore/ops/_grad/grad_math_ops.py b/mindspore/ops/_grad/grad_math_ops.py index 2f39fe8745..1663c231cc 100755 --- a/mindspore/ops/_grad/grad_math_ops.py +++ b/mindspore/ops/_grad/grad_math_ops.py @@ -255,13 +255,10 @@ def get_bprop_floordiv(self): @bprop_getters.register(P.FloorMod) def get_bprop_floormod(self): """Grad definition for `FloorMod` operation.""" - div_op = P.FloorMod() - neg = P.Neg() - mul_op = P.Mul() def bprop(x, y, out, dout): - bc_x = div_op(dout, y) - bc_y = neg(mul_op(bc_x, out)) + bc_x = dout + bc_y = -dout * (x // y) return binop_grad_common(x, y, bc_x, bc_y) return bprop @@ -412,6 +409,7 @@ def get_bprop_reducesum(self): def get_bprop_cumsum(self): """Grad definition for `CumSum` operation.""" cumsum = P.CumSum(exclusive=self.exclusive, reverse=not self.reverse) + def bprop(x, axis, out, dout): return cumsum(dout, axis), zeros_like(axis) return bprop @@ -787,6 +785,7 @@ def get_bprop_atan2(self): """Generate bprop for Atan2""" square = P.Square() + def bprop(x, y, out, dout): tmp = dout / (square(x) + square(y)) dx = tmp * y diff --git a/tests/ut/python/ops/test_ops.py b/tests/ut/python/ops/test_ops.py index 68ff816fb3..d60503158f 100755 --- a/tests/ut/python/ops/test_ops.py +++ b/tests/ut/python/ops/test_ops.py @@ -351,9 +351,8 @@ test_case_math_ops = [ 'skip': ['backward']}), ('FloorMod', { 'block': P.FloorMod(), - 'desc_inputs': [Tensor(np.random.rand(4).astype(np.float16)), - Tensor(np.random.rand(4).astype(np.float16))], - 'skip': ['backward']}), + 'desc_inputs': [[3, 4, 5], [2, 3, 4, 5]], + 'desc_bprop': [[2, 3, 4, 5]]}), ('identity', { 'block': ops.functional.identity, 'desc_inputs': [[2, 2]],