Rate this Page

helion.language.rand#

helion.language.rand(shape, seed, device=None)[source]#

hl.rand provides a Philox-based pseudorandom number generator (PRNG) that operates independently of PyTorch’s global random seed. Instead, it requires an explicit seed argument. Offsets are derived from the full logical sizes of the tiles specified in the shape argument.

Parameters:
  • shape (list[object]) – A list of sizes for the output tensor

  • seed (int | Tensor) – A single element int64 tensor or int literal

  • device (device | None) – Device must match the current compile environment device

Returns:

A device tensor of float32 dtype filled with uniform random values in [0, 1)

Return type:

torch.Tensor

Examples

@helion.kernel
def process_kernel(x: torch.Tensor) -> torch.Tensor:
    output = torch.zeros_like(x)
    (m,) = x.shape
    for tile_m in hl.tile(m):
        output[tile_m] = hl.rand([tile_m], seed=42)
    return output