Skip to content

random

Random seeding and determinism control.

Classes:

  • Randomizable –

    Mixin for objects that draw random numbers from their own stream, set by set_random_state.

Functions:

  • seed_everything –

    Set the seed for the random number generators in PyTorch, NumPy and Python.

  • set_determinism –

    Set the TensorFloat-32 flags for fp32 CUDA matmul and cuDNN convolutions.

Randomizable [source] ΒΆ

Mixin for objects that draw random numbers from their own stream, set by set_random_state.

R is the object's generator. It is None by default, and the draws then come from the global generator, which PyTorch seeds per DataLoader worker and per epoch: one torch.manual_seed makes a run reproducible. A seeded R is copied as is into every DataLoader worker; PointCloudDataLoader re-seeds it per worker (see torch_pointcloud.utils.data.seed_worker), so that workers and epochs draw different numbers.

Example
import torch

from torch_pointcloud.transforms import RandomJitter

jitter = RandomJitter(keys="pos", sigma=0.01, seed=0)
first = jitter({"pos": torch.zeros(4, 3)})["pos"]
jitter.set_random_state(seed=0)
assert torch.equal(jitter({"pos": torch.zeros(4, 3)})["pos"], first)

Methods:

  • set_random_state –

    Give the object its own random stream, or return it to the global generator.

set_random_state [source] ΒΆ

set_random_state(
    seed: Optional[int] = None,
    state: Optional[Generator] = None,
) -> Self

Give the object its own random stream, or return it to the global generator.

Parameters:

  • seed (Optional[int], default: None ) –

    Seed of a new generator.

  • state (Optional[Generator], default: None ) –

    Generator to draw from, shared with the caller.

Returns:

  • Self –

    The object itself, for chaining.

Raises:

  • ValueError –

    If both seed and state are given.

seed_everything [source] ΒΆ

seed_everything(seed: Optional[int] = None) -> int

Set the seed for the random number generators in PyTorch, NumPy and Python.

Parameters:

  • seed (Optional[int], default: None ) –

    The seed to set for the random number generators. If None, a random seed will be selected.

Returns:

  • int –

    The seed that was set.

set_determinism [source] ΒΆ

set_determinism(*, tf32: bool = False) -> None

Set the TensorFloat-32 flags for fp32 CUDA matmul and cuDNN convolutions.

TensorFloat-32 rounds fp32 matmul/convolution inputs to 19-bit mantissas on Ampere+ GPUs, which shifts benchmark metrics relative to references measured with it off. Neither the Lightning Trainer(precision=...) flag nor torch.set_float32_matmul_precision covers the cuDNN convolution path (torch.backends.cudnn.allow_tf32 defaults to True), so both backends are pinned here. Nothing else is touched: RNG seeding is seed_everything, and deterministic kernel selection (torch.use_deterministic_algorithms, torch.backends.cudnn.deterministic) is not enabled.

Parameters:

  • tf32 (bool, default: False ) –

    Allow TensorFloat-32 in fp32 CUDA matmul and cuDNN convolutions.

Example
>>> set_determinism(tf32=False)
>>> torch.backends.cudnn.allow_tf32
False