File size: 554 Bytes
1ef5ba8 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | """Small helpers."""
from __future__ import annotations
import os
from pathlib import Path
from typing import Optional
def find_latest_ckpt(run_dir: str | Path) -> Optional[str]:
"""Locate the latest `*.ckpt` under run_dir, for auto-resume after server restart."""
rd = Path(run_dir)
if not rd.exists():
return None
ckpts = sorted(rd.rglob("*.ckpt"), key=lambda p: p.stat().st_mtime, reverse=True)
return str(ckpts[0]) if ckpts else None
def env_or(default: str, key: str) -> str:
return os.environ.get(key, default)
|