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 / si19 / world-test.om

572 lines · 9901 bytes Raw Blame History
1note SPDX-License-Identifier: AGPL-3.0-only
2note aien-train#19 tests. The golden oracle is test-only exact integer arithmetic at
3note scale 2^24; it never calls add32/mul32 and decodes binary32 bits independently.
4global C ulong 1
5global OW long 8
6global OG long 8
7global OY long 4
8global OX long 6
9global OT long 4
10global OL long 1
11global TV ulong 8
12global TB ulong 64
13text PASS "SI19_WORLD_TEST_PASS checks="
14text FAIL "SI19_WORLD_TEST_FAIL check="
15text NL "\n"
16
17fn check ok bool to void
18put C 0 add get C 0 1
19if not ok
20w = write 1 FAIL 0 len FAIL
21wnum get C 0
22w = write 1 NL 0 1
23exit 1
24end
25end
26
27note ---- independent binary32 decode/encode for the oracle ----
28
29fn odec x ulong to long
30note Exact numerator at scale 2^24 of a normal binary32 value.
31if eq and x 2147483647 0
32ret 0
33end
34e = long and shr x 23 255
35check and gt e 0 lt e 255
36m = long or and x 8388607 8388608
37if ge e 126
38check le sub e 126 30
39m = shl m sub e 126
40else
41k = sub 126 e
42check le k 23
43check eq rem m shl long 1 k 0
44m = shr m k
45end
46if ne and x 2147483648 0
47ret neg m
48end
49ret m
50end
51
52fn obits num long to ulong
53note Exact binary32 bits of num/2^24; fails the test if not exactly representable.
54if eq num 0
55ret 0
56end
57sign = ulong 0
58if lt num 0
59sign = 2147483648
60num = neg num
61end
62m = ulong num
63sc = long 24
64while eq and m 1 0 bound 64
65m = shr m 1
66sc = sub sc 1
67end
68check lt m 16777216
69pw = long 0
70q = m
71while gt q 1 bound 64
72q = shr q 1
73pw = add pw 1
74end
75ex = sub add pw 127 sc
76check and gt ex 0 lt ex 255
77ret or sign or shl ulong ex 23 sub shl m ulong sub 23 pw 8388608
78end
79
80fn ochk num long to void
81x = obits num
82end
83
84fn oload row ulong id ulong to void
85r = mul id 8
86c = mul row 3
87put OX c get TL add r 1
88put OX add c 1 get TL add r 2
89put OX add c 2 get TL add r 3
90c = mul row 2
91put OT c get TL add r 4
92put OT add c 1 get TL add r 5
93end
94
95fn oforward row ulong col ulong to long
96y = get OW add 6 col
97for k ulong 3
98t = mul get OX add mul row 3 k get OW add mul k 2 col
99ochk t
100y = add y t
101ochk y
102end
103put OY add mul row 2 col y
104ret y
105end
106
107fn ograd row ulong col ulong g long to void
108put OG add 6 col add get OG add 6 col g
109ochk get OG add 6 col
110for k ulong 3
111i = add mul k 2 col
112gw = mul g get OX add mul row 3 k
113ochk gw
114put OG i add get OG i gw
115ochk get OG i
116end
117end
118
119fn ocell row ulong col ulong to void
120note One output element: forward, residual, loss term and gradient contributions.
121r = sub oforward row col shl get OT add mul row 2 col 24
122ochk r
123check eq rem r 4096 0
124h = div r 4096
125sq = mul h h
126ochk sq
127put OL 0 add get OL 0 sq
128ochk get OL 0
129g = mul r 2
130ochk g
131ograd row col g
132end
133
134fn ostep to void
135put OL 0 0
136for i ulong 8
137put OG i 0
138end
139for row ulong 2
140for col ulong 2
141ocell row col
142end
143end
144for i ulong 8
145d = get OG i
146check eq rem d 512 0
147d = div d 512
148ochk d
149put OW i sub get OW i d
150ochk get OW i
151end
152end
153
154fn ocompare to void
155note Real afstep slots and committed WS parameters against the exact oracle.
156for i ulong 8
157check eq get WS add 8 i obits get OW i
158end
159check eq get WS 5 obits get OL 0
160check eq get AL 0 obits get OL 0
161for i ulong 4
162check eq get AP add 64 i obits get OY i
163end
164for i ulong 6
165check eq get AP add 96 i obits get OG i
166end
167check eq get AP 112 obits get OG 6
168check eq get AP 113 obits get OG 7
169end
170
171fn tforward pb ulong to void
172note Forward-only predictor reproduces afstep's pre-update Y bit for bit.
173for row ulong 2
174id = get WS add 112 row
175r = mul id 8
176wmpred pb get TL add r 1 get TL add r 2 get TL add r 3
177check eq get PR 0 get AP add 64 mul row 2
178check eq get PR 1 get AP add 65 mul row 2
179end
180end
181
182fn tgolden to void
183note Two actual trainer updates (wstrain, arm M) on admitted experience vs exact oracle.
184wsinit
185check eq wsuses 0 0
186for i ulong 8
187check eq get WS add 8 i get WS add 40 i
188put OW i odec get WS add 40 i
189end
190wscollect 0
191put WS 0 1
192wscollect 0
193put WS 0 2
194wstrain 0 0 0
195tforward 40
196oload 0 get WS 112
197oload 1 get WS 113
198ostep
199ocompare
200check eq get WS 1 1
201put TB 0 get WS 112
202put TB 1 get WS 113
203for i ulong 8
204put TV i get WS add 8 i
205end
206wscopy 120 8 8
207wstrain 0 0 0
208tforward 120
209oload 0 get WS 112
210oload 1 get WS 113
211ostep
212ocompare
213check eq get WS 1 2
214check eq wsuses 0 4
215put TB 2 get WS 112
216put TB 3 get WS 113
217tbatch 0 4
218tbatch 1 4
219changed = ulong 0
220for i ulong 8
221if ne get TV i get WS add 8 i
222changed = add changed 1
223end
224end
225check gt changed 0
226end
227
228fn tbatch id ulong n ulong to void
229note Lineage counts equal the exact number of times id was in an applied batch.
230occ = ulong 0
231for i ulong n
232if eq get TB i id
233occ = add occ 1
234end
235end
236check eq get WS add 128 id occ
237end
238
239fn tlinexact to void
240note 32 real arm-M updates over 8 admitted experiences; every id's count is exact.
241wsinit
242for e ulong 8
243put WS 0 e
244wscollect 0
245end
246put WS 0 8
247for k ulong 32
248wstrain 0 0 0
249put TB mul k 2 get WS 112
250put TB add mul k 2 1 get WS 113
251end
252for id ulong 8
253tbatch id 64
254end
255check eq wsuses 0 64
256end
257
258fn tshuffle to void
259note Shuffled control: row inputs and row outcome come from the recorded, distinct ids.
260wsinit
261wscollect 0
262put WS 0 1
263wscollect 0
264put WS 0 2
265seen = ulong 0
266for k ulong 64
267wsshuf
268a = get WS 116
269t = get WS 117
270if ne a t
271seen = add seen 1
272check eq get AP 0 wmbits get TL add mul a 8 1 0
273check eq get AP 1 wmbits get TL add mul a 8 2 0
274check eq get AP 48 wmbits get TL add mul t 8 4 0
275check eq get AP 49 wmbits get TL add mul t 8 5 0
276end
277end
278check gt seen 0
279check eq wsuses 2 256
280end
281
282note ---- fixture: seeded, resettable, transition boundaries ----
283
284fn tsame to void
285fxinit 2 1 4242 0
286for i ulong 300
287u = fxact 2
288fxstep 2 u
289for k ulong 7
290put OG k get FT k
291end
292fxinit 3 1 4242 0
293for j ulong i
294uu = fxact 3
295fxstep 3 uu
296end
297u = fxact 3
298fxstep 3 u
299for k ulong 7
300check eq get OG k get FT k
301end
302end
303end
304
305fn tdiffer to void
306fxinit 2 1 4242 0
307fxinit 3 1 4243 0
308same = ulong 0
309for i ulong 64
310u = fxact 2
311fxstep 2 u
312for k ulong 5
313put OG k get FT k
314end
315u = fxact 3
316fxstep 3 u
317eqp = eq get OG 0 get FT 0
318if and eqp eq get OG 1 get FT 1
319same = add same 1
320end
321end
322check lt same 64
323end
324
325fn tin x long lo long hi long to void
326check and ge x lo le x hi
327end
328
329fn tdone r ulong to void
330step = rem get TL add r 7 16
331dn = fxdone get TL add r 4 get TL add r 5 step
332check eq get TL add r 6 dn
333end
334
335fn trec id ulong gain long to void
336note Each logged transition obeys the dynamics; terminal flag matches bounds and horizon.
337r = mul id 8
338check eq get TL r long id
339v = get TL add r 2
340tin get TL add r 1 -12 12
341tin v -3 3
342tin get TL add r 3 -1 1
343check eq get TL add r 4 add get TL add r 1 v
344g = sub get TL add r 5 v
345tin sub g mul gain get TL add r 3 -1 1
346tdone r
347end
348
349fn tlink id ulong to void
350note Consecutive records: a terminal record is followed by a fresh reset, never its successor.
351r = mul id 8
352n = add r 8
353a = get TL add r 7
354b = get TL add n 7
355if eq get TL add r 6 1
356check eq rem b 16 0
357a = add div a 16 1
358check eq div b 16 a
359tin get TL add n 1 -12 -4
360tin get TL add n 2 -2 2
361else
362check eq b add a 1
363a = get TL add r 4
364check eq get TL add n 1 a
365a = get TL add r 5
366check eq get TL add n 2 a
367end
368end
369
370fn tboundary to void
371for i ulong 256
372trec i 1
373trec add 256 i -1
374end
375for i ulong 255
376tlink i
377tlink add 256 i
378end
379end
380
381note ---- lineage and held-out separation ----
382
383fn tlineage to void
384check eq wsuses 0 4096
385check eq wsuses 1 4096
386check eq wsuses 2 4096
387check eq wsuses 3 2048
388for i ulong 512
389check ge get WS add 640 i get WS add 1664 i
390check ge get WS add 128 i get WS add 1664 i
391end
392for i ulong 256
393check not wsaffect 3 add 256 i
394check not wsaffect 2 add 256 i
395end
396nb = ulong 0
397for i ulong 256
398if wsaffect 1 add 256 i
399nb = add nb 1
400end
401end
402check gt nb 0
403end
404
405fn tkey r ulong t ulong to bool
406a = get HO add r 1
407if ne a get TL add t 1
408ret false
409end
410a = get HO add r 2
411if ne a get TL add t 2
412ret false
413end
414a = get HO add r 3
415ret eq a get TL add t 3
416end
417
418fn theld env ulong to void
419note Held-out ids are outside the training range and keys never occur in training.
420wsfreq env
421wsheld env
422for n ulong 128
423r = mul n 8
424check eq get HO r long add 1048576 n
425for j ulong 256
426t = mul add mul env 256 j 8
427check not tkey r t
428end
429end
430end
431
432note ---- checkpoint restart and refusal ----
433
434fn tdig to ulong
435h = ulong 1469598103934665603
436for i ulong 2304
437h = mul xor h get WS i 1099511628211
438end
439for i ulong 4096
440h = mul xor h wsenc get TL i 1099511628211
441end
442for i ulong 64
443h = mul xor h wsenc get FS i 1099511628211
444end
445ret h
446end
447
448fn twipe to void
449for i ulong 2304
450put WS i 0
451end
452for i ulong 4096
453put TL i 0
454end
455for i ulong 64
456put FS i 0
457end
458for i ulong 192
459put AD i 0
460end
461end
462
463fn trestart cut ulong to void
464wsinit
465wsrun cut
466cksave 0
467twipe
468check eq ckload 0 51752 0
469check eq get WS 0 cut
470wsrun 512
471cksave 0
472for i ulong 51752
473check eq get CB i get CB add 51752 i
474end
475end
476
477fn trefuse code int to void
478d = tdig
479check eq ckload 0 51752 code
480check eq tdig d
481end
482
483fn treseal to void
484ckput 51744 ckfnv 0 51744
485end
486
487fn tcorrupt to void
488wsinit
489wsrun 100
490cksave 0
491wsrun 140
492d = tdig
493check eq ckload 0 51751 -1
494check eq tdig d
495for k ulong 6
496pos = add 100 mul k 9000
497put CB pos uchar xor get CB pos 1
498trefuse -5
499put CB pos uchar xor get CB pos 1
500end
501put CB 0 uchar xor get CB 0 1
502trefuse -2
503put CB 0 uchar xor get CB 0 1
504ckput 8 2
505trefuse -3
506ckput 8 1
507ckput 32 600
508ckput 24 600
509treseal
510trefuse -6
511ckput 32 100
512ckput 24 100
513ckput 56 99
514treseal
515trefuse -7
516ckput 56 100
517keep = ckget 96
518ckput 96 2143289344
519treseal
520trefuse -8
521ckput 96 keep
522keep = ckget 17440
523ckput 17440 9999
524treseal
525trefuse -10
526ckput 17440 keep
527keep = ckget 18464
528ckput 18464 2199023255552
529treseal
530trefuse -9
531ckput 18464 keep
532treseal
533note Every edit undone: the original event-100 image must load again.
534check eq ckload 0 51752 0
535check eq get WS 0 100
536cksave 51752
537for i ulong 51752
538check eq get CB i get CB add 51752 i
539end
540end
541
542fn main to int
543tgolden
544tsame
545tdiffer
546tshuffle
547tlinexact
548wsinit
549wsrun 512
550tboundary
551tlineage
552theld 0
553theld 1
554wsinit
555wsrun 512
556cksave 51752
557trestart 0
558trestart 1
559trestart 37
560trestart 100
561trestart 255
562trestart 256
563trestart 257
564trestart 300
565trestart 511
566trestart 512
567tcorrupt
568w = write 1 PASS 0 len PASS
569wnum get C 0
570w = write 1 NL 0 1
571ret 0
572end