ttnn.empty_like

ttnn.empty_like(tensor: ttnn.Tensor, *, dtype: ttnn.DataType = the input tensor's dtype, layout: ttnn.Layout = the input tensor's layout, device: ttnn.Device | ttnn.MeshDevice = the input tensor's device, memory_config: ttnn.MemoryConfig = the input tensor's memory config) ttnn.Tensor

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

Parameters:

tensor (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 the input tensor’s dtype.

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

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

  • memory_config (ttnn.MemoryConfig, optional) – The memory configuration for the operation. Defaults to the input tensor’s memory config.

Returns:

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

Example

# Create a TT-NN tensor with the same shape and data type as another tensor
reference_tensor = ttnn.rand((4, 5), dtype=ttnn.bfloat16, device=device)
tensor = ttnn.empty_like(reference_tensor, dtype=ttnn.float32, device=device)
logger.info("TT-NN empty_like tensor shape:", tensor.shape)