Rate this Page
★ ★ ★ ★ ★

torch.func._random.normal_#

torch.func._random.normal_(key, result, *, mean=0.0, std=1.0)[source]#

Fill result in-place with normal random values from a PRNG key.

The values are drawn from a normal distribution with the specified mean and std. The output is fully determined by the key, so calling with the same key always produces the same result.

Supports batched keys: if key has shape (*batch, K), the leading dimensions of result must be broadcastable with *batch and each key independently generates its slice of the output.

Parameters:
  • key (Tensor) – A PRNG key returned by key(), split(), or fold_in().

  • result (Tensor) – The output tensor to fill in-place.

  • mean (float) – Mean of the normal distribution. Default: 0.0.

  • std (float) – Standard deviation of the normal distribution. Default: 1.0.

Returns:

result, filled with normal random values.

Return type:

Tensor

Example:

>>> key = torch.func._random.key(42, device="cuda")  
>>> result = torch.empty(1000, device="cuda")  
>>> torch.func._random.normal_(key, result)