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

Function softmax

imperative/python/megengine/xla/rules/nn.py:713–719  ·  view source on GitHub ↗
(x: HLOTensor, axis: int = -1)

Source from the content-addressed store, hash-verified

711
712
713def softmax(x: HLOTensor, axis: int = -1):
714 assert isinstance(axis, int), f"axis should be int, but get {axis}({type(axis)})"
715 x_max = x.max(axis=axis, keepdims=True)
716 x_exp = exp(x - x_max)
717 x_exp_sum = x_exp.sum(axis=axis, keepdims=True)
718 y = x_exp / x_exp_sum
719 return y
720
721
722def softmax_grad(y: HLOTensor, dy: HLOTensor, axis: int = -1):

Callers 2

softmax_lowerFunction · 0.70
forwardMethod · 0.50

Calls 3

expFunction · 0.50
maxMethod · 0.45
sumMethod · 0.45

Tested by

no test coverage detected