ttnn.ones_like

ttnn.ones_like(tensor: ttnn.Tensor, dtype: ttnn.DataType = the input tensor's dtype, layout: ttnn.Layout = the input tensor's layout, device: ttnn.Device | ttnn.MeshDevice = the input tensor's device, memory_config: ttnn.MemoryConfig = the input tensor's memory config, output_tensor: ttnn.Tensor = None) → ttnn.Tensor

Creates a tensor of the same shape as the input tensor and fills it with the value of 1.0. The data type, layout, device, and memory configuration of the resulting tensor can be specified.

Parameters:
  • tensor (ttnn.Tensor)The tensor to use as a template for the shape of the new tensor.

  • dtype (ttnn.DataType, optional)The data type of the tensor. Defaults to the input tensor’s dtype.

  • layout (ttnn.Layout, optional)The layout of the tensor. Defaults to the input tensor’s layout.

  • device (ttnn.Device | ttnn.MeshDevice, optional)The device on which the tensor will be allocated. Defaults to the input tensor’s device.

  • memory_config (ttnn.MemoryConfig, optional)The memory configuration of the tensor. Defaults to the input tensor’s memory config.

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

Returns:

ttnn.TensorA tensor filled with 1.0.

Note

Supported dtypes and layouts:

Dtypes

Layouts

BFLOAT16, FLOAT32, BFLOAT8_B, BFLOAT4_B, UINT8, UINT16, UINT32, INT8, INT32

TILE, ROW_MAJOR

BFLOAT8_B and BFLOAT4_B are supported only on TILE layout. ROW_MAJOR requires last dimension to be a multiple of 2 with dtype BFLOAT16 or UINT16. TILE requires width and height dimensions to be multiples of 32.

Example

# Create a TT-NN tensor filled with ones, based on the shape of another tensor
reference_tensor = ttnn.rand((3, 2), dtype=ttnn.bfloat16, layout=ttnn.TILE_LAYOUT, device=device)
tensor = ttnn.ones_like(tensor=reference_tensor, dtype=ttnn.bfloat16, layout=ttnn.TILE_LAYOUT, device=device)
logger.info("TT-NN ones_like tensor:", tensor)