ttnn.ones

ttnn.ones(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 1.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 1.0.

Note:

Example

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