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 / mio.om

351 lines · 6331 bytes Raw Blame History
1note SPDX-License-Identifier: AGPL-3.0-only
2note omegallm lio.om (aien-train#52): the Linux platform unit, the only unit that uses host words.
3note It is concatenated last for targets aarch64 and x86linux; eio.om replaces it for x86efi. Both
4note define the same functions: oargc, oargr, oflush, ocwopen, ocwput, ocwend, ofsz, ogradw, ocsinit,
5note ocsg, ocsp, odread, owflush, owopen, owclose, ooffrd, oprd, obmsave and main. Every other unit is
6note free of host words.
7global owfd int 2
8global opth uchar 2100
9global opk uchar 4200
10global ocfd int 1
11global opp uchar 8
12global ost uchar 8
13global owrf int 64
14global owpd int 64
15
16note the argument count (argv[0] included)
17fn oargc to ulong
18ret ulong argcnt
19end
20
21note argv[i] into oarg (at most 4096 bytes); returns the argread result (negative: no such argument)
22fn oargr i ulong to long
23ret argread i oarg 0 4096
24end
25
26fn main to int
27if lt oargc 2
28exit 2
29end
30ret ocmd
31end
32
33note onsnow: monotonic nanoseconds (kvcmp's step timing in cli.om)
34fn onsnow to ulong
35ret ulong monons
36end
37
38fn oflush to void
39n = get oon 0
40p = ulong 0
41while lt p n bound 4097
42w = write 1 oout p sub n p
43if le w 0
44exit 70
45end
46p = add p ulong w
47end
48put oon 0 0
49end
50
51note v1 checkpoint stream (ckpt.om): open PATH.tmp for the path in argv[ai] (created, emptied)
52fn ocwopen ai ulong to void
53pl = oargp ai
54if gt pl 2000
55exit 2
56end
57for i ulong pl
58put opth i get oarg i
59end
60put opth pl 46
61put opth add pl 1 116
62put opth add pl 2 109
63put opth add pl 3 112
64fd = int fopen opth 0 add pl 4 577 420
65if lt fd 0
66exit 70
67end
68put ocfd 0 fd
69end
70
71note write ock[0 .. n) at byte position pos of the open PATH.tmp
72fn ocwput pos ulong n ulong to void
73fd = get ocfd 0
74p = ulong 0
75while lt p n bound 999999
76w = pwrite fd ock p sub n p long add pos p
77if le w 0
78exit 70
79end
80p = add p ulong w
81end
82end
83
84note fsync and close PATH.tmp, then rename it onto the path in argv[ai]
85fn ocwend ai ulong to void
86fd = get ocfd 0
87if ne fsync fd 0
88exit 70
89end
90if ne fclose fd 0
91exit 70
92end
93ocrename oargp ai
94end
95
96note rename opth[0 .. pl+4) to opth[0 .. pl) via a packed two-path list
97fn ocrename pl ulong to void
98put opk 0 2
99put opk 1 0
100put opk 2 uchar and add pl 4 255
101put opk 3 uchar shr add pl 4 8
102for i ulong add pl 4
103put opk add 4 i get opth i
104end
105q = add 8 pl
106put opk q uchar and pl 255
107put opk add q 1 uchar shr pl 8
108for j ulong pl
109put opk add add q 2 j get opth j
110end
111r = renames opk 0 add add q 2 pl 0
112if ne r 0
113exit 70
114end
115end
116
117note size in bytes of the file named by argv[ai] (seek to its end)
118fn ofsz ai ulong to ulong
119n = oargp ai
120fd = int fopen oarg 0 n 0 0
121if lt fd 0
122exit 70
123end
124sz = fseek fd 0 2
125if lt sz 0
126exit 70
127end
128if ne fclose fd 0
129exit 70
130end
131ret ulong sz
132end
133
134note cold store (CONTRACT-V3 section 2): GRD and the Adam moments, 3 P values at the CONTRACT-V3
135note maxima (3 29995392 -> 89986176 values, 719889408 bytes), in one private anonymous mapping made
136note on first use (mapnew prot 3 read/write, flags 34 private|anonymous; zero-filled, and inherited
137note copy-on-write by the gradient workers). A failed mapping is an I/O refusal (exit 70).
138const OCSN ulong 89986176
139global ocs f64 *
140global ocsf ulong 1
141
142fn ocsinit to ulong
143if eq get ocsf 0 0
144r = enlarge ocs OCSN
145if ne r 0
146exit 70
147end
148put ocsf 0 1
149end
150ret OCSN
151end
152
153fn ocsg i ulong to f64
154ret get ocs i
155end
156
157fn ocsp i ulong v f64 to void
158put ocs i v
159end
160
161fn ogradw to f64
162k = get og 45
163if gt k 1
164exit 70
165end
166ret ograd
167end
168
169fn odread i ulong to ulong
170n = oargp i
171fd = int fopen oarg 0 n 0 0
172if lt fd 0
173exit 70
174end
175p = ulong 0
176dn = false
177for o ulong 64
178q = ulong 0
179while and not dn lt q 999999 bound 999999
180q = add q 1
181r = long 0
182if lt p ODHALF
183r = read fd od0 p sub ODHALF p
184else
185if lt p ODCAP
186r = read fd od1 sub p ODHALF sub ODCAP p
187else
188r = read fd ochk 0 1
189end
190end
191if lt r 0
192exit 70
193end
194if eq r 0
195dn = true
196else
197p = add p ulong r
198if gt p ODCAP
199exit 21
200end
201end
202end
203if dn
204break
205end
206end
207if not dn
208exit 70
209end
210c = fclose fd
211put odn 0 p
212ret p
213end
214
215note prep output: two buffered writers (k = 0 TRAIN, k = 1 HELD).
216fn owflush k ulong to void
217n = get owbn k
218fd = get owfd k
219p = ulong 0
220while lt p n bound 65537
221w = long 0
222if eq k 0
223w = write fd owb0 p sub n p
224else
225w = write fd owb1 p sub n p
226end
227if le w 0
228exit 70
229end
230p = add p ulong w
231end
232put owbn k 0
233end
234
235fn owopen k ulong i ulong to void
236n = oargp i
237fd = int fopen oarg 0 n 577 420
238if lt fd 0
239exit 70
240end
241put owfd k fd
242put owbn k 0
243end
244
245fn owclose k ulong to void
246owflush k
247fd = get owfd k
248if ne fsync fd 0
249exit 70
250end
251if ne fclose fd 0
252exit 70
253end
254end
255
256note read argv[ai] (B little-endian u64 offsets) into ochk; exit 21 unless it holds exactly 8 B bytes
257fn ooffrd ai ulong to void
258n = oargp ai
259fd = int fopen oarg 0 n 0 0
260if lt fd 0
261exit 70
262end
263p = ulong 0
264dn = false
265while not dn bound 70000
266r = read fd ochk p sub 65536 p
267if lt r 0
268exit 70
269end
270if eq r 0
271dn = true
272else
273p = add p ulong r
274if ge p 65536
275exit 21
276end
277end
278end
279c = fclose fd
280if ne p mul 8 get og 6
281exit 21
282end
283end
284
285
286note v1 positioned read (CONTRACT-V1 section 3): read up to n bytes of the file named by argv[ai],
287note from byte pos, into opw[off .. off + n). The file is opened and closed on every call. Returns
288note the bytes read: n, fewer only when the file ends first, 0 at or after its end. Exit 70 on an
289note I/O error, 2 on a bad argument; off + n over len opw traps 3. Each pread pass adds at least one
290note byte or ends, so n + 1 <= 2097153 passes suffice: 3 outer passes of at most 999999 inner ones.
291fn oprd ai ulong pos ulong off ulong n ulong to ulong
292pl = oargp ai
293fd = int fopen oarg 0 pl 0 0
294if lt fd 0
295exit 70
296end
297p = ulong 0
298dn = false
299for o ulong 3
300while and not dn lt p n bound 999999
301r = pread fd opw add off p sub n p long add pos p
302if lt r 0
303exit 70
304end
305if eq r 0
306dn = true
307else
308p = add p ulong r
309end
310end
311end
312if ne fclose fd 0
313exit 70
314end
315ret p
316end
317
318note v1 (CONTRACT-V1 section 7): write obm[0 .. n) (bpe.om) to the path in argv[ai] as ocwrite does:
319note PATH.tmp, fsync, rename
320fn obmsave ai ulong n ulong to void
321pl = oargp ai
322if gt pl 2000
323exit 2
324end
325for i ulong pl
326put opth i get oarg i
327end
328put opth pl 46
329put opth add pl 1 116
330put opth add pl 2 109
331put opth add pl 3 112
332fd = int fopen opth 0 add pl 4 577 420
333if lt fd 0
334exit 70
335end
336p = ulong 0
337while lt p n bound 999999
338w = write fd obm p sub n p
339if le w 0
340exit 70
341end
342p = add p ulong w
343end
344if ne fsync fd 0
345exit 70
346end
347if ne fclose fd 0
348exit 70
349end
350ocrename pl
351end