ysharma HF Staff commited on
Commit
1d7ecc8
·
verified ·
1 Parent(s): af9bd39

verify converted gate_up split adapter: clean load + 48-edit subset

Browse files
Files changed (1) hide show
  1. verify_split.py +93 -0
verify_split.py ADDED
@@ -0,0 +1,93 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Verify the gate_up-split adapter for ysharma/orbit-alpha-lora.
2
+
3
+ 1. Load orbit_alpha_lora_gate_up_split.safetensors into QwenImage21Pipeline
4
+ via load_lora_weights and CAPTURE all warnings/logs during the load.
5
+ PASS requires: no warning mentioning gate_up / gate_layer / proj / dropped keys.
6
+ 2. Run the fixed 48-edit selection subset (first 12 eval objects x 4) at 20 steps.
7
+ Compare against the ckpt2000 selection numbers (alpha_iou 0.836, lpips 0.087)
8
+ measured with the ORIGINAL ComfyUI-keyed file, whose gate_up keys were dropped
9
+ at load. The split adapter should be equal or better; a large drop would mean
10
+ the fused-order assumption (rows [0:12288]=gate_layer, rest=proj) is wrong.
11
+ """
12
+ import argparse, io, json, logging, os, warnings
13
+ import eval_edit as ee
14
+ import select_ckpt as sc
15
+
16
+ ee.STEPS = 20 # same subset budget as the selection run, for apples-to-apples numbers
17
+
18
+ MODEL_REPO = 'ysharma/orbit-alpha-lora'
19
+ SPLIT_FILE = 'checkpoints/steps2000res768/orbit_alpha_lora_gate_up_split.safetensors'
20
+ DS_REPO = ee.DS_REPO
21
+ OUT_REPO_PATH = 'eval/gate_up_split'
22
+ REFERENCE = {'name': 'ckpt2000-selection-run', 'alpha_iou': 0.836, 'lpips': 0.087}
23
+
24
+
25
+ def capture_load(pipe, path):
26
+ """Load adapter while recording every warning and diffusers/peft log line."""
27
+ buf = []
28
+
29
+ class Rec(logging.Handler):
30
+ def emit(self, record):
31
+ buf.append(record.getMessage())
32
+
33
+ h = Rec()
34
+ logging.getLogger().addHandler(h)
35
+ for n in ('diffusers', 'peft', 'diffusers.loaders', 'diffusers.models', 'root'):
36
+ lg = logging.getLogger(n)
37
+ old = lg.level
38
+ lg.setLevel(logging.DEBUG)
39
+ lg.addHandler(h)
40
+ setattr(h, '_saved_' + n.replace('.', '_'), (lg, old))
41
+ with warnings.catch_warnings(record=True) as wlist:
42
+ warnings.simplefilter('always')
43
+ pipe.load_lora_weights(path)
44
+ msgs = list(buf) + [str(w.message) for w in wlist]
45
+ for n in ('diffusers', 'peft', 'diffusers.loaders', 'diffusers.models', 'root'):
46
+ lg = logging.getLogger(n)
47
+ lg.removeHandler(h)
48
+ logging.getLogger().removeHandler(h)
49
+ return msgs
50
+
51
+
52
+ def main():
53
+ ap = argparse.ArgumentParser()
54
+ ap.add_argument('--out', required=True)
55
+ args = ap.parse_args()
56
+ os.makedirs(args.out, exist_ok=True)
57
+
58
+ pairs = sc.pick_subset([json.loads(l) for l in open(ee.get_file('pairs_eval.jsonl'))])
59
+ print(f'subset: {len(pairs)} edits', flush=True)
60
+
61
+ pipe = ee.load_pipe()
62
+ m = ee.make_metrics()
63
+
64
+ local = ee.hf_hub_download(repo_id=MODEL_REPO, repo_type='model', filename=SPLIT_FILE)
65
+ msgs = capture_load(pipe, local)
66
+ print('LOAD MESSAGES:', json.dumps(msgs), flush=True)
67
+ bad = [x for x in msgs if any(t in x.lower() for t in
68
+ ('gate_up', 'not found', 'skipped', 'dropped', 'unexpected key', 'no module'))]
69
+ load_clean = not bad
70
+ print(f'LOAD CLEAN: {load_clean}', flush=True)
71
+ if not load_clean:
72
+ for b in bad:
73
+ print(' SUSPECT:', b, flush=True)
74
+
75
+ rows = ee.run_pairs(pipe, m, pairs, 'instruction', os.path.join(args.out, 'split48'))
76
+ r = sc.agg_rows(rows, 'split-adapter-48edits')
77
+ r['load_clean'] = load_clean
78
+ r['load_warnings'] = bad
79
+ r['reference_ckpt2000'] = REFERENCE
80
+ verdict = load_clean and r['alpha_iou'] >= REFERENCE['alpha_iou'] - 0.02 \
81
+ and r['lpips'] <= REFERENCE['lpips'] + 0.01
82
+ r['verdict'] = 'PASS' if verdict else 'FAIL'
83
+ print('VERDICT:', r['verdict'], flush=True)
84
+
85
+ with open(os.path.join(args.out, 'summary.json'), 'w') as f:
86
+ json.dump(r, f, indent=2)
87
+ sc.upload(os.path.join(args.out, 'summary.json'), f'{OUT_REPO_PATH}/summary.json')
88
+ sc.upload(os.path.join(args.out, 'split48', 'results.jsonl'), f'{OUT_REPO_PATH}/split48_results.jsonl')
89
+ print('DONE', flush=True)
90
+
91
+
92
+ if __name__ == '__main__':
93
+ main()