Download appendix/train.py from BradJu/attribute-ownership-negative-experiments: direct link, hf CLI and curl.
- Browser
- Download file 1.5 kB
-
https://huggingface.co/datasets/BradJu/attribute-ownership-negative-experiments/resolve/main/appendix/train.py
- Command line
-
hf download hf://datasets/BradJu/attribute-ownership-negative-experiments/appendix/train.py
-
curl -L -o train.py https://huggingface.co/datasets/BradJu/attribute-ownership-negative-experiments/resolve/main/appendix/train.py
1.5 kB
| """Optional explicit SFT reproduction. Never imported by offline replay.""" | |
| import argparse,hashlib,json,os,sys,tarfile | |
| from pathlib import Path | |
| os.environ['HF_HUB_OFFLINE']='1';os.environ['TRANSFORMERS_OFFLINE']='1' | |
| R=Path(__file__).resolve().parent | |
| p=argparse.ArgumentParser();p.add_argument('--base-dir',type=Path,required=True);p.add_argument('--agenttune-archive',type=Path,required=True);p.add_argument('--output',type=Path,required=True);a=p.parse_args() | |
| cfg=json.loads((R/'config/distillation.json').read_text()) | |
| assert not a.output.exists();assert hashlib.sha256(a.agenttune_archive.read_bytes()).hexdigest()==cfg['agenttune']['sha256'] | |
| a.output.mkdir(parents=True) | |
| with tarfile.open(a.agenttune_archive) as archive:archive.extractall(a.output/'source',filter='data') | |
| sys.path[:0]=[str(R/'code'),str(next((a.output/'source').iterdir())/'src')] | |
| from transformers import AutoTokenizer | |
| normalized=a.output/'normalized-model';normalized.mkdir();tok=AutoTokenizer.from_pretrained(a.base_dir,local_files_only=True) | |
| if isinstance(tok.chat_template,dict):tok.chat_template=tok.chat_template['default'] | |
| tok.save_pretrained(normalized) | |
| for f in a.base_dir.iterdir(): | |
| if not f.name.startswith('.') and not (normalized/f.name).exists():(normalized/f.name).symlink_to(f.resolve()) | |
| from training import train | |
| _,receipt=train(normalized,json.loads((R/'data/teacher-train.json').read_text()),a.output/'trained',cfg['training']) | |
| (a.output/'training-receipt.json').write_text(json.dumps(receipt,indent=2)+'\n') | |