ttnn.randn
- ttnn.randn(shape: list[int], *, device: ttnn.Device | ttnn.MeshDevice = None, dtype: ttnn.DataType = ttnn.bfloat16, layout: ttnn.Layout = ttnn.TILE_LAYOUT, memory_config: ttnn.MemoryConfig = ttnn.DRAM_MEMORY_CONFIG, compute_kernel_config: ttnn.DeviceComputeKernelConfig = None, seed: int = None) ttnn.Tensor
-
Generates a tensor with the given shape, filled with random values from a standard normal distribution. Internally, this operation uses the Box-Muller transform to generate normally distributed random values.
- Parameters:
-
shape (list[int]) – a list of integers defining the shape of the output tensor.
- Keyword Arguments:
-
device (ttnn.Device | ttnn.MeshDevice, optional) – The device on which the tensor will be allocated. Defaults to None.
dtype (ttnn.DataType, optional) – The data type of the tensor. Defaults to ttnn.bfloat16.
layout (ttnn.Layout, optional) – The layout of the tensor. Defaults to ttnn.TILE_LAYOUT.
memory_config (ttnn.MemoryConfig, optional) – Memory configuration for the operation. Defaults to ttnn.DRAM_MEMORY_CONFIG.
compute_kernel_config (ttnn.DeviceComputeKernelConfig, optional) – Configuration for the compute kernel. Defaults to None.
seed (int, optional) – An optional seed to initialize the random number generator for reproducible results. Defaults to None.
- Returns:
-
ttnn.Tensor – the output tensor.
Note
The output tensor supports the following data types and layouts:
Output Tensor dtype
layout
FLOAT32
ROW_MAJOR, TILE
BFLOAT16
ROW_MAJOR, TILE
Note
Memory layout support: interleaved DRAM and L1.
Example
# Create a TT-NN tensor with random values standard normal distributed tensor = ttnn.randn(shape=[2, 3], dtype=ttnn.bfloat16, layout=ttnn.ROW_MAJOR_LAYOUT, device=device) logger.info("TT-NN randn tensor:", tensor)