ttnn.clamp
- ttnn.clamp(input_tensor: ttnn.Tensor, *, min: float or ttnn.Tensor = None, max: float or ttnn.Tensor = None, memory_config: ttnn.MemoryConfig | None = None) ttnn.Tensor
-
Performs clamp function on
input_tensor
,min
,max
. Only one of ‘min’ or ‘max’ value can be None.- Parameters:
-
input_tensor (ttnn.Tensor) – the input tensor.
- Keyword Arguments:
-
min (float or ttnn.Tensor) – Minimum value. Defaults to None.
max (float or ttnn.Tensor) – Maximum value. Defaults to None.
memory_config (ttnn.MemoryConfig, optional) – Memory configuration for the operation. Defaults to None.
- Returns:
-
ttnn.Tensor – the output tensor.
Note
Supported dtypes, layouts, and ranks:
Dtypes
Layouts
Ranks
BFLOAT16
TILE
2, 3, 4
Example
>>> input_tensor = ttnn.from_torch(torch.tensor([[1, 2], [3,4]], dtype=torch.bfloat16), dtype=ttnn.bfloat16, layout=ttnn.TILE_LAYOUT, device=device) >>> min_tensor = ttnn.from_torch(torch.tensor([[0, 2], [0,4]], dtype=torch.bfloat16), dtype=ttnn.bfloat16, layout=ttnn.TILE_LAYOUT, device=device) >>> max_tensor = ttnn.from_torch(torch.tensor([[1, 2], [3,4]], dtype=torch.bfloat16), dtype=ttnn.bfloat16, layout=ttnn.TILE_LAYOUT, device=device) >>> output = ttnn.clamp(input_tensor, min_tensor, max_tensor)
>>> input_tensor = ttnn.from_torch(torch.tensor([[1, 2], [3,4]], dtype=torch.bfloat16), dtype=ttnn.bfloat16, layout=ttnn.TILE_LAYOUT, device=device) >>> output = ttnn.clamp(input_tensor, min = 2, max = 9)