wheattoast11 commited on
Commit
d05142f
·
verified ·
1 Parent(s): ae70733

Upload eval_v2_finetuned_all.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. eval_v2_finetuned_all.py +74 -0
eval_v2_finetuned_all.py ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # /// script
2
+ # requires-python = ">=3.10"
3
+ # dependencies = [
4
+ # "lighteval>=0.6.0",
5
+ # "torch>=2.0.0",
6
+ # "transformers>=4.40.0",
7
+ # "accelerate>=0.30.0",
8
+ # "peft>=0.10.0",
9
+ # ]
10
+ # ///
11
+ """
12
+ v2 Finetuned: All 6 benchmarks (MMLU, GSM8K, ARC-C, Winogrande, TruthfulQA, HellaSwag).
13
+ Merges LoRA adapter before evaluation.
14
+ """
15
+
16
+ import gc
17
+ import glob
18
+ import os
19
+ import subprocess
20
+
21
+ def main():
22
+ hf_token = os.getenv("HF_TOKEN")
23
+ if hf_token:
24
+ os.environ.setdefault("HUGGING_FACE_HUB_TOKEN", hf_token)
25
+ os.environ.setdefault("HF_HUB_TOKEN", hf_token)
26
+ os.environ["PYTORCH_CUDA_ALLOC_CONF"] = "expandable_segments:True"
27
+
28
+ from transformers import AutoModelForCausalLM, AutoTokenizer
29
+ from peft import PeftModel
30
+ import torch
31
+
32
+ print("Merging v2 adapter...")
33
+ model = AutoModelForCausalLM.from_pretrained(
34
+ "LiquidAI/LFM2.5-1.2B-Instruct",
35
+ trust_remote_code=True,
36
+ torch_dtype=torch.float16,
37
+ device_map="cpu",
38
+ )
39
+ model = PeftModel.from_pretrained(model, "wheattoast11/agent-zero-lfm-1.2b-v2")
40
+ model = model.merge_and_unload()
41
+
42
+ merged_path = "/tmp/merged_model_v2"
43
+ model.save_pretrained(merged_path)
44
+ tokenizer = AutoTokenizer.from_pretrained(
45
+ "wheattoast11/agent-zero-lfm-1.2b-v2",
46
+ trust_remote_code=True,
47
+ )
48
+ tokenizer.save_pretrained(merged_path)
49
+ del model, tokenizer
50
+ gc.collect()
51
+ print("Adapter merged.")
52
+
53
+ model_args = f"model_name={merged_path},trust_remote_code=True,dtype=float16,max_length=2048"
54
+
55
+ # Run in two batches to manage memory
56
+ batches = [
57
+ "leaderboard|mmlu:abstract_algebra|5,leaderboard|mmlu:anatomy|5,leaderboard|mmlu:astronomy|5,leaderboard|mmlu:business_ethics|5,leaderboard|mmlu:clinical_knowledge|5,leaderboard|gsm8k|5",
58
+ "leaderboard|hellaswag|0,leaderboard|arc:challenge|25,leaderboard|truthfulqa:mc|0,leaderboard|winogrande|5",
59
+ ]
60
+
61
+ for i, tasks in enumerate(batches):
62
+ out_dir = f"/tmp/results_v2_batch{i}"
63
+ cmd = ["lighteval", "accelerate", model_args, tasks, "--output-dir", out_dir]
64
+ print(f"\nBatch {i}: {' '.join(cmd)}")
65
+ subprocess.run(cmd, check=True)
66
+
67
+ print("\n=== ALL RESULTS ===")
68
+ for f in sorted(glob.glob("/tmp/results_v2_*/**/*.json", recursive=True)):
69
+ print(f"\n=== {f} ===")
70
+ with open(f) as fh:
71
+ print(fh.read()[:10000])
72
+
73
+ if __name__ == "__main__":
74
+ main()