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

Function unsqueeze

tensorrt_llm/functional.py:1930–1958  ·  view source on GitHub ↗

Add an operation to insert a singleton dimension to a tensor. That functions creates an operation that insert a singleton dimension (dimension of size 1) at position 'axis' in the output tensor. It works with negative values for the 'axis'. For example, for a tensor 'input' of

(input: Tensor, axis: int)

Source from the content-addressed store, hash-verified

1928
1929
1930def unsqueeze(input: Tensor, axis: int):
1931 '''
1932 Add an operation to insert a singleton dimension to a tensor.
1933
1934 That functions creates an operation that insert a singleton dimension
1935 (dimension of size 1) at position 'axis' in the output tensor. It works with
1936 negative values for the 'axis'.
1937
1938 For example, for a tensor 'input' of shape [4, 4]:
1939
1940 unsqueeze(input, 0) will produce an output of shape [1, 4, 4],
1941 unsqueeze(input, 1) will produce an output of shape [4, 1, 4],
1942 unsqueeze(input, -1) will produce an output of shape [4, 4, 1],
1943 unsqueeze(input, -2) will produce an output of shape [4, 1, 4],
1944
1945 Parameters:
1946 input : Tensor
1947 The input tensor to expand with a singleton dimension.
1948
1949 axis : int
1950 The index of the singleton dimension in the output tensor.
1951
1952 Returns:
1953 The tensor produced by the layer.
1954 '''
1955 if axis < 0:
1956 axis = axis + input.ndim() + 1
1957
1958 return expand_dims(input, axis)
1959
1960
1961def stack(inputs: Sequence[Tensor], dim: int = 0) -> Tensor:

Callers 15

forwardMethod · 0.90
_validate_draft_tokensFunction · 0.90
_get_packed_position_idsFunction · 0.90
_get_draft_token_arrayFunction · 0.90
_get_maskFunction · 0.90
_add_decoding_dimFunction · 0.90
_beam_search_candidatesFunction · 0.90
_prepare_drafter_inputFunction · 0.90
_process_gen_logitsFunction · 0.90
unsqueezeMethod · 0.85

Calls 2

expand_dimsFunction · 0.85
ndimMethod · 0.45

Tested by

no test coverage detected