MCPcopy Create free account
hub / github.com/apache/singa / backward

Method backward

python/singa/autograd.py:4044–4058  ·  view source on GitHub ↗

backward of ReduceSum Args: dy (CTensor): gradient tensor. Returns: the gradient tensor over input tensor.

(self, dy)

Source from the content-addressed store, hash-verified

4042 return _x.data
4043
4044 def backward(self, dy):
4045 """
4046 backward of ReduceSum
4047 Args:
4048 dy (CTensor): gradient tensor.
4049 Returns:
4050 the gradient tensor over input tensor.
4051 """
4052 x_shape, x = self.cache
4053 dy = singa.Reshape(dy, x_shape)
4054 scale = np.prod(x_shape) / np.prod(x.shape())
4055 mask = singa.Tensor(list(x.shape()), x.device())
4056 mask.SetFloatValue(scale)
4057 dy = singa.__mul__(mask, dy)
4058 return dy
4059
4060
4061def reduce_sum(x, axes=None, keepdims=1):

Callers

nothing calls this directly

Calls 4

shapeMethod · 0.80
TensorMethod · 0.80
deviceMethod · 0.80
__mul__Method · 0.45

Tested by

no test coverage detected