ttnn.clone

ttnn.clone(input: ttnn.Tensor, *, dtype: ttnn.DataType = None, memory_config: ttnn.MemoryConfig = None, compute_kernel_config: ttnn.ComputeKernelConfig = None, sub_core_grids: ttnn.CoreRangeSet = None) → ttnn.Tensor

Clones the input tensor, creating a copy with the specified memory configuration and converting its data type to dtype. This operation does not alter the tensor’s layout.

Parameters:

input (ttnn.Tensor)the input tensor to be cloned.

Keyword Arguments:
  • dtype (ttnn.DataType, optional)the target data type of the cloned tensor. Defaults to None.

  • memory_config (ttnn.MemoryConfig, optional)the memory configuration for the clone, options include DRAM_MEMORY_CONFIG or L1_MEMORY_CONFIG. Defaults to None.

  • compute_kernel_config (ttnn.ComputeKernelConfig, optional)the configuration for the compute kernel. Defaults to None.

  • sub_core_grids (ttnn.CoreRangeSet, optional)cores to run on for interleaved tensors. Defaults to None, which uses all cores.

Returns:

ttnn.Tensorthe cloned output tensor.

Note

  • ROW_MAJOR_LAYOUT: Returns the tensor unpadded in the last two dimensions.

  • TILE_LAYOUT: Pads the tensor to ensure its width and height are multiples of 32.

  • If the input’s current layout matches the specified layout, padding adjustments are applied to the last two dimensions as necessary.

Example

# Create a tensor with specific values
tensor = ttnn.rand([1, 32, 32], dtype=ttnn.bfloat16, layout=ttnn.TILE_LAYOUT, device=device)

# Clone the tensor
output = ttnn.clone(tensor, dtype=ttnn.bfloat16, memory_config=ttnn.DRAM_MEMORY_CONFIG)
logger.info(f"Clone: {output}")