Download src/study/checkpoints.py from BurnyCoder/recursive-judge-grpo-study: direct link, hf CLI and curl.
- Browser
- Download file 1.06 kB
-
https://huggingface.co/datasets/BurnyCoder/recursive-judge-grpo-study/resolve/main/src/study/checkpoints.py
- Command line
-
hf download hf://datasets/BurnyCoder/recursive-judge-grpo-study/src/study/checkpoints.py
-
curl -L -o checkpoints.py https://huggingface.co/datasets/BurnyCoder/recursive-judge-grpo-study/resolve/main/src/study/checkpoints.py
1.06 kB
| """Recover a fully written single-process TRL update after interruption.""" | |
| import json | |
| def last_complete(directory): | |
| """Trainer saves its JSON state after weights, optimizer, scheduler and RNG state.""" | |
| # See transformers.Trainer._save_checkpoint, https://huggingface.co/docs/transformers/main_classes/trainer | |
| candidates = [] | |
| for path in directory.glob("checkpoint-*"): | |
| suffix = path.name.removeprefix("checkpoint-") | |
| if path.is_dir() and suffix.isdigit(): | |
| candidates.append((int(suffix), path)) | |
| for step, path in sorted(candidates, reverse=True): | |
| try: | |
| state = json.loads((path/"trainer_state.json").read_text(encoding="utf-8")) | |
| files = ("adapter_model.safetensors", "adapter_config.json", "optimizer.pt", "scheduler.pt", "rng_state.pth") | |
| if state.get("global_step") == step and all((path/name).stat().st_size for name in files): | |
| return path, step | |
| except (OSError, UnicodeError, json.JSONDecodeError): | |
| continue | |
| return None, 0 | |