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)

Applies clamp to input_tensor element-wise.

Parameters:

input_tensor (ttnn.Tensor) – the input tensor.

Keyword Arguments:
  • min (ttnn.Tensor or number) – Minimum value. Defaults to None.

  • max (ttnn.Tensor or number) – Maximum value. Defaults to None.

  • memory_config (ttnn.MemoryConfig, optional) – Memory configuration for the operation. Defaults to None.

  • output_tensor (ttnn.Tensor, optional) – preallocated output tensor. Defaults to None.

  • queue_id (int, optional) – command queue id. Defaults to 0.

Returns:

ttnn.Tensor – the output tensor.

Note

Supported dtypes, layouts, and ranks:

Dtypes

Layouts

BFLOAT16, BFLOAT8_B, INT32, FLOAT32

TILE

INT32 is supported only for Tensor-scalar-scalar version.

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)