ttnn.repeat

ttnn.repeat(input_tensor: ttnn.Tensor, repeat_dims: List[int], *, memory_config: ttnn.MemoryConfig = None, optional_output_tensor: ttnn.Tensor = None) → ttnn.Tensor

Returns a tensor that repeats input_tensor along each dimension the number of times given in repeat_dims.

Parameters:
  • input_tensor (ttnn.Tensor)the input tensor.

  • repeat_dims (List[int])the number of repetitions for each dimension. A list shorter than the tensor’s rank is padded with 1s at the front, and a longer list adds leading dimensions to the output.

Keyword Arguments:
  • memory_config (ttnn.MemoryConfig, optional)Memory configuration for the operation. Defaults to None: an interleaved input keeps its memory configuration. A sharded input keeps its memory layout and buffer type, with a shard spec derived for the output shape, when such a spec can be derived; otherwise, and for an empty output, the output is interleaved in the input’s buffer type. When optional_output_tensor is given, the output uses its memory configuration.

  • optional_output_tensor (ttnn.Tensor, optional)Preallocated output tensor, with the output’s shape, dtype and layout. Defaults to None.

Returns:

ttnn.Tensorthe output tensor, with the same dtype and layout as the input.

Note

Supported dtypes and layouts:

Dtypes

Layouts

BFLOAT16, FLOAT32, INT32, UINT32, UINT16

TILE, ROW_MAJOR

BFLOAT8_B

TILE

A 0 in repeat_dims returns an empty tensor.

For a BFLOAT16 TILE input whose last two dims are not both multiples of 32, input values must not be NaN.

Memory Support:
  • Interleaved: DRAM and L1

  • Sharded: HEIGHT_SHARDED, WIDTH_SHARDED and BLOCK_SHARDED input and output in L1; DRAM-sharded input is also accepted with an interleaved memory_config

  • ND sharded: DRAM and L1

Example

# Create a tensor to repeat
input_tensor = torch.tensor([[1, 2], [3, 4]])
input_tensor_tt = ttnn.from_torch(input_tensor, device=device)

# Repeat the tensor along specified dimensions
repeated_tensor = ttnn.repeat(input_tensor_tt, (1, 2))
logger.info(f"Repeated Tensor Shape: {repeated_tensor.shape}")  # Shape([2, 4])