File size: 600 Bytes
41dd7e0 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | """Seeding and YAML helpers."""
from __future__ import annotations
import os
import random
from typing import Any, Dict
import numpy as np
import torch
import yaml
def seed_everything(seed: int) -> None:
random.seed(seed)
np.random.seed(seed)
torch.manual_seed(seed)
torch.cuda.manual_seed_all(seed)
def load_yaml(path: str | os.PathLike) -> Dict[str, Any]:
with open(path) as f:
return yaml.safe_load(f)
def save_resolved_config(cfg: Dict[str, Any], path: str | os.PathLike) -> None:
with open(path, "w") as f:
yaml.safe_dump(cfg, f, sort_keys=False)
|