MCPcopy Index your code
hub / github.com/NVIDIA/TensorRT-LLM / softplus

Function softplus

tensorrt_llm/functional.py:3463–3490  ·  view source on GitHub ↗

Add the softplus activation base on PyTorch definition. See https://pytorch.org/docs/stable/generated/torch.nn.functional.softplus.html#torch-nn-functional-softplus for a description of that function. Parameters: input : Tensor Input TensorRT LLM Tensor.

(input: Tensor, beta: float, threshold: float)

Source from the content-addressed store, hash-verified

3461
3462
3463def softplus(input: Tensor, beta: float, threshold: float) -> Tensor:
3464 '''
3465 Add the softplus activation base on PyTorch definition.
3466
3467 See https://pytorch.org/docs/stable/generated/torch.nn.functional.softplus.html#torch-nn-functional-softplus for a
3468 description of that function.
3469
3470 Parameters:
3471 input : Tensor
3472 Input TensorRT LLM Tensor.
3473 beta : float
3474 The parameter for softplus computation.
3475 threshold : float
3476 The threshold for reverting to the linear function when input * beta > threshold
3477
3478 Returns:
3479 The output tensor created by that layer.
3480 '''
3481 sf_layer = default_trtnet().add_activation(input.trt_tensor,
3482 trt.ActivationType.SOFTPLUS)
3483 sf_layer.alpha = 1 / beta
3484 sf_layer.beta = beta
3485
3486 prod_tensor = input * beta
3487 result = prod_tensor > threshold
3488
3489 return where(result, input, _create_tensor(sf_layer.get_output(0),
3490 sf_layer))
3491
3492
3493def outer(input: Tensor, vec2: Tensor) -> Tensor:

Callers

nothing calls this directly

Calls 4

default_trtnetFunction · 0.85
whereFunction · 0.85
_create_tensorFunction · 0.85
get_outputMethod · 0.45

Tested by

no test coverage detected