ttnn.zeros

ttnn.zeros(shape: ttnn.Shape, dtype: ttnn.DataType | None = None, layout: ttnn.Layout | None = None, device: ttnn.Device | ttnn.MeshDevice | None = None, memory_config: ttnn.MemoryConfig | None = 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

>>> tensor = ttnn.zeros(shape=[1, 2, 2, 2], dtype=ttnn.bfloat16, layout=ttnn.ROW_MAJOR_LAYOUT)
>>> print(tensor)
ttnn.Tensor([[[[0.0, 0.0],
                [0.0, 0.0]],
                [[0.0, 0.0],
                [0.0, 0.0]]]]], shape=Shape([1, 2, 2, 2]), dtype=DataType::BFLOAT16, layout=Layout::ROW_MAJOR)