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

Function nonzero

tensorrt_llm/functional.py:2336–2349  ·  view source on GitHub ↗

Adds a layer that finds the indices of non-zero values of the input tensor. Parameters: input: Tensor The input tensor for which we need to find the indices of non-zero values. Returns: A tensor of shape [D, C] where D is the number of dimensions of `input`

(input: Tensor)

Source from the content-addressed store, hash-verified

2334
2335
2336def nonzero(input: Tensor) -> Tensor:
2337 '''
2338 Adds a layer that finds the indices of non-zero values of the input tensor.
2339
2340 Parameters:
2341 input: Tensor
2342 The input tensor for which we need to find the indices of non-zero values.
2343 Returns:
2344 A tensor of shape [D, C] where D is the number of dimensions of `input` and
2345 C is the number of non-zero values in it.
2346 Each column of this 2D tensor represents the index tuple for each non-zero value.
2347 '''
2348 non_zero_layer = default_trtnet().add_non_zero(input.trt_tensor)
2349 return _create_tensor(non_zero_layer.get_output(0), non_zero_layer)
2350
2351
2352def masked_select(input: Tensor, mask: Tensor) -> Tensor:

Callers 2

_get_draft_token_arrayFunction · 0.90
forward_expertsMethod · 0.85

Calls 3

default_trtnetFunction · 0.85
_create_tensorFunction · 0.85
get_outputMethod · 0.45

Tested by

no test coverage detected