| #!/bin/bash |
| |
| |
| set -e |
| cd /w |
| export PYTHONPATH="/w:${PYTHONPATH}" |
|
|
| |
| |
| |
| |
| |
| |
| export CUDA_VISIBLE_DEVICES=0 |
|
|
| |
| pip install -q 'huggingface_hub>=0.28' |
|
|
| |
| mkdir -p data |
| python -c "from huggingface_hub import hf_hub_download; [hf_hub_download(repo_id='Pratham-math/fathom-code', filename=f'data/{f}', local_dir='/w', token='${HF_TOKEN}') for f in ['train.jsonl','eval.jsonl','sft_traces.jsonl']]" |
| ls -la data/ |
|
|
| |
| pip install -q openenv-core fastapi 'uvicorn[standard]' pydantic RestrictedPython tiktoken httpx |
| pip install -q hydra-core omegaconf wandb 'huggingface_hub>=0.28' tyro |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| pip install -q transformers==4.56.2 accelerate==1.5.2 peft==0.14.0 'bitsandbytes>=0.48.1' |
| pip install -q datasets==4.7.0 |
| |
| pip install -q --no-deps trl==1.2.0 |
| pip install -q vllm==0.18.0 |
|
|
| |
| pip install -q safetensors sentencepiece einops scipy xxhash protobuf pyyaml fsspec aiohttp dill multiprocess pyarrow requests filelock packaging tokenizers regex tqdm |
|
|
| |
| |
| |
| |
| |
| pip install -q matplotlib |
|
|
| |
| |
| echo "flash-attn intentionally skipped to avoid build-time OOM" |
|
|
| nohup uvicorn env.server.app:app --host 0.0.0.0 --port 8001 > env.log 2>&1 & |
| sleep 10 |
| python -c "import urllib.request, sys; sys.exit(0 if urllib.request.urlopen('http://localhost:8001/healthz', timeout=5).status==200 else 1)" || (echo "env down"; cat env.log; exit 1) |
|
|
| |
| python -m train.smoke_test --env-url http://localhost:8001 |
| grep -q "VERDICT: GO" outputs/smoke/SMOKE_RESULT.md || (cat outputs/smoke/SMOKE_RESULT.md; exit 1) |
|
|
| |
| |
| |
| |
| python <<'PY' |
| from hydra import initialize_config_dir, compose |
| from train.model_load import load_model_and_tokenizer |
| from train.sft import run_sft |
| with initialize_config_dir(config_dir="/w/configs", version_base="1.3"): |
| cfg = compose(config_name="config", overrides=["model=qwen_1_5b","train=sft"]) |
| m, t = load_model_and_tokenizer(cfg) |
| print("SFT adapter:", run_sft(cfg, m, t)) |
| PY |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| python <<'PY' |
| from hydra import initialize_config_dir, compose |
| from train.model_load import load_model_and_tokenizer |
| from train.grpo import run_grpo |
| from rewards.compose import make_reward_fn |
| with initialize_config_dir(config_dir="/w/configs", version_base="1.3"): |
| cfg = compose(config_name="config", overrides=[ |
| "model=qwen_1_5b", |
| "train=grpo", |
| "train.max_steps=200", |
| "train.num_generations=8", |
| "train.max_prompt_length=4096", |
| "train.max_completion_length=1024", |
| "train.vllm_gpu_memory_utilization=0.50", |
| ]) |
| m, t = load_model_and_tokenizer(cfg) |
| print("GRPO merged:", run_grpo(cfg, m, t, make_reward_fn(cfg.reward), "http://localhost:8001")) |
| PY |
|
|
| |
| python /w/scripts/make_plots.py || echo "plot generation failed (non-fatal)" |
|
|
| |
| HF_USER=$(python -c "from huggingface_hub import HfApi; print(HfApi(token='${HF_TOKEN}').whoami()['name'])") |
| python <<PY |
| from huggingface_hub import HfApi |
| api = HfApi(token="${HF_TOKEN}") |
| repo = "${HF_USER}/fathom-1.5b-grpo" |
| api.create_repo(repo, repo_type="model", exist_ok=True, private=False) |
| import os |
| for sub in ["sft_adapter", "grpo_merged_16bit", "plots"]: |
| if os.path.isdir(f"outputs/{sub}"): |
| api.upload_folder(folder_path=f"outputs/{sub}", path_in_repo=sub, repo_id=repo, repo_type="model") |
| print(f"Uploaded outputs/{sub} -> {repo}/{sub}") |
| print(f"Trained model + plots: https://huggingface.co/{repo}") |
| PY |
| echo "DONE" |
|
|