deepreads / src /utils /seed.py
yash-b18
feat: repo scaffold — structure, config, README, requirements
0390c27
Raw History Blame Contribute Delete
694 Bytes
"""
Reproducibility utilities — set all random seeds in one call.
"""
from __future__ import annotations
import os
import random
import numpy as np
def set_seed(seed: int = 42) -> None:
"""
Set random seeds for Python, NumPy, and PyTorch (if available).
Args:
seed: Integer seed value.
"""
random.seed(seed)
np.random.seed(seed)
os.environ["PYTHONHASHSEED"] = str(seed)
try:
import torch
torch.manual_seed(seed)
if torch.cuda.is_available():
torch.cuda.manual_seed_all(seed)
torch.backends.cudnn.deterministic = True
torch.backends.cudnn.benchmark = False
except ImportError:
pass