File size: 723 Bytes
3f30783
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
"""Strip optimizer + RNG state from TabLoop checkpoints: keeps {step, model, config}.
    python strip.py <src checkpoints dir> <dst dir>       (skips existing outputs; ignores latest.ckpt)"""
import glob, os, re, sys, torch
src, dst = sys.argv[1], sys.argv[2]; os.makedirs(dst, exist_ok=True)
for p in sorted(glob.glob(f"{src}/step-*.ckpt")):
    s = int(re.search(r"step-(\d+)\.ckpt", p).group(1)); out = f"{dst}/step-{s:06d}.ckpt"
    if os.path.exists(out): continue
    ck = torch.load(p, map_location="cpu", weights_only=False)
    torch.save({"step": ck["step"], "model": ck["model"], "config": ck["config"]}, out + ".tmp"); os.replace(out + ".tmp", out)
print(src, len(glob.glob(f"{dst}/step-*.ckpt")), "stripped")