ttnn.clamp

ttnn.clamp = Operation(python_fully_qualified_name='ttnn.clamp', function=<ttnn._ttnn.operations.unary.clamp_t object>, preprocess_golden_function_inputs=<function default_preprocess_golden_function_inputs>, golden_function=<function _golden_function_clamp>, postprocess_golden_function_outputs=<function default_postprocess_golden_function_outputs>, is_cpp_operation=True, is_experimental=False)

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)