Initialize optimizer research workspace with official baselines and history-free coverage
Vendor pinned MeZO, AGZO, LOZO and LoREN sources with independent environments. Add direct in-place fix/adjust/node training, derived history-free basis gradients, development-best checkpoints and experiment tooling. Keep models, datasets, caches and credentials outside Git. Validation: 93 project tests passed; 521 vendored author files verified.
This commit is contained in:
commit
e0feabec8f
596 files changed
+87356
No files matched your search
@@ -0,0 +1,85 @@
|
||||
"""Copy verified existing assets, or explicitly download absent public assets. No moves."""
|
||||
import argparse
|
||||
import hashlib
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
import shutil
|
||||
import subprocess
|
||||
import time
|
||||
|
||||
def main():
|
||||
p=argparse.ArgumentParser();p.add_argument('--download-missing',action='store_true');p.add_argument('--datasets-only',action='store_true');a=p.parse_args()
|
||||
subprocess.run(['mountpoint','-q','/mnt/e'],check=True)
|
||||
root=Path(os.environ.get('EXPERIMENT_ASSETS','/mnt/e/Experiments/Assets'))
|
||||
old=Path('/mnt/e/Experiments/optimizer_research')
|
||||
root.mkdir(parents=True,exist_ok=True)
|
||||
for d in ('models','data','results'):(root/d).mkdir(exist_ok=True)
|
||||
os.environ['HF_HOME']=str(root/'models/.huggingface')
|
||||
os.environ['HF_HUB_CACHE']=str(root/'models/.huggingface/hub')
|
||||
os.environ['HF_DATASETS_CACHE']=str(root/'data/.huggingface/datasets')
|
||||
os.environ['HF_XET_CACHE']=str(root/'models/.huggingface/xet')
|
||||
manifest=json.loads((root/'asset_manifest.json').read_text()) if (root/'asset_manifest.json').exists() else {'root':str(root),'models':{},'datasets':{}}
|
||||
lockpath=Path(__file__).with_name('assets.lock.json')
|
||||
lock=json.loads(lockpath.read_text()) if lockpath.exists() else {}
|
||||
for ident,alias in ([] if a.datasets_only else [('facebook/opt-1.3b','opt-1.3b'),('Qwen/Qwen3-0.6B','qwen3-0.6b')]):
|
||||
dest=root/'models'/alias;dest.mkdir(exist_ok=True)
|
||||
cache=old/'huggingface/hub'/('models--'+ident.replace('/','--'))/'snapshots'
|
||||
candidates=sorted(cache.glob('*')) if cache.exists() else []
|
||||
expected=lock.get('models',{}).get(ident,{})
|
||||
snapshots=[v for v in candidates if (v/'config.json').exists() and (not expected or v.name==expected['revision'])]
|
||||
if snapshots:
|
||||
source=snapshots[-1];revision=source.name
|
||||
for f in source.rglob('*'):
|
||||
if not f.is_file():continue
|
||||
target=dest/f.relative_to(source);target.parent.mkdir(parents=True,exist_ok=True)
|
||||
if not target.exists():shutil.copy2(f,target,follow_symlinks=True)
|
||||
if target.stat().st_size!=f.stat().st_size:raise RuntimeError(f'Partial asset {target}')
|
||||
elif a.download_missing:
|
||||
from huggingface_hub import snapshot_download
|
||||
snapshot_download(ident,revision=expected.get('revision','main'),local_dir=dest);revision=expected.get('revision','downloaded: see local HF metadata')
|
||||
else:raise RuntimeError(f'No cached model {ident}; retry with --download-missing')
|
||||
files={}
|
||||
for f in sorted(dest.rglob('*')):
|
||||
if not f.is_file() or '.cache' in f.parts:continue
|
||||
h=hashlib.sha256()
|
||||
with f.open('rb') as stream:
|
||||
for block in iter(lambda:stream.read(8*1024*1024),b''):h.update(block)
|
||||
files[str(f.relative_to(dest))]={'bytes':f.stat().st_size,'sha256':h.hexdigest()}
|
||||
pinned=expected.get('files',{}).get(str(f.relative_to(dest)))
|
||||
if pinned and files[str(f.relative_to(dest))]!=pinned:raise RuntimeError(f'Model hash mismatch: {f}')
|
||||
manifest['models'][ident]={'path':str(dest),'revision':revision,'files':files}
|
||||
print(f'Model ready: {ident} ({len(files)} files)',flush=True)
|
||||
# Preserve raw full datasets separately from frozen historical benchmark samples.
|
||||
from datasets import load_dataset, DatasetDict
|
||||
for ident,config,alias in [('glue','sst2','sst2'),('ucinlp/drop',None,'drop')]:
|
||||
dest=root/'data'/alias
|
||||
from datasets import load_from_disk
|
||||
try:
|
||||
ds=load_from_disk(str(dest)) if (dest/'dataset_dict.json').exists() else None
|
||||
except ValueError:
|
||||
# Rebuild from immutable raw parquet when a newer datasets serialized List
|
||||
# features that legacy author environments cannot read.
|
||||
ds=None
|
||||
if ds is None:
|
||||
if alias=='sst2' and (old/'datasets/sst2/train.parquet').exists():
|
||||
ds=load_dataset('parquet',data_files={s:str(old/f'datasets/sst2/{s}.parquet') for s in ('train','validation')})
|
||||
else:
|
||||
hub=old/'huggingface/hub'/('datasets--'+ident.replace('/','--'))/'snapshots'
|
||||
parquet={s:sorted(str(f) for v in hub.glob('*') for f in v.rglob(f'*{s}*.parquet')) for s in ('train','validation')}
|
||||
if all(parquet.values()):ds=load_dataset('parquet',data_files=parquet)
|
||||
elif a.download_missing:ds=load_dataset(ident,config) if config else load_dataset(ident)
|
||||
else:raise RuntimeError(f'No cached raw {alias}; retry with --download-missing')
|
||||
ds.save_to_disk(str(dest))
|
||||
from datasets import load_from_disk
|
||||
ds=load_from_disk(str(dest))
|
||||
manifest['datasets'][alias]={'path':str(dest),'rows':{s:len(d) for s,d in ds.items()},
|
||||
'fingerprints':{s:d._fingerprint for s,d in ds.items()}}
|
||||
print(f'Dataset ready: {alias} {manifest["datasets"][alias]["rows"]}',flush=True)
|
||||
frozen=old/'results/final_results/data'
|
||||
if frozen.exists():
|
||||
shutil.copytree(frozen,root/'data/historical_opt13_sst2',dirs_exist_ok=True)
|
||||
target=root/'asset_manifest.json';tmp=target.with_suffix('.tmp');tmp.write_text(json.dumps(manifest,indent=2));tmp.replace(target)
|
||||
print(f'Manifest: {target}')
|
||||
|
||||
if __name__=='__main__':main()
|
||||
Reference in new issue
Block a user