Download code/refined_math/archive.py from davidheineman/tiny-rl-refined-math-v1: direct link, hf CLI and curl.
- Browser
- Download file 3.1 kB
-
https://huggingface.co/datasets/davidheineman/tiny-rl-refined-math-v1/resolve/main/code/refined_math/archive.py
- Command line
-
hf download hf://datasets/davidheineman/tiny-rl-refined-math-v1/code/refined_math/archive.py
-
curl -L -o archive.py https://huggingface.co/datasets/davidheineman/tiny-rl-refined-math-v1/resolve/main/code/refined_math/archive.py
3.1 kB
| from concurrent.futures import ThreadPoolExecutor | |
| from dataclasses import dataclass | |
| import hashlib | |
| import json | |
| from pathlib import Path | |
| from huggingface_hub import HfApi | |
| from omegaconf import OmegaConf | |
| from rich import print | |
| from tqdm import tqdm | |
| from budget_rl.archive import archive_case, ensure_destination | |
| from refined_v4.study import read, write | |
| from .data import ROOT | |
| class Config: | |
| root: str = str(ROOT) | |
| repo: str = 'davidheineman/tiny-rl-refined-math-v1' | |
| workers: int = 2 | |
| def main(config: Config): | |
| root = Path(config.root) | |
| if not 1 <= config.workers <= 4: | |
| raise ValueError('Archive concurrency must be in [1, 4]') | |
| referenced = {path.resolve() for path in (root / 'iterations').glob('*/runs/*/*/*/sft.pt') | |
| if path.is_symlink()} | |
| cases = [] | |
| # These completed controls were superseded; selected/current suites stay local. | |
| for suite in ('optim-v1', 'attention-v1'): | |
| plan = read(root / 'iterations' / suite / 'plan.json') | |
| for case in plan['cases']: | |
| folder = Path(case['output']) | |
| if not (folder / 'complete.json').exists(): | |
| continue | |
| complete = read(folder / 'complete.json') | |
| if complete['sft_tokens'] != 2097152 or complete['rl_rollouts'] != 65536: | |
| continue | |
| if any((folder / filename).resolve() in referenced for filename in ('sft.pt', 'rl.pt')): | |
| continue | |
| cases.append(dict(key=suite + '__' + case['key'], folder=str(folder), reuse=False)) | |
| policy = dict(repo=config.repo, repo_type='model', private=False, | |
| suites=['optim-v1', 'attention-v1'], sft_tokens=2097152, rl_rollouts=65536, | |
| authorization='User AGENTS.md storage instructions allow archiving old data to Hugging Face before local removal.', | |
| retention='Selected/current suites and any referenced SFT weights stay local. Delete superseded completed copies only after remote LFS SHA256 and size verification.') | |
| protocol = dict(sft_tokens=2097152, rl_rollouts=65536, | |
| signature=hashlib.sha256(json.dumps(policy, sort_keys=True).encode()).hexdigest()) | |
| output = root / 'archive-negative-v1' | |
| output.mkdir(exist_ok=True) | |
| write(output / 'archive-policy.json', policy) | |
| write(output / 'plan.json', dict(protocol=protocol, cases=cases)) | |
| api = HfApi() | |
| ensure_destination(api, config.repo, 'model', False, True) | |
| def archive(case): | |
| return archive_case(case, protocol, None, config.repo, 'model', False) | |
| with ThreadPoolExecutor(max_workers=config.workers) as pool: | |
| futures = [pool.submit(archive, case) for case in cases] | |
| for future in tqdm(futures, desc='Archive superseded math checkpoints', colour='cyan'): | |
| record = future.result() | |
| print('[green]Remote checkpoint hashes verified[/green]', record['prefix']) | |
| write(output / 'complete.json', dict(cases=len(cases), repo=config.repo, protocol=protocol)) | |
| if __name__ == '__main__': | |
| main(OmegaConf.to_object(OmegaConf.merge(OmegaConf.structured(Config), OmegaConf.from_cli()))) | |