mshaiel2004's picture
Upload folder using huggingface_hub
78856c0 verified
Raw History Blame Contribute Delete
577 Bytes
import os
import random
import numpy as np
import torch
def seed_everything(seed: int = 42) -> None:
"""Set seeds for reproducibility across Python, NumPy, and PyTorch.
Args:
seed: The integer seed value. Defaults to 42.
"""
random.seed(seed)
os.environ["PYTHONHASHSEED"] = str(seed)
np.random.seed(seed)
torch.manual_seed(seed)
if torch.cuda.is_available():
torch.cuda.manual_seed(seed)
torch.cuda.manual_seed_all(seed)
torch.backends.cudnn.deterministic = True
torch.backends.cudnn.benchmark = False