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

Function flip

tensorrt_llm/functional.py:922–963  ·  view source on GitHub ↗

Reverses the order of an n-D tensor along given axis in dims. That flip operation maps to a TensorRT ISliceLayer. For the dimensions listed in dims it copies the elements from the last one to the first one (from (N-1) down to 0 with a step of -1). For the dimensions not in 'dims',

(input: Tensor, dims: Sequence[int])

Source from the content-addressed store, hash-verified

920
921
922def flip(input: Tensor, dims: Sequence[int]) -> Tensor:
923 '''
924 Reverses the order of an n-D tensor along given axis in dims.
925
926 That flip operation maps to a TensorRT ISliceLayer. For the dimensions
927 listed in dims it copies the elements from the last one to the first one
928 (from (N-1) down to 0 with a step of -1). For the dimensions not in 'dims',
929 it copies the elements from the first one to the last one (from 0 to N-1
930 with a step of 1).
931
932 Parameters:
933 input : Tensor
934 The input tensor on which the cast is applied.
935
936 dims : list or tuple
937 The axes to flip. Negative indices are supported.
938
939 Returns:
940 The tensor produced by the inserted layer.
941 '''
942 assert not input.is_dynamic()
943
944 ndim = input.ndim()
945
946 for index, value in enumerate(dims):
947 assert -ndim <= value < ndim
948 if -ndim <= value < 0:
949 dims[index] += ndim
950
951 assert len(dims) == len(set(dims))
952
953 start_values = [
954 input.size()[i] - 1 if i in dims else 0 for i in range(ndim)
955 ]
956 stride_values = [-1 if i in dims else 1 for i in range(ndim)]
957
958 layer = default_trtnet().add_slice(input.trt_tensor,
959 start=start_values,
960 shape=input.size(),
961 stride=stride_values)
962
963 return _create_tensor(layer.get_output(0), layer)
964
965
966def interpolate(input: Tensor,

Callers

nothing calls this directly

Calls 6

default_trtnetFunction · 0.85
_create_tensorFunction · 0.85
is_dynamicMethod · 0.80
ndimMethod · 0.45
sizeMethod · 0.45
get_outputMethod · 0.45

Tested by

no test coverage detected