v17_astra / scripts /pack_phases.py
LingweiGu's picture
Publish audited v17 Astra rollouts, verified rotation and training handoff
3bd542a verified
Raw History Blame Contribute Delete
1.76 kB
"""Pack each approved phase with the existing MiniCPM packer. Persist phase ranges needed by the sampler."""
import argparse,json,sys
from pathlib import Path
from phase_data import PhaseOrderedSampler
def main():
ap=argparse.ArgumentParser();ap.add_argument('scripts',type=Path);ap.add_argument('materialized',type=Path);ap.add_argument('output',type=Path);ap.add_argument('--workers',type=int,default=2);a=ap.parse_args()
sys.path.insert(0,str(a.scripts.resolve()))
from pack_trajectory_dataset import write_split
from datasets import load_from_disk
ranges=[]
for ep in sorted(a.materialized.glob('e[0-9][0-9]')):
receipts=json.loads((ep/'receipt.json').read_text())
for j,p in enumerate(('p1','p2')):
src=sorted((ep/p/'train').glob('*.parquet'));out=a.output/ep.name/p
out.parent.mkdir(parents=True,exist_ok=True)
if not out.exists():
tmp=out.with_suffix('.partial')
if tmp.exists():raise RuntimeError('incomplete pack at '+str(tmp))
stats,*_=write_split(src,tmp,20261120,None,131072,32768,a.workers)
assert stats['rows']==receipts[j]['rows'] and stats['supervised']==receipts[j]['loss']
tmp.rename(out)
ds=load_from_disk(str(out));ranges.append(dict(epoch=ep.name,phase=p,path=str(out.resolve()),packs=len(ds),loss=receipts[j]['loss']))
sampler=PhaseOrderedSampler([x['packs'] for x in ranges],20261120)
offset=0;it=iter(sampler)
for x in ranges:
n=x['packs'];ix=[next(it) for _ in range(n)]
assert set(ix)==set(range(offset,offset+n));offset+=n
(a.output/'phases.json').write_text(json.dumps(ranges,indent=2));print(ranges)
if __name__=='__main__':main()