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

723 lines · 12337 bytes Raw Blame History
1note SPDX-License-Identifier: AGPL-3.0-only
2note aien-train#25 ORIG-2 tests for select.om. The golden oracle is test-only exact integer
3note arithmetic at scale 2^24 that decodes binary32 bits independently and never calls
4note add32/mul32; every intermediate must be exactly representable or the test fails.
5note Groups: tgolden (two MLP updates, H=2), trelu0, tfd (central differences, both kinds),
6note tchange, tnoupdate, tshuffle, trestart (3 cut points per kind, one mid-epoch),
7note trefuse (8 refusal codes, state unchanged), tprovenance (every SS word accounted for).
8global TC ulong 1
9global QW long 1024
10global QG long 1024
11global QZ long 24
12global QH long 64
13global QA long 64
14global QL long 8
15global QI uchar 16384
16global QM uchar 16384
17global QP ulong 1024
18global QD ulong 8
19text TPASS "SI19_SELECT_TEST_PASS checks="
20text TFAIL "SI19_SELECT_TEST_FAIL check="
21text TNL "\n"
22
23fn tck ok bool to void
24put TC 0 add get TC 0 1
25if not ok
26w = write 1 TFAIL 0 len TFAIL
27wnum get TC 0
28w = write 1 TNL 0 1
29exit 1
30end
31end
32
33note ---- independent binary32 decode/encode at scale 2^24 ----
34
35fn qdec x ulong to long
36note Exact numerator at scale 2^24 of a binary32 value (zero or normal).
37if eq and x 2147483647 0
38ret 0
39end
40e = long and shr x 23 255
41tck and gt e 0 lt e 255
42m = long or and x 8388607 8388608
43if ge e 126
44tck le sub e 126 30
45m = shl m sub e 126
46else
47k = sub 126 e
48tck le k 23
49tck eq rem m shl long 1 k 0
50m = shr m k
51end
52if ne and x 2147483648 0
53ret neg m
54end
55ret m
56end
57
58fn qbits num long to ulong
59note Exact binary32 bits of num/2^24; fails the test when not exactly representable.
60if eq num 0
61ret 0
62end
63sign = ulong 0
64if lt num 0
65sign = 2147483648
66num = neg num
67end
68m = ulong num
69sc = long 24
70while eq and m 1 0 bound 64
71m = shr m 1
72sc = sub sc 1
73end
74tck lt m 16777216
75pw = long 0
76q = m
77while gt q 1 bound 64
78q = shr q 1
79pw = add pw 1
80end
81ex = sub add pw 127 sc
82tck and gt ex 0 lt ex 255
83ret or sign or shl ulong ex 23 sub shl m ulong sub 23 pw 8388608
84end
85
86fn qchk num long to void
87x = qbits num
88end
89
90fn qmul a long b long to long
91note Product of two scale-2^24 numbers, exact at scale 2^24.
92p = mul a b
93tck eq rem p 16777216 0
94ret div p 16777216
95end
96
97note ---- hand-built configuration: one record, MLP with H = 2 ----
98
99fn qrecord to void
100note Record 0: TRAIN, core 0, pressure 0, M = N = 1, arms 0 and 1 admissible.
101for i ulong 32
102put RW i 0
103end
104put RW 0 3553143591248351811
105put RW 1 1
106put RW 5 1
107put RW 6 1
108put RW 7 1
109put RW 9 24
110put RW 10 2097152
111put RW 12 3
112put RW 13 2
113put RW 16 1000
114put RW 17 900
115put RW 24 1
116put RW 25 1
117put RC 0 1
118put RC 2 0
119end
120
121fn qw8 n long to ulong
122ret wmbits n 3
123end
124
125fn qconfig to void
126note H = 2, 705-param layout, lr 2^-4; weights multiples of 1/8 with |w| <= 1.
127qrecord
128for i ulong 32
129put SS i 0
130end
131for i ulong 1024
132put SP i 0
133put SG i 0
134end
135put SS 0 2
136put SS 1 2
137put SS 15 705
138put SS 3 wmbits 1 4
139for i ulong 20
140put SP mul i 32 qw8 sub rem mul long i 3 17 8
141put SP add mul i 32 1 qw8 sub rem mul long i 5 17 8
142end
143put SP 640 qw8 1
144put SP 641 qw8 2
145put SP 672 qw8 3
146put SP 673 qw8 -5
147put SP 704 qw8 1
148end
149
150fn qload to void
151note Oracle weights from the live bits (decoded independently).
152for i ulong 705
153put QW i qdec get SP i
154put QG i 0
155end
156end
157
158fn qinput a ulong to void
159oxfeat 0
160for j ulong 12
161put QZ j mul get XF j 1048576
162end
163for k ulong 8
164put QZ add 12 k 0
165end
166put QZ add 12 a 16777216
167end
168
169fn qhidden h ulong to long
170y = get QW add 640 h
171for i ulong 20
172y = add y qmul get QZ i get QW add mul i 32 h
173qchk y
174end
175ret y
176end
177
178fn qforward a ulong to void
179note Exact forward of the H = 2 network; QL[0] = output.
180qinput a
181for h ulong 2
182z = qhidden h
183put QH h z
184if gt z 0
185put QA h z
186else
187put QA h 0
188end
189end
190y = get QW 704
191for h ulong 2
192y = add y qmul get QA h get QW add 672 h
193qchk y
194end
195put QL 0 y
196end
197
198fn qgradh h ulong dh long to void
199k = add 640 h
200put QG k add get QG k dh
201qchk get QG k
202for i ulong 20
203k = add mul i 32 h
204put QG k add get QG k qmul dh get QZ i
205qchk get QG k
206end
207end
208
209fn qbackward g long to void
210note Exact gradient of (out - y)^2 given g = 2 (out - y); ReLU passes only when QH > 0.
211put QG 704 add get QG 704 g
212for h ulong 2
213k = add 672 h
214put QG k add get QG k qmul g get QA h
215qchk get QG k
216if gt get QH h 0
217qgradh h qmul g get QW k
218end
219end
220end
221
222fn qupdate to void
223note QW -= QG / 16 (lr 2^-4), exact.
224for i ulong 705
225d = get QG i
226tck eq rem d 16 0
227put QW i sub get QW i div d 16
228qchk get QW i
229put QG i 0
230end
231end
232
233fn qround to void
234note One update of the live code against the oracle: output, every gradient, every param.
235out = slfwd 0 1
236qforward 1
237tck eq out qbits get QL 0
238y = qbits sub get QL 0 2097152
239slback 0 1 y
240qbackward 4194304
241for k ulong 705
242tck eq get SG k qbits get QG k
243end
244slstep
245qupdate
246for k ulong 705
247tck eq get SP k qbits get QW k
248end
249for k ulong 705
250tck eq get SG k 0
251end
252end
253
254fn tgolden to void
255qconfig
256qload
257qround
258tck lt get QH 0 0
259tck gt get QH 1 0
260qround
261tck gt get QH 1 0
262end
263
264fn trelu0 to void
265note Pre-activation exactly 0: no gradient reaches W1, b1 or W2 of that unit; 2^-10 above 0 does.
266qconfig
267put SP 641 qw8 -1
268out = slfwd 0 1
269tck eq get SH 1 0
270tck eq get SA 1 0
271tck eq out qw8 1
272slback 0 1 0
273tck eq get SG 641 0
274tck eq get SG 673 0
275for i ulong 20
276tck eq get SG add mul i 32 1 0
277end
278tck ne get SG 704 0
279for i ulong 705
280put SG i 0
281end
282put SP 641 add32 qw8 -1 wmbits 1 10
283out = slfwd 0 1
284tck eq get SH 1 wmbits 1 10
285tck gt get SZ 20 0
286slback 0 1 0
287tck ne get SG 641 0
288tck ne get SG 673 0
289tck ne get SG 1 0
290end
291
292note ---- fixture data ----
293
294fn tdata to void
295n = sxgen 4242 200
296tck eq oxload n 0
297tck eq get RC 0 200
298tck eq get RC 4 40
299end
300
301note ---- central finite differences on the real model ----
302
303fn qfix x ulong to long
304note Truncated value of a binary32 at scale 2^30 (for tolerance comparisons only).
305if eq and x 2147483647 0
306ret 0
307end
308e = long and shr x 23 255
309m = long or and x 8388607 8388608
310k = sub 150 e
311v = long 0
312if le k 30
313v = shl m sub 30 k
314else
315if lt k 64
316v = shr m sub k 30
317end
318end
319if ne and x 2147483648 0
320ret neg v
321end
322ret v
323end
324
325fn qsqerr r ulong a ulong y ulong to ulong
326d = add32 slfwd r a xor y 2147483648
327ret mul32 d d
328end
329
330fn qfd r ulong a ulong y ulong p ulong to ulong
331note Central difference of the squared error in parameter p, eps = 2^-6.
332w = get SP p
333put SP p add32 w wmbits 1 6
334lp = qsqerr r a y
335put SP p add32 w wmbits -1 6
336lm = qsqerr r a y
337put SP p w
338ret mul32 add32 lp xor lm 2147483648 wmbits 32 0
339end
340
341fn qfdone r ulong a ulong y ulong p ulong to bool
342note Checks one parameter when its analytic gradient is at least 2^-6; returns checked.
343g = get SG p
344b = qfix g
345if lt wsabs b 16777216
346ret false
347end
348d = sub qfix qfd r a y p b
349tck le mul wsabs d 16 wsabs b
350ret true
351end
352
353fn qtrain1 to ulong
354for r ulong get RC 0
355if eq oxpart r 0
356ret r
357end
358end
359exit 85
360end
361
362fn qgrad r ulong a ulong y ulong to void
363out = slfwd r a
364for i ulong 1024
365put SG i 0
366end
367slback r a y
368end
369
370fn tfdaff to void
371slinit 1 19024 wmbits 1 8 0
372slnorm
373r = qtrain1
374y = sltarget r 1
375qgrad r 1 y
376n = ulong 0
377for j ulong 12
378if qfdone r 1 y add 12 j
379n = add n 1
380end
381end
382tck ge n 3
383end
384
385fn tfdmlp to void
386slinit 2 19024 wmbits 1 8 0
387slnorm
388r = qtrain1
389y = sltarget r 2
390qgrad r 2 y
391n = ulong 0
392if qfdone r 2 y 704
393n = add n 1
394end
395for h ulong 32
396if qfdone r 2 y add 672 h
397n = add n 1
398end
399if ge wsabs qfix get SH h 33554432
400if qfdone r 2 y add 640 h
401n = add n 1
402end
403if qfdone r 2 y h
404n = add n 1
405end
406end
407end
408tck ge n 6
409end
410
411fn tfd to void
412tfdaff
413tfdmlp
414end
415
416note ---- change, no-update and shuffled controls ----
417
418fn qsnap to void
419for i ulong 1024
420put QP i get SP i
421end
422end
423
424fn qdiff to ulong
425n = ulong 0
426for i ulong 1024
427if ne get QP i get SP i
428n = add n 1
429end
430end
431ret n
432end
433
434fn tchange1 kind ulong to void
435slinit kind 19024 wmbits 1 8 0
436slnorm
437qsnap
438r = qtrain1
439p0 = slfwd r 0
440p1 = slfwd r 1
441slrun 1
442tck ge get SS 6 2
443tck gt qdiff 0
444tck or ne p0 slfwd r 0 ne p1 slfwd r 1
445end
446
447fn tchange to void
448tchange1 1
449tchange1 2
450end
451
452fn tnoupdate to void
453slinit 2 19024 0 2
454slnorm
455qsnap
456slepoch
457tck eq get SS 4 1
458tck eq get SS 6 200
459tck eq qdiff 0
460for i ulong 1024
461tck eq get SB i get QP i
462end
463end
464
465fn tshuffle to void
466slinit 1 19024 wmbits 1 8 1
467slnorm
468for i ulong 16384
469put QM i 0
470end
471moved = ulong 0
472for p ulong 1600
473if slpairok div p 8 rem p 8
474q = get SX p
475tck slpairok div q 8 rem q 8
476tck eq get QM q 0
477put QM q 1
478if ne q p
479moved = add moved 1
480end
481else
482tck eq get SX p p
483end
484end
485tck gt moved 100
486r = qtrain1
487q = get SX add mul r 8 1
488put SS 16 0
489t = sltarget div q 8 rem q 8
490put SS 16 1
491tck eq sltarget r 1 t
492end
493
494note ---- restart identity and refusals ----
495
496fn qkeep n ulong to void
497for i ulong n
498put QI i get SI i
499end
500end
501
502fn qsame n ulong to void
503for i ulong n
504tck eq get SI i get QI i
505end
506end
507
508fn trestart kind ulong cut ulong part ulong maxep ulong to void
509note Uninterrupted image vs train-to-cut (+ part records), save, wipe, load, continue.
510slinit kind 19024 wmbits 1 10 0
511slnorm
512sltrain maxep 16 0
513n = slsave 0
514qkeep n
515slinit kind 19024 wmbits 1 10 0
516slnorm
517if gt cut 0
518sltrain maxep 16 cut
519end
520slrun part
521tck eq slsave 0 n
522slinit kind 777 0 2
523tck eq slload 0 n 0
524tck eq get SS 4 cut
525tck eq get SS 5 part
526sltrain maxep 16 0
527tck eq slsave 0 n
528qsame n
529end
530
531fn qdig to ulong
532h = ulong 1469598103934665603
533for i ulong 32
534h = mul xor h get SS i 1099511628211
535end
536for i ulong 1024
537h = mul xor h get SP i 1099511628211
538h = mul xor h get SB i 1099511628211
539end
540for i ulong 256
541h = mul xor h get SX i 1099511628211
542end
543ret h
544end
545
546fn qseal n ulong to void
547siput sub n 8 sifnv 0 sub n 8
548end
549
550fn qrefuse n ulong code int to void
551d = qdig
552tck eq slload 0 n code
553tck eq qdig d
554end
555
556fn trefuse to void
557slinit 1 19024 wmbits 1 12 0
558slnorm
559sltrain 2 16 0
560n = slsave 0
561d = qdig
562qrefuse sub n 1 -1
563put SI 0 uchar xor get SI 0 1
564qrefuse n -2
565put SI 0 uchar xor get SI 0 1
566siput 8 2
567qrefuse n -3
568siput 8 1
569siput 16 3
570qseal n
571qrefuse n -4
572siput 16 1
573qseal n
574for k ulong 6
575pos = add 100 mul k 300
576put SI pos uchar xor get SI pos 1
577qrefuse n -5
578put SI pos uchar xor get SI pos 1
579end
580siput 48 65
581qseal n
582qrefuse n -6
583siput 48 2
584siput 40 5
585qseal n
586qrefuse n -6
587siput 40 wmbits 1 12
588keep = siget 272
589siput 272 2143289344
590qseal n
591qrefuse n -7
592siput 272 keep
593keep = siget 104
594siput 104 xor keep 1
595qseal n
596qrefuse n -8
597note Inference admission (sladmit) takes the unbound image and reports the binding.
598tck eq sladmit 0 n 0
599tck not slbound 0
600tck eq get SS 4 2
601keep2 = siget 272
602siput 272 2143289344
603qseal n
604tck eq sladmit 0 n -7
605siput 272 keep2
606siput 104 keep
607qseal n
608tck eq slload 0 n 0
609tck eq qdig d
610tck eq get SS 4 2
611end
612
613note ---- provenance: every image word is a declared seed, counter, the data hash or derived ----
614
615fn qexpect to void
616note The expected SS vector of a fresh MLP init with seed 19024 and lr 2^-8.
617for i ulong 32
618put QP i 0
619end
620put QP 0 2
621put QP 1 32
622put QP 2 19024
623put QP 3 wmbits 1 8
624s = ulong 19024
625for k ulong 672
626s = slnext s
627end
628put QP 7 s
629put QP 8 get SS 8
630put QP 9 get SS 9
631put QP 10 get SS 10
632put QP 11 get RC 2
633put QP 13 2139095040
634put QP 15 705
635put QP 19 get SS 19
636end
637
638fn qinitw k ulong s ulong to void
639note Param k of the declared init equals the k-th LCG draw mapped to {-16..15}/128.
640tck eq get SP k wmbits sub long rem shr s 8 32 16 7
641end
642
643fn tprovenance to void
644slinit 2 19024 wmbits 1 8 0
645slnorm
646n = slsave 0
647tck eq n 11560
648qexpect
649for i ulong 32
650tck eq siget add 16 mul i 8 get QP i
651end
652tck ne get RC 2 0
653tck eq get SS 11 get RC 2
654tck eq get SS 19 slfnvp 705
655tck eq slfnvb 705 slfnvp 705
656s = ulong 19024
657for k ulong 640
658s = slnext s
659qinitw k s
660end
661for h ulong 32
662s = slnext s
663qinitw add 672 h s
664end
665tck eq get SP 704 0
666for h ulong 32
667tck eq get SP add 640 h 0
668end
669tck eq get SS 7 s
670end
671
672fn tv2 to void
673note v2 admission (ORIG1-CONTRACT-v2.md): training pairs come from the TRAIN split only,
674note ntrain is the TRAIN split's admitted count; the image's SS[20] (v2 flag) is range checked.
675n = sxgen 4242 200
676tck eq oxadm2 n 0
677tck gt get RC 4 0
678tck gt get RC 6 0
679slinit 2 19024 wmbits 1 8 0
680slnorm
681tck eq get SS 10 get RC 4
682k = ulong 0
683for r ulong 200
684for a ulong 8
685if slpairok r a
686tck eq oxpart r 0
687k = add k 1
688end
689end
690end
691tck gt k 0
692put SS 20 1
693sltrain 1 16 0
694m = slsave 0
695tck eq sladmit 0 m 0
696tck eq get SS 20 1
697siput 176 2
698qseal m
699tck eq sladmit 0 m -6
700end
701
702fn main to int
703tgolden
704trelu0
705tdata
706tfd
707tchange
708tnoupdate
709tshuffle
710trestart 2 1 0 5
711trestart 2 2 3 5
712trestart 2 4 0 5
713trestart 1 0 2 6
714trestart 1 2 0 6
715trestart 1 5 0 6
716trefuse
717tprovenance
718tv2
719w = write 1 TPASS 0 len TPASS
720wnum get TC 0
721w = write 1 TNL 0 1
722ret 0
723end