ttnn.abs

ttnn.abs(input_tensor: ttnn.Tensor or ComplexTensor, *, memory_config: ttnn.MemoryConfig = None, output_tensor: ttnn.Tensor = None, sub_core_grids: ttnn.CoreRangeSet = None) ttnn.Tensor

Applies abs to input_tensor element-wise.

\[\mathrm{{output\_tensor}}_i = \verb|abs|(\mathrm{{input\_tensor}}_i)\]
Parameters:

input_tensor (ttnn.Tensor or ComplexTensor) – the input tensor.

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. When input_tensor is a ttnn.ComplexTensor, this argument is not supported.

  • sub_core_grids (ttnn.CoreRangeSet, optional) – sub core grids for the operation. Defaults to None. When input_tensor is a ttnn.ComplexTensor, this argument is not supported.

Returns:

ttnn.Tensor – the output tensor.

Note

Supported dtypes: BFLOAT16, BFLOAT8_B, FLOAT32

Example

# Create a tensor
tensor = ttnn.from_torch(
    torch.tensor([[1, 2], [3, 4]], dtype=torch.bfloat16), layout=ttnn.TILE_LAYOUT, device=device
)

# Compute the absolute value
output = ttnn.abs(tensor)
logger.info(f"Absolute value: {output}")