ttnn.softshrink
- ttnn.softshrink(input_tensor: ttnn.Tensor, *, lambd: float = 0.5, memory_config: ttnn.MemoryConfig = None, output_tensor: ttnn.Tensor = None, sub_core_grids: ttnn.CoreRangeSet = None) ttnn.Tensor
-
Applies softshrink to
input_tensorelement-wise with lambd.The lambda parameter for the softshrink function
\[\mathrm{output\_tensor}_i = \verb|softshrink|(\mathrm{input\_tensor}_i, \verb|lambd|)\]- Parameters:
-
input_tensor (ttnn.Tensor) – the input tensor.
- Keyword Arguments:
-
lambd (float) – Defaults to 0.5.
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
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, ) # Apply soft shrinkage function output = ttnn.softshrink(tensor, lambd=5) logger.info(f"Soft shrink: {output}")