Skip to content

Instantly share code, notes, and snippets.

@BramVanroy
Last active March 30, 2023 07:42
Show Gist options
  • Save BramVanroy/9d108c64bc2b3a0ddb1b5ff30af948b8 to your computer and use it in GitHub Desktop.
Save BramVanroy/9d108c64bc2b3a0ddb1b5ff30af948b8 to your computer and use it in GitHub Desktop.
Settnig deterministic seeds
def set_seed(seed: Optional[int]):
if seed is not None:
torch.manual_seed(seed)
torch.cuda.manual_seed_all(seed)
torch.backends.cudnn.deterministic = True
torch.backends.cudnn.benchmark = False
np.random.seed(seed)
random.seed(seed)
os.environ["PYTHONHASHSEED"] = str(seed)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment