MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / _MulNoNanGrad

Function _MulNoNanGrad

tensorflow/python/ops/math_grad.py:1202–1216  ·  view source on GitHub ↗

The gradient of scalar multiplication with NaN-suppression.

(op, grad)

Source from the content-addressed store, hash-verified

1200
1201@ops.RegisterGradient("MulNoNan")
1202def _MulNoNanGrad(op, grad):
1203 """The gradient of scalar multiplication with NaN-suppression."""
1204 x = op.inputs[0]
1205 y = op.inputs[1]
1206 if (isinstance(grad, ops.Tensor) and
1207 _ShapesFullySpecifiedAndEqual(x, y, grad)):
1208 return gen_math_ops.mul_no_nan(grad, y), gen_math_ops.mul_no_nan(x, grad)
1209 assert x.dtype.base_dtype == y.dtype.base_dtype, (x.dtype, " vs. ", y.dtype)
1210 sx = array_ops.shape(x)
1211 sy = array_ops.shape(y)
1212 rx, ry = gen_array_ops.broadcast_gradient_args(sx, sy)
1213 return (array_ops.reshape(
1214 math_ops.reduce_sum(gen_math_ops.mul_no_nan(grad, y), rx), sx),
1215 array_ops.reshape(
1216 math_ops.reduce_sum(gen_math_ops.mul_no_nan(x, grad), ry), sy))
1217
1218
1219@ops.RegisterGradient("Div")

Callers

nothing calls this directly

Calls 4

reshapeMethod · 0.80
reduce_sumMethod · 0.80
shapeMethod · 0.45

Tested by

no test coverage detected