diff --git a/mindspore/ops/_grad/grad_math_ops.py b/mindspore/ops/_grad/grad_math_ops.py index 446c634a26..e7327da481 100755 --- a/mindspore/ops/_grad/grad_math_ops.py +++ b/mindspore/ops/_grad/grad_math_ops.py @@ -425,11 +425,22 @@ def get_bprop_rsqrt(self): @bprop_getters.register(P.Reciprocal) def get_bprop_reciprocal(self): """Grad definition for `Reciprocal` operation.""" - reciprocal_grad = G.ReciprocalGrad() + if self.target == "GPU": + neg = P.Neg() + mul = P.Mul() + square = P.Square() + reciprocal = P.Reciprocal() + + def bprop(x, out, dout): + g = neg(reciprocal(square(x))) + dx = mul(dout, g) + return (dx,) + else: + reciprocal_grad = G.ReciprocalGrad() - def bprop(x, out, dout): - dx = reciprocal_grad(out, dout) - return (dx,) + def bprop(x, out, dout): + dx = reciprocal_grad(out, dout) + return (dx,) return bprop diff --git a/mindspore/ops/operations/array_ops.py b/mindspore/ops/operations/array_ops.py index 1d6e82c8b0..2cc26d61eb 100644 --- a/mindspore/ops/operations/array_ops.py +++ b/mindspore/ops/operations/array_ops.py @@ -2375,6 +2375,8 @@ class ResizeNearestNeighbor(PrimitiveWithInfer): return tuple(x)[:-2] + tuple(self.size) def infer_dtype(self, x): + validator.check_subclass("x", x, mstype.tensor, self.name) + validator.check_tensor_type_same({"x": x}, mstype.number_type, self.name) return x diff --git a/mindspore/ops/operations/math_ops.py b/mindspore/ops/operations/math_ops.py index e721cd140a..a704a573dc 100644 --- a/mindspore/ops/operations/math_ops.py +++ b/mindspore/ops/operations/math_ops.py @@ -1290,6 +1290,10 @@ class Reciprocal(PrimitiveWithInfer): @prim_attr_register def __init__(self): """init Reciprocal""" + if context.get_context("device_target") == "GPU": + self.target = "GPU" + else: + self.target = "OTHER" self.init_prim_io_names(inputs=['x'], outputs=['y']) def infer_shape(self, x):