ttnn.empty_like

ttnn.empty_like(reference: ttnn.Tensor, *, dtype: ttnn.DataType | None = ttnn.bfloat16, layout: ttnn.Layout | None = ttnn.ROW_MAJOR, device: ttnn.Device | ttnn.MeshDevice | None = None, memory_config: ttnn.MemoryConfig | None = ttnn.DRAM_MEMORY_CONFIG) ttnn.Tensor

Creates a new tensor with the same shape as the given reference, but without initializing its values. The data type, layout, device, and memory configuration of the new tensor can be specified.

Parameters:

reference (ttnn.Tensor) – The reference tensor whose shape will be used for the output tensor.

Keyword Arguments:
  • dtype (ttnn.DataType, optional) – The desired data type of the output tensor. Defaults to ttnn.bfloat16.

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

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

  • memory_config (ttnn.MemoryConfig, optional) – The memory configuration for the operation. Defaults to ttnn.DRAM_MEMORY_CONFIG.

Returns:

ttnn.Tensor – The output uninitialized tensor with the same shape as the reference tensor.

Example

>>> reference = ttnn.from_torch(torch.randn(2, 3), dtype=ttnn.bfloat16)
>>> tensor = ttnn.empty_like(reference, dtype=ttnn.float32)
>>> print(tensor)
ttnn.Tensor([[[[0.87, 0.45, 0.22], [0.60, 0.75, 0.25]]]], shape=Shape([2, 3]), dtype=DataType::BFLOAT16, layout=Layout::ROW_MAJOR)