Krishna1107 Claude Opus 4.7 commited on
Commit
f249cf5
·
1 Parent(s): 51e8315

Add 7B variant of HF Job for stronger cold-start.

Browse files

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>

Files changed (1) hide show
  1. scripts/run_hf_job_7b.sh +206 -0
scripts/run_hf_job_7b.sh ADDED
@@ -0,0 +1,206 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env bash
2
+ # Runs INSIDE the HF Job container. Self-contained: clones the repo, installs
3
+ # deps, and walks Phases 0..6. On any failure, the trap pushes whatever
4
+ # artifacts already landed in /tmp/results/ to the dataset repo under partial/.
5
+ #
6
+ # Required env vars (set via `hf jobs run --secret`):
7
+ # HF_TOKEN
8
+ # WANDB_API_KEY
9
+
10
+ set -euo pipefail
11
+
12
+ MODEL_REPO="jester1177/mutant-hunter-qwen-coder-7b-lora"
13
+ DATASET_REPO="jester1177/mutant-hunter-results"
14
+ RESULTS_DIR="/tmp/results"
15
+
16
+ push_partial() {
17
+ rc=$?
18
+ echo ""
19
+ echo "[trap] caught exit code ${rc}; uploading whatever is in ${RESULTS_DIR}/ as partial/"
20
+ if [ -d "${RESULTS_DIR}" ]; then
21
+ python - <<'PY' || echo "[trap] partial upload itself failed; giving up"
22
+ import os
23
+ from huggingface_hub import HfApi
24
+ api = HfApi()
25
+ api.upload_folder(
26
+ folder_path="/tmp/results",
27
+ repo_id="jester1177/mutant-hunter-results",
28
+ repo_type="dataset",
29
+ path_in_repo="partial",
30
+ )
31
+ print("[trap] partial artifacts pushed to dataset repo under partial/")
32
+ PY
33
+ else
34
+ echo "[trap] no ${RESULTS_DIR}/ directory exists; nothing to push"
35
+ fi
36
+ exit "${rc}"
37
+ }
38
+ trap push_partial ERR
39
+
40
+ echo "=== Phase 0: setup ==="
41
+ cd /tmp
42
+ if [ ! -d MetaOpenEnv_MutantHunter ]; then
43
+ git clone https://github.com/melohub-xbit/MetaOpenEnv_MutantHunter.git
44
+ fi
45
+ cd MetaOpenEnv_MutantHunter
46
+ mkdir -p "${RESULTS_DIR}" "${RESULTS_DIR}/training" "${RESULTS_DIR}/plots"
47
+
48
+ python -c "import torch; assert torch.cuda.is_available(), 'No CUDA available in base image'; print(f'Using pre-installed torch {torch.__version__}, CUDA {torch.version.cuda}')"
49
+ pip install --no-cache-dir -e ".[training]"
50
+ pip install --no-cache-dir bitsandbytes wandb
51
+
52
+ python -c "from huggingface_hub import login; login(token='${HF_TOKEN}')"
53
+ python -c "import os; os.environ['HOME']='/tmp'; import wandb; wandb.login(key='${WANDB_API_KEY}')"
54
+
55
+ python - <<'PY'
56
+ from huggingface_hub import HfApi
57
+ api = HfApi()
58
+ api.create_repo("jester1177/mutant-hunter-qwen-coder-7b-lora", repo_type="model", exist_ok=True)
59
+ api.create_repo("jester1177/mutant-hunter-results", repo_type="dataset", exist_ok=True)
60
+ print("repos ready")
61
+ PY
62
+
63
+ echo "=== Phase 1: heuristic baseline (~5 min) ==="
64
+ python training/baseline_eval.py \
65
+ --episodes 15 \
66
+ --policy mutation_aware \
67
+ --seed-start 0 \
68
+ --out "${RESULTS_DIR}/baseline_heuristic.json"
69
+
70
+ python - <<'PY'
71
+ from huggingface_hub import upload_file
72
+ upload_file(
73
+ path_or_fileobj="/tmp/results/baseline_heuristic.json",
74
+ path_in_repo="baseline_heuristic.json",
75
+ repo_id="jester1177/mutant-hunter-results",
76
+ repo_type="dataset",
77
+ )
78
+ print("baseline_heuristic.json pushed")
79
+ PY
80
+
81
+ echo "=== Phase 2: zero-shot LLM baseline (~30 min) ==="
82
+ python evaluation/zero_shot_distribution.py \
83
+ --episodes 15 \
84
+ --model Qwen/Qwen2.5-Coder-7B-Instruct \
85
+ --max-new-tokens 1024 \
86
+ --seed-start 0 \
87
+ --device auto
88
+
89
+ cp evaluation/_results/zero_shot_distribution.json "${RESULTS_DIR}/baseline_zeroshot.json"
90
+
91
+ python - <<'PY'
92
+ from huggingface_hub import upload_file
93
+ upload_file(
94
+ path_or_fileobj="/tmp/results/baseline_zeroshot.json",
95
+ path_in_repo="baseline_zeroshot.json",
96
+ repo_id="jester1177/mutant-hunter-results",
97
+ repo_type="dataset",
98
+ )
99
+ print("baseline_zeroshot.json pushed")
100
+ PY
101
+
102
+ echo "=== Phase 3: 200-step GRPO training (~4h) ==="
103
+ python training/train_grpo.py \
104
+ --steps 80 \
105
+ --rollouts-per-step 3 \
106
+ --base-model Qwen/Qwen2.5-Coder-7B-Instruct \
107
+ --max-new-tokens 1024 \
108
+ --learning-rate 5e-6 \
109
+ --seed 42 \
110
+ --output-dir "${RESULTS_DIR}/training" \
111
+ --wandb-project mutant-hunter-final
112
+
113
+ if [ ! -d "${RESULTS_DIR}/training/final" ]; then
114
+ echo "ERROR: ${RESULTS_DIR}/training/final/ not found after training" >&2
115
+ exit 1
116
+ fi
117
+
118
+ python - <<'PY'
119
+ from huggingface_hub import HfApi
120
+ HfApi().upload_folder(
121
+ folder_path="/tmp/results/training/final",
122
+ repo_id="jester1177/mutant-hunter-qwen-coder-7b-lora",
123
+ repo_type="model",
124
+ )
125
+ print("LoRA adapter pushed to model repo")
126
+ PY
127
+
128
+ if [ -f "${RESULTS_DIR}/training/training_log.jsonl" ]; then
129
+ python - <<'PY'
130
+ from huggingface_hub import upload_file
131
+ upload_file(
132
+ path_or_fileobj="/tmp/results/training/training_log.jsonl",
133
+ path_in_repo="training_log.jsonl",
134
+ repo_id="jester1177/mutant-hunter-qwen-coder-7b-lora",
135
+ repo_type="model",
136
+ )
137
+ print("training_log.jsonl pushed")
138
+ PY
139
+ else
140
+ echo "[warn] training_log.jsonl not found; skipping upload"
141
+ fi
142
+
143
+ echo "=== Phase 4: trained eval (~30 min) ==="
144
+ # Stash Phase 2 output so the next run does not clobber it.
145
+ cp "${RESULTS_DIR}/baseline_zeroshot.json" "${RESULTS_DIR}/baseline_zeroshot.keep.json"
146
+
147
+ python evaluation/zero_shot_distribution.py \
148
+ --episodes 15 \
149
+ --model Qwen/Qwen2.5-Coder-7B-Instruct \
150
+ --lora-path "${RESULTS_DIR}/training/final" \
151
+ --max-new-tokens 1024 \
152
+ --seed-start 0 \
153
+ --device auto
154
+
155
+ cp evaluation/_results/zero_shot_distribution.json "${RESULTS_DIR}/trained_eval.json"
156
+
157
+ python - <<'PY'
158
+ from huggingface_hub import upload_file
159
+ upload_file(
160
+ path_or_fileobj="/tmp/results/trained_eval.json",
161
+ path_in_repo="trained_eval.json",
162
+ repo_id="jester1177/mutant-hunter-results",
163
+ repo_type="dataset",
164
+ )
165
+ print("trained_eval.json pushed")
166
+ PY
167
+
168
+ echo "=== Phase 5: plots ==="
169
+ python evaluation/make_plots.py \
170
+ --baseline-heuristic-json "${RESULTS_DIR}/baseline_heuristic.json" \
171
+ --baseline-zeroshot-json "${RESULTS_DIR}/baseline_zeroshot.json" \
172
+ --trained-eval-json "${RESULTS_DIR}/trained_eval.json" \
173
+ --training-log-json "${RESULTS_DIR}/training/training_log.jsonl" \
174
+ --out-dir "${RESULTS_DIR}/plots/"
175
+
176
+ python - <<'PY'
177
+ from huggingface_hub import HfApi
178
+ HfApi().upload_folder(
179
+ folder_path="/tmp/results/plots",
180
+ repo_id="jester1177/mutant-hunter-qwen-coder-7b-lora",
181
+ repo_type="model",
182
+ path_in_repo="plots",
183
+ )
184
+ print("plots/ pushed to model repo")
185
+ PY
186
+
187
+ echo "=== Phase 6: summary ==="
188
+ echo "Model: https://huggingface.co/${MODEL_REPO}"
189
+ echo "Dataset: https://huggingface.co/datasets/${DATASET_REPO}"
190
+
191
+ python - <<'PY' || echo "[warn] could not read W&B run URL"
192
+ import os
193
+ os.environ.setdefault("HOME", "/tmp")
194
+ try:
195
+ import wandb
196
+ api = wandb.Api()
197
+ runs = api.runs("mutant-hunter-final", order="-created_at", per_page=1)
198
+ for r in runs:
199
+ print(f"W&B run: {r.url}")
200
+ break
201
+ except Exception as e:
202
+ print(f"[warn] wandb URL lookup failed: {e}")
203
+ PY
204
+
205
+ echo ""
206
+ echo "=== Done ==="