ttnn.leaky_relu
- ttnn.leaky_relu(input_tensor: ttnn.Tensor, negative_slope: float, *, memory_config: ttnn.MemoryConfig = None, output_tensor: ttnn.Tensor = None, sub_core_grids: ttnn.CoreRangeSet = None) ttnn.Tensor
-
Applies leaky_relu to
input_tensorelement-wise with negative_slope.Passes non-negative inputs through unchanged and scales negative inputs by negative_slope.
\[\mathrm{output\_tensor}_i = \max(0, \mathrm{input\_tensor}_i) + \verb|negative_slope| \cdot \min(0, \mathrm{input\_tensor}_i)\]- Parameters:
-
input_tensor (ttnn.Tensor) – the input tensor.
negative_slope (float) – The slope parameter for the Leaky ReLU function.
- Keyword Arguments:
-
memory_config (ttnn.MemoryConfig, optional) – Memory configuration for the operation. Defaults to None.
output_tensor (ttnn.Tensor, optional) – preallocated output tensor. Defaults to None.
sub_core_grids (ttnn.CoreRangeSet, optional) – sub core grids for the operation. Defaults to None.
- Returns:
-
ttnn.Tensor – the output tensor.
Note
Supported dtypes and layouts:
Dtypes
Layouts
FLOAT32, BFLOAT16, BFLOAT8_B, UINT32, UINT16, UINT8
TILE, ROW_MAJOR
Example
# Create a tensor with specific values tensor = ttnn.from_torch( torch.tensor([[1, 2], [3, 4]], dtype=torch.bfloat16), dtype=ttnn.bfloat16, layout=ttnn.TILE_LAYOUT, device=device, ) negative_slope = 3 # Apply Leaky ReLU activation function output = ttnn.leaky_relu(tensor, negative_slope) logger.info(f"Leaky ReLU: {output}")