MCPcopy
hub / github.com/NVIDIA/TensorRT-LLM / softmax

Function softmax

tensorrt_llm/functional.py:2639–2667  ·  view source on GitHub ↗

Add an operation to compute softmax on a tensor. That operation computes the softmax on the input tensor in the dimension 'dim' if specified. Otherwise, it is applied on the last dimension. It inserts a ISoftmaxLayer to the TensorRT graph. Parameters: input : Tensor

(input: Tensor, dim: Optional[int] = None)

Source from the content-addressed store, hash-verified

2637
2638
2639def softmax(input: Tensor, dim: Optional[int] = None) -> Tensor:
2640 '''
2641 Add an operation to compute softmax on a tensor.
2642
2643 That operation computes the softmax on the input tensor in the dimension
2644 'dim' if specified. Otherwise, it is applied on the last dimension.
2645
2646 It inserts a ISoftmaxLayer to the TensorRT graph.
2647
2648 Parameters:
2649 input : Tensor
2650 The input tensor on which to apply softmax.
2651
2652 dim : Optional[int]
2653 The dimension used to apply softmax.
2654
2655 Returns:
2656 The output tensor of the softmax layer.
2657 '''
2658 if dim is None:
2659 dim = input.ndim() - 1
2660 if dim < 0:
2661 dim = input.ndim() + dim
2662 axes = dim_to_trt_axes(dim)
2663
2664 layer = default_trtnet().add_softmax(input.trt_tensor)
2665 layer.axes = axes
2666
2667 return _create_tensor(layer.get_output(0), layer)
2668
2669
2670def _lookup_plugin(input: Tensor, weight: Tensor, rank: int,

Callers 13

_ctx_logits2probsFunction · 0.90
forwardMethod · 0.85
forwardMethod · 0.85
default_routingMethod · 0.85
renormalizeMethod · 0.85
group_limited_greedyMethod · 0.85
mask_and_softmaxMethod · 0.85
forwardMethod · 0.85
forwardMethod · 0.85
joint_attn_forwardMethod · 0.85
forwardMethod · 0.85
forwardMethod · 0.85

Calls 5

dim_to_trt_axesFunction · 0.85
default_trtnetFunction · 0.85
_create_tensorFunction · 0.85
ndimMethod · 0.45
get_outputMethod · 0.45

Tested by

no test coverage detected