ttnn.to_dtype
- ttnn.to_dtype(tensor: ttnn.Tensor, dtype: ttnn.DataType) None
-
Converts a host tensor to the desired dtype.
- Parameters:
-
tensor (ttnn.Tensor) – the tensor to be converted to the desired dtype.
dtype (ttnn.DataType) – the desired data type.
Note
This operations supports tensors according to the following data types and layout:
tensor dtype - layout
BFLOAT16, BFLOAT8_B, BFLOAT4_B, FLOAT32, UINT32, INT32, UINT16, UINT8 - TILE
BFLOAT16, FLOAT32, UINT32, INT32, UINT16, UINT8 - ROW_MAJOR
- Memory Support:
-
Interleaved: DRAM and L1
Height, Width, Block, and ND Sharded: DRAM and L1
- Limitations:
-
tensor must be on the host.
Example
# Create a TT-NN tensor on the host and convert it to a different data type tensor = ttnn.rand((10, 64, 32), device=device, dtype=ttnn.bfloat16) tensor = ttnn.from_device(tensor) # to_dtype requires a host tensor tensor = ttnn.to_dtype(tensor, dtype=ttnn.uint8) assert tensor.dtype == ttnn.uint8 assert tensor.shape == (10, 64, 32) logger.info("TT-NN tensor shape after converting to uint8", tensor.shape)