file.py 345 B

12345678910111213141516
  1. import os
  2. from pathlib import Path
  3. def get_latest_checkpoint(path: Path | str) -> Path | None:
  4. # Find the latest checkpoint
  5. ckpt_dir = Path(path)
  6. if ckpt_dir.exists() is False:
  7. return None
  8. ckpts = sorted(ckpt_dir.glob("*.ckpt"), key=os.path.getmtime)
  9. if len(ckpts) == 0:
  10. return None
  11. return ckpts[-1]