For the complete documentation index, see llms.txt. Markdown versions of all pages are available by appending .md to any URL (e.g. /max/get-started.md).
Mojo function
logsoftmax
def logsoftmax[dtype: DType, simd_width: Int, rank: Int, input_fn: def[_simd_width: Int](Coord[**?]) capturing thin -> SIMD[dtype, _simd_width], target: StringSlice[ImmStaticOrigin] = StringSlice("cpu"), has_prologue_fusion: Bool = True](shape: Coord, output: TileTensor[dtype, Storage=output.Storage, address_space=output.address_space, linear_idx_type=output.linear_idx_type], axis: Int, context: Optional[DeviceContext] = None)
Computes log-softmax over the given axis using a caller-supplied input lambda.
Delegates to softmax with logsoftmax=True, which applies an elementwise
log to the normalized outputs.
Parameters:
- βdtype (
DType): The dtype of the input and output buffers. - βsimd_width (
Int): The simd_width to use in vectorization. - βrank (
Int): The rank of the input and output tensors. - βinput_fn (
def[_simd_width: Int](Coord[**?]) capturing thin -> SIMD[dtype, _simd_width]): The elementwise input lambda. - βtarget (
StringSlice[ImmStaticOrigin]): The target device ("cpu" or "gpu"). - βhas_prologue_fusion (
Bool): Whether the input lambda supports prologue fusion.
Args:
- βshape (
Coord): The shape of the output tensor. - βoutput (
TileTensor[dtype, Storage=output.Storage, address_space=output.address_space, linear_idx_type=output.linear_idx_type]): The output buffer in which to store the log-softmax values. - βaxis (
Int): The axis along which to compute the log-softmax. - βcontext (
Optional[DeviceContext]): Optional device context for GPU execution.
def logsoftmax[dtype: DType, simd_width: Int, rank: Int, target: StringSlice[ImmStaticOrigin] = StringSlice("cpu")](input: TileTensor[dtype, Storage=input.Storage, address_space=input.address_space, linear_idx_type=input.linear_idx_type], output: TileTensor[dtype, Storage=output.Storage, address_space=output.address_space, linear_idx_type=output.linear_idx_type], axis: Int, context: Optional[DeviceContext] = None)
Computes log-softmax over the given axis of input and stores the result in output.
Wraps input with a load lambda and delegates to softmax with
logsoftmax=True.
Parameters:
- βdtype (
DType): The dtype of the input and output buffers. - βsimd_width (
Int): The simd_width to use in vectorization. - βrank (
Int): The rank of the input and output tensors. - βtarget (
StringSlice[ImmStaticOrigin]): The target device ("cpu" or "gpu").
Args:
- βinput (
TileTensor[dtype, Storage=input.Storage, address_space=input.address_space, linear_idx_type=input.linear_idx_type]): The input buffer used to compute the log-softmax. - βoutput (
TileTensor[dtype, Storage=output.Storage, address_space=output.address_space, linear_idx_type=output.linear_idx_type]): The output buffer in which to store the log-softmax values. - βaxis (
Int): The axis along which to compute the log-softmax. - βcontext (
Optional[DeviceContext]): Optional device context for GPU execution.
Was this page helpful?
Thank you! We'll create more content like this.
Thank you for helping us improve!