File size: 391 Bytes
8b8e59d
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
from pathlib import Path


def latest_ckpt(d: str | Path):
    """Latest checkpoint: prefer model_final.pt, else max numeric step."""
    d = Path(d)
    final = d / "model_final.pt"
    if final.exists():
        return final
    ckpts = [p for p in d.glob("model_*.pt") if p.stem.split("_")[-1].isdigit()]
    return max(ckpts, key=lambda p: int(p.stem.split("_")[-1])) if ckpts else None