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 *reshape_tile_mode: Advanced option. Set to RECREATE to recompute and reallocate the mapping tensor. This may alleviate DRAM fragmentation but is slow. Default is CACHE. This keyword is namedreshape_tile_modeon all overloads; the small-vector (tuple/list) shape overload previously used the namerecreate_mapping_tensorfor the same option—update callers toreshape_tile_mode. :kwtype *reshape_tile_mode: TileReshapeMapMode :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 :keyword *skip_padding_fill: If False,pad_valueis applied to tile padding lanes. If True,pad_valueis ignored and tile padding is left as-is. Default is False. Note: this option is silently ignored forBFLOAT8_Boutputs because the BF8 typecast computes a shared exponent across each 16-element sub-block, and unfilled padding would corrupt logical values in straddling sub-blocks; the fill always runs in that case. :kwtype *skip_padding_fill: bool- 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])