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 / native / omegallm / ckpt.om

274 lines · 6104 bytes Raw Blame History
1note SPDX-License-Identifier: AGPL-3.0-only
2note omegallm ckpt.om (aien-train#52): checkpoint OLLMCK01 / OLLMCK02 and gradient OLLMGR01 files
3note (CONTRACT section 6, CONTRACT-V1 section 6). Needs math.om, data.om, model.om, adam.om before it.
4note Files are streamed: a save encodes the f64 payload little-endian in chunks of OCKC values into
5note ock, hashes each chunk (FNV-1a 64) and writes it at its file position through the platform
6note unit (ocwopen, ocwput, ocwend; lio.om writes PATH.tmp, fsync, rename; eio.om the file in
7note place), then writes the header at position 0. A load reads the header and then the payload in
8note chunks through oprd into opw, hashing and decoding into the pools in one pass.
9note CK01 header 112 bytes (FNV at 104); CK02 120 bytes (G at 104, FNV at 112); GR01 112 bytes, step
10note field = B, one payload. Largest file at the v3 maxima: 120 + 24 P with P = 29995392 (Wolfram:
11note 120+24*29995392 -> 719889528); a file over OCKCAP = 719889529 bytes is refused with 15 before its
12note header is read, as v0 refused a file over its image (exactly OCKCAP bytes goes to the header
13note checks, then 15).
14note Magic as a little-endian u64 (Wolfram FromDigits[Reverse[ToCharacterCode["OLLMCK01"]],256]
15note -> 3544415659172318287; "OLLMGR01" -> 3544423372933581903; "OLLMCK02" -> 3616473253210246223).
16note Load refusals (exit codes): 10 file shorter than its header or than header + 24 P, 11 bad magic,
17note 12 a shape zero or over the maximum, V < 256, D mod H != 0, TOTAL > 999999, or (CK02) G = 0,
18note G > B or B mod G != 0, 13 P disagrees with the shapes, 14 FNV-1a mismatch, 15 file longer than
19note header + 24 P; 70 I/O.
20const OCKCAP ulong 719889529
21const OCKC ulong 65536
22global ock uchar 524288
23
24fn ocput8 o ulong v ulong to void
25for k ulong 8
26put ock add o k uchar and shr v mul k 8 255
27end
28end
29
30
31note little-endian u64 at ock[o .. o + 8)
32fn ocget8 o ulong to ulong
33v = ulong 0
34for k ulong 8
35v = or v shl ulong get ock add o k mul k 8
36end
37ret v
38end
39
40note decode m values from ock into gradient pool [o .. o + m) (a worker's gradient block, lio.om)
41fn ocdecb o ulong m ulong to void
42for j ulong m
43ogrp add o j bitcast f64 ocget8 mul j 8
44end
45end
46note little-endian u64 at opw[o .. o + 8)
47fn opw8 o ulong to ulong
48v = ulong 0
49for k ulong 8
50v = or v shl ulong get opw add o k mul k 8
51end
52ret v
53end
54
55note FNV-1a 64 step over ock[0 .. n) from state h (basis cbf29ce484222325, prime 100000001b3)
56fn ocfnvk h ulong n ulong to ulong
57x = h
58for i ulong n
59x = mul xor x ulong get ock i 1099511628211
60end
61ret x
62end
63
64fn ocfnvw h ulong n ulong to ulong
65x = h
66for i ulong n
67x = mul xor x ulong get opw i 1099511628211
68end
69ret x
70end
71
72note header fields from og into ock[0 .. 104); magic mg, step field st
73fn ochead mg ulong st ulong to void
74ocput8 0 mg
75for i ulong 7
76ocput8 add 8 mul i 8 get og i
77end
78ocput8 64 get og 40
79ocput8 72 st
80ocput8 80 get og 42
81ocput8 88 get og 43
82ocput8 96 get og 8
83end
84
85note encode m values of pool k (0 params, 1 m, 2 v, 3 GRD, 4 BLK) from value index i into ock
86fn ocenc k ulong i ulong m ulong to void
87if eq k 0
88for j ulong m
89ocput8 mul j 8 bitcast ulong owg add i j
90end
91ret
92end
93if ge k 3
94o = add get og 10 i
95if eq k 4
96o = add get og 8 i
97end
98for j ulong m
99ocput8 mul j 8 bitcast ulong ogrg add o j
100end
101ret
102end
103o = add get og add 10 k i
104for j ulong m
105ocput8 mul j 8 bitcast ulong omvg add o j
106end
107end
108
109note decode m values from opw into pool k (0 params, 1 m, 2 v) from value index i
110fn ocdec k ulong i ulong m ulong to void
111if eq k 0
112for j ulong m
113owp add i j bitcast f64 opw8 mul j 8
114end
115ret
116end
117o = add get og add 10 k i
118for j ulong m
119omvp add o j bitcast f64 opw8 mul j 8
120end
121end
122
123note stream pools ks .. ke-1 (ocenc numbering) after a header of hl bytes; returns the FNV-1a
124fn ocbody ks ulong ke ulong hl ulong to ulong
125p = get og 8
126h = ulong 14695981039346656037
127pos = hl
128nc = div add p sub OCKC 1 OCKC
129for k ulong sub ke ks
130for c ulong nc
131i = mul c OCKC
132m = sub p i
133if gt m OCKC
134m = OCKC
135end
136ocenc add ks k i m
137nb = mul m 8
138h = ocfnvk h nb
139ocwput pos nb
140pos = add pos nb
141end
142end
143ret h
144end
145
146note write checkpoint (params, m, v) to argv[ai] with the loaded or initialised magic (og 46)
147fn ocksave ai ulong to void
148ocwopen ai
149hl = ulong 112
150if eq get og 46 2
151hl = 120
152end
153h = ocbody 0 3 hl
154if eq hl 120
155ochead 3616473253210246223 get og 41
156ocput8 104 get og 44
157ocput8 112 h
158else
159ochead 3544415659172318287 get og 41
160ocput8 104 h
161end
162ocwput 0 hl
163ocwend ai
164end
165
166note write gradient file GR01: header with step = B, payload GRD (for either checkpoint magic)
167fn ogrsave ai ulong to void
168ocwopen ai
169h = ocbody 3 4 112
170ochead 3544423372933581903 get og 6
171ocput8 104 h
172ocwput 0 112
173ocwend ai
174end
175
176note load the checkpoint named by argv[ai] into og, ow (params) and omv (m, v)
177fn ockload ai ulong to void
178n = ofsz ai
179if gt n OCKCAP
180exit 15
181end
182hn = oprd ai 0 0 120
183if lt n 112
184exit 10
185end
186mg = opw8 0
187hl = ulong 112
188if eq mg 3616473253210246223
189hl = 120
190put og 46 2
191else
192if ne mg 3544415659172318287
193exit 11
194end
195put og 46 1
196end
197if lt n hl
198exit 10
199end
200for i ulong 7
201put og i opw8 add 8 mul i 8
202end
203if not ogeom
204exit 12
205end
206put og 40 opw8 64
207put og 41 opw8 72
208put og 42 opw8 80
209put og 43 opw8 88
210if gt get og 42 999999
211exit 12
212end
213g = ulong 1
214if eq hl 120
215g = opw8 104
216end
217if not ogok2 g
218exit 12
219end
220put og 44 g
221put og 45 1
222p = get og 8
223if ne opw8 96 p
224exit 13
225end
226hs = opw8 sub hl 8
227pb = mul 24 p
228if lt n add hl pb
229exit 10
230end
231if gt n add hl pb
232exit 15
233end
234if ne ocklp ai hl p hs 1
235exit 14
236end
237end
238
239note one pass over the payload at hl: read, hash and decode each chunk; exit 70 on a short read.
240note Returns 1 when the payload FNV equals hs, else 0.
241fn ocklp ai ulong hl ulong p ulong hs ulong to ulong
242h = ulong 14695981039346656037
243nc = div add p sub OCKC 1 OCKC
244pos = hl
245for k ulong 3
246for c ulong nc
247i = mul c OCKC
248m = sub p i
249if gt m OCKC
250m = OCKC
251end
252nb = mul m 8
253if ne oprd ai pos 0 nb nb
254exit 70
255end
256h = ocfnvw h nb
257ocdec k i m
258pos = add pos nb
259end
260end
261if eq h hs
262ret 1
263end
264ret 0
265end
266
267note G against the loaded shapes: 1 <= G <= B and B mod G = 0
268fn ogok2 g ulong to bool
269b = get og 6
270if or eq g 0 gt g b
271ret false
272end
273ret eq rem b g 0
274end