interplane.Get Omega
Read in your language

aien-train

AIEN training programme: language-model history, GB10 constraints and the route to training on the project engine. Plans and runnable checks are distinguished.

Brought by drakestapleton

branch main Branches Tags History

aien-train / tests / omegallm / weight-edit-check.py

60 lines · 2818 bytes Raw Blame History
1"""Independent external test instrument for the Omega checkpoint editor."""
2import json
3from pathlib import Path
4import struct
5import subprocess
6import sys
7import tempfile
8
9build = Path(sys.argv[1]).resolve()
10tool = build / 'weight-edit'
11ollm = build / 'ollm'
12
13def run(*args, expected=0):
14 p = subprocess.run([str(x) for x in args], capture_output=True)
15 assert p.returncode == expected, (str(args[0]), p.returncode, expected, p.stderr.decode())
16
17def values(path):
18 b = path.read_bytes()
19 h = struct.unpack('<15Q', b[:120])
20 return b, h, struct.unpack('<' + 'd' * (h[12] * 3), b[120:])
21
22with tempfile.TemporaryDirectory(prefix='weight-edit-check-') as tmp:
23 r = Path(tmp)
24 old, new = r/'old.ck', r/'new.ck'
25 run(ollm, 'init', old, 256, 8, 16, 2, 32, 2, 2, 1, 10, 3000, 1)
26 new.write_bytes(old.read_bytes())
27 (r/'train.bin').write_bytes(b'abc abcd abcde\0' * 200)
28 run(ollm, 'train', new, r/'train.bin', 2, 1)
29 run(tool, old, new, r/'identity.ck', 1000, 1000)
30 assert new.read_bytes() == (r/'identity.ck').read_bytes()
31 oldb, oldh, oldv = values(old)
32 newb, newh, newv = values(new)
33 p, d = newh[12], newh[3]
34 for alpha, gain in [(500, 1000), (900, 1000), (1100, 1000), (1000, 950), (1050, 1100)]:
35 out = r/f'a{alpha}-g{gain}.ck'
36 run(tool, old, new, out, alpha, gain)
37 b, h, v = values(out)
38 assert h[:-1] == newh[:-1]
39 assert b[120 + p*8:] == newb[120 + p*8:], 'optimizer state changed'
40 expected = [newv[i] + (alpha/1000.0-1.0)*(newv[i]-oldv[i]) for i in range(p)]
41 for i in range(p-d, p):
42 expected[i] *= gain/1000.0
43 assert tuple(expected) == v[:p], 'weight calculation differs from independent reference'
44 # Production loader checks payload checksum and file structure.
45 run(ollm, 'eval', out, r/'train.bin', 1)
46 run(tool, old, new, new, 1100, 1000, expected=52)
47 assert new.read_bytes() == newb
48 run(tool, old, new, r/'bad-range.ck', 1201, 1000, expected=51)
49 run(tool, old, new, r/'bad-low-range.ck', 499, 1000, expected=51)
50 corrupt = bytearray(oldb)
51 corrupt[-1] ^= 1
52 (r/'corrupt.ck').write_bytes(corrupt)
53 run(tool, r/'corrupt.ck', new, r/'bad-hash.ck', 1000, 1000, expected=14)
54 run(ollm, 'init', r/'wrong.ck', 256, 8, 16, 2, 32, 1, 2, 1, 10, 3000, 1)
55 run(tool, r/'wrong.ck', new, r/'bad-shape.ck', 1000, 1000, expected=53)
56 assert not any((r/name).exists() for name in ('bad-range.ck','bad-low-range.ck','bad-hash.ck','bad-shape.ck'))
57 assert old.read_bytes() == oldb
58 print(json.dumps({'identity': 'PASS', 'five_weight_reference_cases': 'PASS',
59 'checksum_loads': 'PASS', 'optimizer_bytes_preserved': 'PASS',
60 'overwrite_range_hash_shape_refusals': 'PASS', 'originals_unchanged': 'PASS'}))