MCPcopy Create free account
hub / github.com/NVIDIA/TensorRT-LLM / reduce

Function reduce

tensorrt_llm/functional.py:3160–3194  ·  view source on GitHub ↗

Add an reduction operation to do along a dimension. It is implemented using the IReduceLayer from TensorRT. Parameters: input : Tensor The input tensor. op : trt.ReduceOperation The reduction operation to perform. Options: SUM, PROD

(input: Tensor,
           op: trt.ReduceOperation,
           dim: Union[int, Tuple[int]],
           keepdim: bool = False)

Source from the content-addressed store, hash-verified

3158
3159
3160def reduce(input: Tensor,
3161 op: trt.ReduceOperation,
3162 dim: Union[int, Tuple[int]],
3163 keepdim: bool = False) -> Tensor:
3164 '''
3165 Add an reduction operation to do along a dimension.
3166
3167 It is implemented using the IReduceLayer from TensorRT.
3168
3169 Parameters:
3170 input : Tensor
3171 The input tensor.
3172
3173 op : trt.ReduceOperation
3174 The reduction operation to perform.
3175 Options: SUM, PROD, MAX, MIN, AVG
3176
3177 dim : int
3178 The dimension along which the reduction is performed.
3179
3180 keepdim : bool
3181 Is the dimension kept in the reduced tensor? When True the
3182 dimension is kept, it is removed from the shape otherwise.
3183
3184 Returns:
3185 The tensor produced by this reduction operation.
3186 '''
3187 dim = dim_resolve_negative(dim, input.ndim())
3188 axes = dim_to_trt_axes(dim)
3189
3190 layer = default_trtnet().add_reduce(input.trt_tensor,
3191 op,
3192 axes,
3193 keep_dims=keepdim)
3194 return _create_tensor(layer.get_output(0), layer)
3195
3196
3197prod = partial(reduce, op=trt.ReduceOperation.PROD)

Callers 5

forwardMethod · 0.90
meanFunction · 0.85
maxFunction · 0.85
sumFunction · 0.85
volume_funcMethod · 0.85

Calls 6

dim_resolve_negativeFunction · 0.85
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