set_seed¶
- torchtune.training.set_seed(seed: Optional[int] = None, debug_mode: Optional[Union[int, str]] = None) int [source]¶
Function that sets seed for pseudo-random number generators across commonly used libraries.
This seeds PyTorch, NumPy, and the python.random module. For distributed jobs, each local process sets its own seed, computed seed + rank. For more details, see https://pytorch.org/docs/stable/notes/randomness.html.
- Parameters:
seed (Optional[int]) – the integer value seed. If None, a random seed will be generated and set.
debug_mode (Optional[Union[str, int]]) –
Controls debug_mode settings for deterministic operations within PyTorch.
If None, don’t set any PyTorch global values.
If “default” or 0, don’t error or warn on nondeterministic operations and additionally enable PyTorch CuDNN benchmark.
If “warn” or 1, warn on nondeterministic operations and disable PyTorch CuDNN benchmark.
If “error” or 2, error on nondeterministic operations and disable PyTorch CuDNN benchmark.
For more details, see
torch.set_deterministic_debug_mode()
and https://pytorch.org/docs/stable/notes/randomness.html#avoiding-nondeterministic-algorithms.
- Returns:
the current seed
- Return type:
- Raises:
ValueError – If the input seed value is outside the required range.