ttnn.reshape

ttnn.reshape() ttnn.Tensor
Note: for a 0 cost view, the following conditions must be met:
  • the last dimension must not change

  • In Tiled the second last two dimensions must not change OR there is no padding on the second last dimension

Parameters:
  • input_tensor (*) – Input Tensor.

  • shape (*) – Shape of tensor.

:keyword * memory_config: Memory Config of the output tensor. Default is to match input tensor memory config :keyword * pad_value: Value to pad the output tensor. Default is 0 :kwtype * pad_value: number :keyword * recreate_mapping_tensor: Advanced option. Set to true to recompute and realloc mapping tensor. This may alleviate DRAM fragmentation but is slow. :kwtype * recreate_mapping_tensor: bool :keyword * sub_core_grids: Specifies sub-core grid ranges for advanced core selection control. Default uses all the cores in the device. :kwtype * sub_core_grids: CoreRangeSet, optional

Returns:

ttnn.Tensor – the output tensor with the new shape.

Example

# Create a tensor to reshape
input_tensor = torch.arange(4, dtype=torch.bfloat16)
input_tensor_tt = ttnn.from_torch(input_tensor, device=device)

# Reshape the tensor
reshaped_tensor = ttnn.reshape(input_tensor_tt, (1, 1, 2, 2))
logger.info("Reshaped Tensor Shape:", reshaped_tensor.shape)  # Reshaped Tensor Shape: Shape([1, 1, 2, 2])