gigl.common.utils.compute.random#
Matches the set_seed(seed, deterministic=False) shape used by
Hugging Face Transformers, MMEngine, and Accelerate; follows the recipe
at https://pytorch.org/docs/stable/notes/randomness.html.
Attributes#
Functions#
|
Seed Python / NumPy / PyTorch RNGs, optionally enforce deterministic torch ops. |
Module Contents#
- gigl.common.utils.compute.random.seed_everything(seed=_DEFAULT_SEED, should_enable_expensive_deterministic_compute=False)[source]#
Seed Python / NumPy / PyTorch RNGs, optionally enforce deterministic torch ops.
What gets seeded:
random.seed(seed)— Python stdlib.np.random.seed(seed)— NumPy global RNG.torch.manual_seed(seed)— CPU and all CUDA devices (torch.manual_seedcallstorch.cuda.manual_seed_allinternally. Also covers PyTorch Geometric.
When
should_enable_expensive_deterministic_compute=True(opt-in; default False because it costs throughput and should not be enabled for training or for production inference - can be used for debugging purposes.Important: Graph Sampling currently do not follow determinism outlined here.
Example
>>> seed_everything(42) 42
- Parameters:
seed (int) – RNG seed.
deterministic – If True, also enforces bitwise-deterministic torch ops (cudnn flags,
use_deterministic_algorithms,CUBLAS_WORKSPACE_CONFIG). Default False — most training pipelines want seeded RNGs without paying the throughput cost.should_enable_expensive_deterministic_compute (bool)
- Return type:
None