DancingNow's picture
Add files using upload-large-folder tool
275b5a1 verified
Raw History Blame Contribute Delete
792 Bytes
from __future__ import annotations
from pathlib import Path
from typing import Any
import yaml
SECTIONS = ("data", "model", "diffusion", "training", "output")
def load_config(path: Path) -> dict[str, Any]:
with path.open("r", encoding="utf-8") as handle:
config = yaml.safe_load(handle)
if not isinstance(config, dict):
raise ValueError(f"Config must contain a mapping: {path}")
missing = [section for section in SECTIONS if not isinstance(config.get(section), dict)]
if missing:
raise ValueError(f"Missing config sections: {', '.join(missing)}")
return config
def resolve_path(project_root: Path, value: str) -> Path:
path = Path(value).expanduser()
return path.resolve() if path.is_absolute() else (project_root / path).resolve()