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
Methods:
-
set_random_stateβGive the object its own random stream, or return it to the global generator.
set_random_state [source] ΒΆ
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
seedandstateare given.
seed_everything [source] ΒΆ
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 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.