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.TensorThe output uninitialized tensor with the same shape as the input tensor.
Note
Supported dtypes and layouts:
Dtypes
Layouts
BFLOAT16, FLOAT32, BFLOAT8_B, BFLOAT4_B, UINT8, UINT16, UINT32, INT8, INT32
TILE, ROW_MAJOR
BFLOAT8_B and BFLOAT4_B are supported only on TILE layout.
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)