ttnn.rand
- ttnn.rand(*, 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, low: float | None, high: float | None, seed: int | None) ttnn.Tensor
-
Generates a tensor with the given shape, filled with random values from a uniform distribution. based on the specified data type:
-
- DataType.float32 / bfloat16 / bfloat4_b / bfloat8_b:
-
Floating-point values in range [0.0, 1.0)
-
- Integer data types:
-
Not supported for uniform random generation.
- Parameters:
-
shape (list[int]) –
- 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.
low (float, optional) – The lower bound of the range (inclusive).
high (float, optional) – The upper bound of the range (exclusive).
seed (int, optional) – An optional seed to initialize the random number generator for reproducible results. Defaults to 0.
- Returns:
-
ttnn.Tensor – A tensor with specified shape, dtype, and layout containing random values.
Example
# Create a TT-NN tensor with random values uniformly distributed between 0 and 1 tensor = ttnn.rand(shape=[2, 3], dtype=ttnn.bfloat16, layout=ttnn.ROW_MAJOR_LAYOUT, device=device) logger.info("TT-NN rand tensor:", tensor)
-