ttnn.zeros

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

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

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

  • 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.

Note

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

Returns:

ttnn.Tensor – A tensor filled with 0.0.

Note

Supported dtypes, layouts, and ranks:

Dtypes

Layouts

Ranks

BFLOAT16, FLOAT32

ROW_MAJOR, TILE

2, 3, 4

Example

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