ttnn.full

ttnn.full(shape: ttnn.Shape, fill_value: float, dtype: ttnn.DataType = None, layout: ttnn.Layout = None, device: ttnn.Device | ttnn.MeshDevice = None, memory_config: ttnn.MemoryConfig = None, output_tensor: ttnn.Tensor = None) ttnn.Tensor

Creates a tensor of the specified shape and fills it with the specified scalar value.

Parameters:
  • shape (ttnn.Shape) – The shape of the tensor.

  • fill_value (float) – The value to fill the tensor with.

  • dtype (ttnn.DataType, optional) – The data type of the tensor. Defaults to None.

  • layout (ttnn.Layout, optional) – The layout of the tensor. Defaults to None.

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

  • memory_config (ttnn.MemoryConfig, optional) – The memory configuration of the tensor. Defaults to None.

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

Note

ROW_MAJOR_LAYOUT requires last dimension (shape[-1]) to be a multiple of 2 with dtype BFLOAT16 or UINT16. TILE_LAYOUT requires width (shape[-1]) and height (shape[-2]) dimension to be multiple of 32.

Returns:

ttnn.Tensor – A filled tensor of specified shape and value.

Example

# Create a TT-NN tensor filled with a specified value
tensor = ttnn.full(shape=[2, 2], fill_value=7.0, dtype=ttnn.bfloat16, layout=ttnn.ROW_MAJOR_LAYOUT, device=device)
logger.info("TT-NN full tensor:", tensor)