Browse Source

!3986 fix reciprocal grad gpu and resizeNearestNeighor

Merge pull request !3986 from fangzehua/recipro
tags/v0.7.0-beta
mindspore-ci-bot Gitee 5 years ago
parent
commit
25da0c3fa7
3 changed files with 21 additions and 4 deletions
  1. +15
    -4
      mindspore/ops/_grad/grad_math_ops.py
  2. +2
    -0
      mindspore/ops/operations/array_ops.py
  3. +4
    -0
      mindspore/ops/operations/math_ops.py

+ 15
- 4
mindspore/ops/_grad/grad_math_ops.py View File

@@ -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



+ 2
- 0
mindspore/ops/operations/array_ops.py View File

@@ -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




+ 4
- 0
mindspore/ops/operations/math_ops.py View File

@@ -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):


Loading…
Cancel
Save