This document is relevant for: Trn1, Trn2, Trn3

nki.language.softmax#

nki.language.softmax(x, axis=-1, dtype=None)[source]#

Softmax activation function on the input, element-wise.

((Similar to torch.nn.functional.softmax))

Warning

This API is experimental and may change in future releases.

Parameters:
  • x – a tile.

  • axis – int or tuple/list of ints. The axis (or axes) along which to operate; must be free dimensions, not partition dimension (0); can only be the last contiguous dim(s) of the tile: [1], [1,2], [1,2,3], [1,2,3,4]

  • dtype – (optional) data type to cast the output type to (see Supported Data Types for more information); if not specified, it will default to be the same as the data type of the input tile.

Returns:

a tile that has softmax of x.

Examples:

import nki.language as nl

# nki.language.softmax -- uniform input produces uniform output
a = nl.full((128, 512), 1.0, dtype=nl.float32, buffer=nl.sbuf)
result = nl.softmax(a, axis=1)

This document is relevant for: Trn1, Trn2, Trn3