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

405 lines · 8654 bytes Raw Blame History
1note SPDX-License-Identifier: AGPL-3.0-only
2note omegallm data.om (aien-train#52): argument paths, whole-file data reads, prep (CONTRACT
3note section 4), the splitmix64 batch rule and the add-one byte baselines. Needs math.om before it.
4note A data file lives in two byte pools (od0 then od1), 2^25 bytes in all; a byte is read by odb.
5const ODHALF ulong 16777216
6const ODCAP ulong 33554432
7global od0 uchar 16777216
8global od1 uchar 16777216
9global odn ulong 1
10global oarg uchar 4100
11global ochk uchar 65536
12global obx ulong 16384
13global oby ulong 16384
14global owb0 uchar 65536
15global owb1 uchar 65536
16global owbn ulong 2
17global ocnt ulong 65536
18global ocnu ulong 256
19global ocnr ulong 256
20global oseps uchar 16
21note v1 (CONTRACT-V1 section 3): the window that the platform's positioned read oprd fills; prep,
22note the bpe commands and the windowed data reads all use it.
23const OPWCAP ulong 2097152
24global opw uchar 2097152
25
26note exit codes of this unit: 2 usage, 20 data file empty or too short for T, 21 data file over
27note 2^25 bytes, 70 I/O.
28
29note argument i into oarg; returns its length (1 .. 4096) or exits 2.
30fn oargp i ulong to ulong
31r = oargr i
32if or le r 0 gt r 4096
33exit 2
34end
35ret ulong r
36end
37
38note argv[i] as an unsigned decimal of 1 .. 19 digits.
39fn oargu i ulong to ulong
40n = oargp i
41if gt n 19
42exit 2
43end
44v = ulong 0
45for k ulong n
46c = ulong get oarg k
47if or lt c 48 gt c 57
48exit 2
49end
50v = add mul v 10 sub c 48
51end
52ret v
53end
54
55fn odb i ulong to ulong
56if lt i ODHALF
57ret ulong get od0 i
58end
59ret ulong get od1 sub i ODHALF
60end
61
62fn odset i ulong c ulong to void
63if lt i ODHALF
64put od0 i uchar c
65else
66put od1 sub i ODHALF uchar c
67end
68end
69
70note prep output: two buffered writers (k = 0 TRAIN, k = 1 HELD); owopen, owflush and owclose are
71note the platform unit's (lio.om, eio.om).
72fn owbyte k ulong c ulong to void
73n = get owbn k
74if ge n 65536
75owflush k
76n = ulong 0
77end
78if eq k 0
79put owb0 n uchar c
80else
81put owb1 n uchar c
82end
83put owbn k add n 1
84end
85
86note 1 when the separator <|endoftext|> starts at opw[p] (p + 13 <= n).
87fn oissep p ulong n ulong to bool
88if gt add p 13 n
89ret false
90end
91for k ulong 13
92if ne get opw add p k get oseps k
93ret false
94end
95end
96ret true
97end
98
99fn owsp c ulong to bool
100ret or or eq c 9 eq c 10 or eq c 13 eq c 32
101end
102
103note Emit story opw[a, e) after trimming whitespace; an empty story is dropped. st[0..4] count
104note stories, train stories, held stories, train bytes, held bytes. A story over 999999 bytes is
105note refused with exit 24 (cmdprep refuses it already while scanning; every loop here is bounded).
106fn ostory a ulong e ulong st edit ulong 8 to void
107if gt sub e a 999999
108exit 24
109end
110lo = a
111hi = e
112while lt lo hi bound 999999
113if not owsp ulong get opw lo
114break
115end
116lo = add lo 1
117end
118while gt hi lo bound 999999
119if not owsp ulong get opw sub hi 1
120break
121end
122hi = sub hi 1
123end
124if lt lo hi
125k = ulong 0
126if eq rem get st 0 10 9
127k = ulong 1
128end
129put st 0 add get st 0 1
130put st add k 1 add get st add k 1 1
131for i ulong sub hi lo
132owbyte k ulong get opw add lo i
133end
134owbyte k 0
135put st add k 3 add add get st add k 3 sub hi lo 1
136end
137end
138
139note `<|endoftext|>` = 60 124 101 110 100 111 102 116 101 120 116 124 62.
140fn oseptab to void
141put oseps 0 60
142put oseps 1 124
143put oseps 2 101
144put oseps 3 110
145put oseps 4 100
146put oseps 5 111
147put oseps 6 102
148put oseps 7 116
149put oseps 8 101
150put oseps 9 120
151put oseps 10 116
152put oseps 11 124
153put oseps 12 62
154end
155
156note Stream window over argv[ai] (prep and the bpe commands): opw holds the file's bytes
157note [wb, wb + wn) with opst = wb, wn, eof (1 once a refill came back short). opstart fills it from
158note byte 0; opshift a moves opw[a, wn) to the front and refills the rest of the window.
159global opst ulong 4
160fn opstart ai ulong to void
161wn = oprd ai 0 0 OPWCAP
162put opst 0 0
163put opst 1 wn
164put opst 2 0
165if lt wn OPWCAP
166put opst 2 1
167end
168end
169
170fn opshift ai ulong a ulong to void
171wn = get opst 1
172cnt = sub wn a
173i = ulong 0
174for o ulong 3
175lim = mul add o 1 999999
176if gt lim cnt
177lim = cnt
178end
179while lt i lim bound 999999
180put opw i get opw add a i
181i = add i 1
182end
183end
184wb = add get opst 0 a
185wn = sub wn a
186r = oprd ai add wb wn wn sub OPWCAP wn
187put opst 0 wb
188put opst 1 add wn r
189put opst 2 0
190if lt r sub OPWCAP wn
191put opst 2 1
192end
193end
194
195note prep IN TRAIN HELD (CONTRACT-V1 section 3): IN is read as a stream through the window opw.
196note The current story starts at opw[a]; p scans. When the separator test at p needs bytes past
197note the window, opshift moves [a, wn) to the front and refills. A story whose raw length passes
198note 999999 is exit 24 as soon as the scan shows it (v0 refused the same story, after the same
199note earlier stories, in ostory); so a moved story keeps at most 1000012 bytes and every refill
200note reads at least 1097140. Each inner pass advances p by 1 or 13 or ends the scan: 999999 x 999999
201note passes cover any IN below 2^39 bytes.
202fn cmdprep to void
203if ne oargc 5
204exit 2
205end
206oseptab
207opstart 2
208wn = get opst 1
209eof = ne get opst 2 0
210owopen 0 3
211owopen 1 4
212st = new ulong 8 0
213a = ulong 0
214p = ulong 0
215dn = false
216while not dn bound 999999
217q = ulong 0
218while and not dn lt q 999999 bound 999999
219q = add q 1
220if and gt add p 13 wn not eof
221opshift 2 a
222p = sub p a
223a = ulong 0
224wn = get opst 1
225eof = ne get opst 2 0
226end
227if ge p wn
228dn = true
229else
230if eq get opw p 60
231if oissep p wn
232ostory a p st
233p = add p 13
234a = p
235continue
236end
237end
238p = add p 1
239if gt sub p a 999999
240exit 24
241end
242end
243end
244end
245ostory a wn st
246owclose 0
247owclose 1
248oputc 80
249for i ulong 5
250oputc 32
251oputu get st i
252end
253oputc 10
254oflush
255end
256
257note Batch for step s (CONTRACT section 4): x and y for b = 0..B-1 into obx/oby (stride T); N, the
258note data length in tokens, is odn[0] (odopen).
259note OMUTB is the target offset: 1 in the product, 2 in mutant b (targets shifted by one).
260const OMUTB ulong 1
261fn obatch s ulong to void
262bb = get og 6
263tt = get og 1
264n = get odn 0
265sd = get og 40
266for b ulong bb
267o = rem smx xor sd mul add mul s bb b 11400714819323198485 sub n tt
268obrow b o
269end
270end
271
272note v1 data file (CONTRACT-V1 section 3): argument ai holds bytes when V = 256 and u16
273note little-endian tokens when V > 256 (og 49 = bytes per token, og 47 = the argument). Sets
274note odn[0] = N tokens; exit 21 on an odd byte length at V > 256, 20 when N < T + 1. Rows are read
275note through oprd when used, so a token >= V is refused (25) only in a row actually read.
276fn odopen ai ulong to void
277w = ulong 1
278if gt get og 0 256
279w = 2
280end
281nb = ofsz ai
282if ne rem nb w 0
283exit 21
284end
285put og 47 ai
286put og 49 w
287put odn 0 div nb w
288if le get odn 0 get og 1
289exit 20
290end
291end
292
293note token k of the window last read by odrow. OMUTE: 1 in the product (u16 little-endian); 0 in
294note mutant e (big-endian), which the referee comparison must catch.
295const OMUTE ulong 1
296fn odtk k ulong to ulong
297if eq get og 49 1
298ret ulong get opw k
299end
300lo = ulong get opw mul k 2
301hi = ulong get opw add mul k 2 1
302if eq OMUTE 0
303ret or shl lo 8 hi
304end
305ret or shl hi 8 lo
306end
307
308note read tokens o .. o + n - 1 (fewer at the end of the file; the rest read as 0) into opw;
309note exit 25 when a token read is >= V
310fn odrow o ulong n ulong to void
311w = get og 49
312nb = mul n w
313for i ulong nb
314put opw i 0
315end
316r = oprd get og 47 mul o w 0 nb
317m = div r w
318v = get og 0
319for k ulong m
320if ge odtk k v
321exit 25
322end
323end
324end
325
326fn obrow b ulong o ulong to void
327tt = get og 1
328odrow o add tt OMUTB
329for t ulong tt
330put obx add mul b tt t odtk t
331put oby add mul b tt t odtk add t OMUTB
332end
333end
334
335note base TRAIN HELD (CONTRACT section 7 and agreed reading A5): unigram and bigram add-one
336note counts over all TRAIN bytes and all N-1 adjacent TRAIN pairs; scored on HELD targets 1..M-1.
337fn cmdbase to void
338if ne oargc 4
339exit 2
340end
341n = odread 2
342if lt n 2
343exit 20
344end
345for o ulong 64
346for i ulong 524288
347j = add mul o 524288 i
348if ge j n
349break
350end
351obfit j
352end
353end
354m = odread 3
355if lt m 2
356exit 20
357end
358su = 0.0f64
359sb = 0.0f64
360dn = f64 add n 256
361for o2 ulong 64
362for i2 ulong 524288
363j2 = add mul o2 524288 i2
364if ge j2 m
365break
366end
367if gt j2 0
368su = add su obsu j2 dn
369sb = add sb obsb j2
370end
371end
372end
373fm = f64 sub m 1
374oputc 66
375oputc 32
376oputl rmic div div neg su fm 0.6931471805599453
377oputc 32
378oputl rmic div div neg sb fm 0.6931471805599453
379oputc 10
380oflush
381end
382
383note count TRAIN byte j and the pair (j-1, j)
384fn obfit j ulong to void
385c = odb j
386put ocnu c add get ocnu c 1
387if gt j 0
388pv = odb sub j 1
389q = add mul pv 256 c
390put ocnt q add get ocnt q 1
391put ocnr pv add get ocnr pv 1
392end
393end
394
395note log of the unigram probability (c+1)/(N+256) of HELD byte j
396fn obsu j ulong dn f64 to f64
397ret flog div f64 add get ocnu odb j 1 dn
398end
399
400note log of the bigram probability (c+1)/(row+256) of HELD pair (j-1, j)
401fn obsb j ulong to f64
402pv = odb sub j 1
403q = add mul pv 256 odb j
404ret flog div f64 add get ocnt q 1 f64 add get ocnr pv 256
405end