final_eval: resolve LoRA path via hf_hub_download, upload results to eval/final at end
Browse files- final_eval.py +25 -8
final_eval.py
CHANGED
|
@@ -5,24 +5,27 @@ usage, matches training captions) and without (apples-to-apples with the
|
|
| 5 |
baselines, which ran bare instructions). Reuses eval_edit.py's pipeline,
|
| 6 |
metrics and seeding so numbers are directly comparable to the baseline run.
|
| 7 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
Usage:
|
| 9 |
-
python final_eval.py --lora /
|
| 10 |
"""
|
| 11 |
import argparse, json, os, sys
|
| 12 |
|
| 13 |
-
# The job bootstrap only fetches this file; pull eval_edit.py (the module with
|
| 14 |
-
# the pipeline/metrics/seeding shared with the baseline run) from the repo
|
| 15 |
-
# itself so the sibling import works in a fresh container.
|
| 16 |
_here = os.path.dirname(os.path.abspath(__file__))
|
| 17 |
if _here not in sys.path:
|
| 18 |
sys.path.insert(0, _here)
|
|
|
|
|
|
|
|
|
|
| 19 |
if not os.path.exists(os.path.join(_here, 'eval_edit.py')):
|
| 20 |
from huggingface_hub import hf_hub_download
|
|
|
|
| 21 |
p = hf_hub_download(repo_id='ysharma/gso-orbit-rgba', repo_type='dataset',
|
| 22 |
filename='eval_edit.py')
|
| 23 |
-
|
| 24 |
-
import shutil
|
| 25 |
-
shutil.copy(p, os.path.join(_here, 'eval_edit.py'))
|
| 26 |
print(f'fetched eval_edit.py -> {os.path.join(_here, "eval_edit.py")}', flush=True)
|
| 27 |
|
| 28 |
import eval_edit as E
|
|
@@ -34,12 +37,20 @@ def main():
|
|
| 34 |
ap.add_argument('--out', required=True)
|
| 35 |
args = ap.parse_args()
|
| 36 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
pairs = [json.loads(l) for l in open(E.get_file('pairs_eval.jsonl'))]
|
| 38 |
assert len(pairs) == 160, f'expected 160 eval pairs, got {len(pairs)}'
|
| 39 |
|
| 40 |
pipe = E.load_pipe()
|
| 41 |
m = E.make_metrics()
|
| 42 |
-
pipe.load_lora_weights(
|
| 43 |
|
| 44 |
for variant, suffix in (('no_suffix', ''), ('suffix', ' ' + E.ALPHA_SUFFIX)):
|
| 45 |
pv = [dict(p, instruction=p['instruction'] + suffix) for p in pairs]
|
|
@@ -66,6 +77,12 @@ def main():
|
|
| 66 |
except Exception as e:
|
| 67 |
print(f'sheet failed (non-fatal): {e}', flush=True)
|
| 68 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 69 |
print('DONE', flush=True)
|
| 70 |
|
| 71 |
|
|
|
|
| 5 |
baselines, which ran bare instructions). Reuses eval_edit.py's pipeline,
|
| 6 |
metrics and seeding so numbers are directly comparable to the baseline run.
|
| 7 |
|
| 8 |
+
Self-contained for job bootstrap: fetches its sibling eval_edit.py from the
|
| 9 |
+
dataset repo, resolves the LoRA checkpoint from the model repo via
|
| 10 |
+
hf_hub_download, and uploads results to the dataset repo at the end.
|
| 11 |
+
|
| 12 |
Usage:
|
| 13 |
+
python final_eval.py --lora checkpoints/steps2000res768/orbit_alpha_lora/orbit_alpha_lora.safetensors --out /out/final
|
| 14 |
"""
|
| 15 |
import argparse, json, os, sys
|
| 16 |
|
|
|
|
|
|
|
|
|
|
| 17 |
_here = os.path.dirname(os.path.abspath(__file__))
|
| 18 |
if _here not in sys.path:
|
| 19 |
sys.path.insert(0, _here)
|
| 20 |
+
|
| 21 |
+
# The job bootstrap only runs this file; pull eval_edit.py (pipeline/metrics/
|
| 22 |
+
# seeding shared with the baseline run) from the dataset repo.
|
| 23 |
if not os.path.exists(os.path.join(_here, 'eval_edit.py')):
|
| 24 |
from huggingface_hub import hf_hub_download
|
| 25 |
+
import shutil
|
| 26 |
p = hf_hub_download(repo_id='ysharma/gso-orbit-rgba', repo_type='dataset',
|
| 27 |
filename='eval_edit.py')
|
| 28 |
+
shutil.copy(p, os.path.join(_here, 'eval_edit.py'))
|
|
|
|
|
|
|
| 29 |
print(f'fetched eval_edit.py -> {os.path.join(_here, "eval_edit.py")}', flush=True)
|
| 30 |
|
| 31 |
import eval_edit as E
|
|
|
|
| 37 |
ap.add_argument('--out', required=True)
|
| 38 |
args = ap.parse_args()
|
| 39 |
|
| 40 |
+
# LoRA: local path if it exists, else a file path inside ysharma/orbit-alpha-lora.
|
| 41 |
+
lora_path = args.lora
|
| 42 |
+
if not os.path.exists(lora_path):
|
| 43 |
+
from huggingface_hub import hf_hub_download
|
| 44 |
+
lora_path = hf_hub_download(repo_id='ysharma/orbit-alpha-lora',
|
| 45 |
+
filename=args.lora)
|
| 46 |
+
print(f'using lora: {lora_path}', flush=True)
|
| 47 |
+
|
| 48 |
pairs = [json.loads(l) for l in open(E.get_file('pairs_eval.jsonl'))]
|
| 49 |
assert len(pairs) == 160, f'expected 160 eval pairs, got {len(pairs)}'
|
| 50 |
|
| 51 |
pipe = E.load_pipe()
|
| 52 |
m = E.make_metrics()
|
| 53 |
+
pipe.load_lora_weights(lora_path)
|
| 54 |
|
| 55 |
for variant, suffix in (('no_suffix', ''), ('suffix', ' ' + E.ALPHA_SUFFIX)):
|
| 56 |
pv = [dict(p, instruction=p['instruction'] + suffix) for p in pairs]
|
|
|
|
| 77 |
except Exception as e:
|
| 78 |
print(f'sheet failed (non-fatal): {e}', flush=True)
|
| 79 |
|
| 80 |
+
# results survive the container only if pushed from inside the job
|
| 81 |
+
from huggingface_hub import HfApi
|
| 82 |
+
HfApi().upload_folder(folder_path=args.out, repo_id='ysharma/gso-orbit-rgba',
|
| 83 |
+
repo_type='dataset', path_in_repo='eval/final')
|
| 84 |
+
print('uploaded results -> ysharma/gso-orbit-rgba/eval/final', flush=True)
|
| 85 |
+
|
| 86 |
print('DONE', flush=True)
|
| 87 |
|
| 88 |
|