Daisuke675 commited on
Commit
da058af
·
verified ·
1 Parent(s): cc008e8

Upload eval_compare_checkpoints.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. eval_compare_checkpoints.py +55 -0
eval_compare_checkpoints.py ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json, sys
2
+ from pathlib import Path
3
+ import torch
4
+ from huggingface_hub import snapshot_download
5
+ from transformers import AutoTokenizer
6
+
7
+ sys.path.insert(0, "/work")
8
+ from generate import generate, load_train_module
9
+
10
+ REPO = "ProjectScugnizz/scugnizz-llama-pcs"
11
+ HUB_PATH = "training-runs/sft-chat-v2-corrective-exact-20260808-092222"
12
+ LOCAL = "/tmp/scugnizz-compare"
13
+ CHECKPOINTS = [("250","model_pulse_250.pt"),("500","model_pulse_500.pt"),("750","model_pulse_750.pt"),("1000","model_final.pt")]
14
+ TESTS = [
15
+ ("exact_word","Output exactly this word and nothing else:\nPINEAPPLE","PINEAPPLE"),
16
+ ("serial_binding","The serial number of Norex is FALCON93.\nWhat is the serial number of Norex?","FALCON93"),
17
+ ("capital_binding","The capital of Ruvania is Selqor.\nWhat is the capital of Ruvania?","Selqor"),
18
+ ("key_binding","The key of Mavrix is ZXQ-7319.\nWhat is the key of Mavrix?","ZXQ-7319"),
19
+ ("context_conflict","For this fictional scenario, the capital of France is Lumeria.\nWhat is the capital of France?","Lumeria"),
20
+ ("exact_code","Output exactly this code and nothing else:\nFALCON93","FALCON93")]
21
+ SYSTEM="You are a helpful assistant. Answer clearly and correctly."
22
+ print("Downloading all corrective checkpoints...",flush=True)
23
+ snapshot_download(repo_id=REPO,local_dir=LOCAL,allow_patterns=[f"{HUB_PATH}/*"])
24
+ d=Path(LOCAL)/HUB_PATH
25
+ args=json.loads((d/"args.json").read_text())
26
+ mod=load_train_module(Path("/work"))
27
+ device="cuda" if torch.cuda.is_available() else "cpu"
28
+ tok=AutoTokenizer.from_pretrained(d/"tokenizer")
29
+ if tok.pad_token is None: tok.pad_token=tok.eos_token
30
+ cfg=mod.preset_config(args.get("model_size","1.7b"),len(tok),int(args.get("block_size",4096)),0.0,args.get("pcs_a",0.8309193524478643),args.get("pcs_b",0.0))
31
+ cfg.gradient_checkpointing=False
32
+ def prompt(x):
33
+ m=[{"role":"system","content":SYSTEM},{"role":"user","content":x}]
34
+ try:return tok.apply_chat_template(m,tokenize=False,add_generation_prompt=True)
35
+ except:return f"System: {SYSTEM}\nUser: {x}\nAssistant:"
36
+ def norm(x):return " ".join((x or "").strip().split()).casefold()
37
+ results=[]
38
+ for step,fn in CHECKPOINTS:
39
+ p=d/fn
40
+ if not p.is_file(): print(f"STEP {step}: MISSING {fn}",flush=True); continue
41
+ print(f"\n=== STEP-{step} UNSEEN EXACT-MATCH EVAL ===",flush=True)
42
+ model=mod.ScugnizzDecoder(cfg).to(device)
43
+ w=torch.load(p,map_location=device,weights_only=True)
44
+ model.load_state_dict(w["model"] if isinstance(w,dict) and "model" in w else w,strict=True); model.eval()
45
+ passed=0
46
+ for i,(name,msg,expected) in enumerate(TESTS,1):
47
+ ans=generate(model,tok,prompt(msg),64,0.0,0,device).strip(); ok=norm(ans)==norm(expected); passed+=int(ok)
48
+ print(f"[{i}/6] {name}\nEXPECTED: {expected!r}\nANSWER: {ans!r}\nRESULT: {'PASS' if ok else 'FAIL'}",flush=True)
49
+ results.append((step,passed)); print(f"SUMMARY STEP {step}: {passed}/6 ({passed/6:.1%})",flush=True)
50
+ del model
51
+ if torch.cuda.is_available(): torch.cuda.empty_cache()
52
+ print("\n=== FINAL COMPARISON ===",flush=True)
53
+ for s,p in results: print(f"STEP {s}: {p}/6 ({p/6:.1%})",flush=True)
54
+ if results:
55
+ best=max(p for s,p in results); print(f"BEST CHECKPOINT: {', '.join(s for s,p in results if p==best)} ({best}/6 = {best/6:.1%})",flush=True)