Buckets:
AnonymousSpottedToad/human_verified_bucket / codebase /python /olaflaitinen_Promethium /src /promethium /utils /reproducibility.py
| """ | |
| Reproducibility utilities for deterministic behavior. | |
| """ | |
| import random | |
| import numpy as np | |
| import torch | |
| from typing import Optional | |
| def set_seed(seed: int = 42) -> None: | |
| """ | |
| Set random seeds for reproducibility across all libraries. | |
| Args: | |
| seed: Random seed value. Default is 42. | |
| Example: | |
| >>> from promethium.utils import set_seed | |
| >>> set_seed(42) | |
| """ | |
| random.seed(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 | |
| def get_device(prefer_gpu: bool = True) -> str: | |
| """ | |
| Determine the best available device for computation. | |
| Args: | |
| prefer_gpu: If True, prefer CUDA if available. Default is True. | |
| Returns: | |
| Device string: 'cuda' if GPU available and preferred, else 'cpu'. | |
| Example: | |
| >>> from promethium.utils import get_device | |
| >>> device = get_device() | |
| >>> print(f"Using device: {device}") | |
| """ | |
| if prefer_gpu and torch.cuda.is_available(): | |
| return "cuda" | |
| return "cpu" | |
Xet Storage Details
- Size:
- 1.25 kB
- Xet hash:
- 3cea84755a51dbcc9cd79762d60ec36993de96403e75671a73ca6289f0413513
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.