ttnn.from_buffer
- ttnn.from_buffer(buffer: List[Any], shape: ttnn.Shape, dtype: ttnn.DataType, device: ttnn.Device | ttnn.MeshDevice, layout: ttnn.Layout = ttnn.ROW_MAJOR, memory_config: ttnn.MemoryConfig = ttnn.DRAM_MEMORY_CONFIG) ttnn.Tensor
-
Creates a device tensor with values from a buffer of the specified data type, layout, and memory configuration.
- Parameters:
-
buffer (List[Any])The buffer to be used to create the tensor.
shape (ttnn.Shape)The shape of the tensor to be created.
dtype (ttnn.DataType)The tensor data type.
device (ttnn.Device | ttnn.MeshDevice)The device where the tensor will be allocated.
layout (ttnn.Layout, optional)The tensor layout. Defaults to ttnn.ROW_MAJOR.
memory_config (ttnn.MemoryConfig, optional)The memory configuration for the operation. Defaults to ttnn.DRAM_MEMORY_CONFIG.
- Returns:
-
ttnn.TensorA tensor with the values from the buffer.
Note
Supported dtypes and layouts:
Dtypes
Layouts
BFLOAT16, FLOAT32, UINT8, INT8, UINT16, UINT32, INT32
TILE, ROW_MAJOR
The buffer element type must be compatible with dtype. BFLOAT8_B, BFLOAT4_B, and FP8_E4M3 are not supported for host-side construction.
Example
# Create a TT-NN tensor from a Python buffer (list) buffer = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0] tensor = ttnn.from_buffer( buffer=buffer, shape=[2, 3], dtype=ttnn.bfloat16, layout=ttnn.ROW_MAJOR_LAYOUT, device=device ) logger.info("TT-NN from_buffer tensor:", tensor)