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 unless dtype is ttnn.bfloat4 or ttnn.bfloat8, in which case it defaults to ttnn.TILE.

  • memory_config (ttnn.MemoryConfig, optional) – The memory configuration for the operation. Defaults to ttnn.DRAM_MEMORY_CONFIG.

Returns:

ttnn.Tensor – A tensor with the values from the buffer.

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)