MCPcopy Create free account
hub / github.com/MegEngine/MegEngine / softmax_grad

Function softmax_grad

imperative/python/megengine/xla/rules/nn.py:722–727  ·  view source on GitHub ↗
(y: HLOTensor, dy: HLOTensor, axis: int = -1)

Source from the content-addressed store, hash-verified

720
721
722def softmax_grad(y: HLOTensor, dy: HLOTensor, axis: int = -1):
723 assert isinstance(axis, int), f"axis should be int, but get {axis}({type(axis)})"
724 ydy = y * dy
725 ydy_sum = ydy.sum(axis=axis, keepdims=True)
726 dx = ydy - y * ydy_sum
727 return dx
728
729
730@register_lower_rule(mops.Softmax)

Callers 1

softmax_backward_lowerFunction · 0.85

Calls 1

sumMethod · 0.45

Tested by

no test coverage detected