Spaces:
Sleeping
Sleeping
| import random | |
| import torch | |
| import numpy as np | |
| import os | |
| def set_seed(seed: int = 42): | |
| random.seed(seed) | |
| np.random.seed(seed) | |
| torch.manual_seed(seed) | |
| torch.cuda.manual_seed(seed) # current GPU | |
| torch.cuda.manual_seed_all(seed) # all GPUs | |
| # Ensure deterministic behavior | |
| torch.backends.cudnn.deterministic = True | |
| torch.backends.cudnn.benchmark = False | |
| # For PyTorch >= 1.8 | |
| os.environ["CUBLAS_WORKSPACE_CONFIG"] = ":4096:8" | |
| torch.use_deterministic_algorithms(True, warn_only=True) |