Rate this Page
★ ★ ★ ★ ★

torch.func._random.split#

torch.func._random.split(key, num=2)[source]#

Split a PRNG key into num new independent keys.

Each returned key produces a different, deterministic random sequence. This is the primary mechanism for deriving multiple independent keys from a single parent key without mutating any state.

Supports batched keys: if key has shape (*batch, K), each key in the batch is split independently and the result has shape (num, *batch, K).

Parameters:
Returns:

A tensor of shape (num, *key.shape) containing the derived keys.

Return type:

Tensor

Example:

>>> key = torch.func._random.key(42, device="cuda")  
>>> k1, k2 = torch.func._random.split(key)