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 / evidence / ECOSYSTEM6 / independent-review / mutant1-unit.om

799 lines · 13441 bytes Raw Blame History
1note SPDX-License-Identifier: AGPL-3.0-only
2note Native IEEE binary32 addition over bit patterns, RNE and gradual underflow.
3note Canonical positive quiet NaN; no foreign floating runtime or compiler f32 type.
4fn ajam x ulong n ulong to ulong
5if eq n 0
6ret x
7end
8if ge n 64
9if ne x 0
10ret 1
11end
12ret 0
13end
14q = shr x n
15mask = sub shl 1 n 1
16if ne and x mask 0
17q = or q 1
18end
19ret q
20end
21fn add32 aa ulong bb ulong to ulong
22a = and aa 4294967295
23b = and bb 4294967295
24if or gt and a 2147483647 2139095040 gt and b 2147483647 2139095040
25ret 2143289344
26end
27if lt and a 2147483647 and b 2147483647
28t = a
29a = b
30b = t
31end
32if eq and a 2147483647 2139095040
33if and eq and b 2147483647 2139095040 ne and xor a b 2147483648 0
34ret 2143289344
35end
36ret a
37end
38if eq and b 2147483647 0
39if eq and a 2147483647 0
40ret and and a b 2147483648
41end
42ret a
43end
44sign = and a 2147483648
45ea = and shr a 23 255
46eb = and shr b 23 255
47ma = and a 8388607
48mb = and b 8388607
49if eq ea 0
50ea = 1
51else
52ma = or ma 8388608
53end
54if eq eb 0
55eb = 1
56else
57mb = or mb 8388608
58end
59ma = shl ma 3
60mb = shl mb 3
61mb = ajam mb sub ea eb
62if eq and xor a b 2147483648 0
63ma = add ma mb
64if ge ma 134217728
65ma = ajam ma 1
66ea = add ea 1
67end
68else
69ma = sub ma mb
70if eq ma 0
71ret 0
72end
73while and lt ma 67108864 gt ea 1
74ma = shl ma 1
75ea = sub ea 1
76end
77end
78q = shr ma 3
79r = and ma 7
80if gt r 4
81q = add q 1
82else
83if eq r 4
84if ne and q 1 0
85q = add q 1
86end
87end
88end
89if ge q 16777216
90q = shr q 1
91ea = add ea 1
92end
93if ge ea 255
94ret or sign 2139095040
95end
96if lt q 8388608
97ea = 0
98end
99q = and q 8388607
100ea = shl ea 23
101q = or q ea
102ret or sign q
103end
104note SPDX-License-Identifier: AGPL-3.0-only
105note Native IEEE binary32 multiplication represented as bits; no host floating runtime.
106note Round-to-nearest ties-to-even, gradual underflow, signed zeros and infinities.
107note Canonical positive quiet NaN for every NaN result. Inputs are low32 bits.
108fn mround x ulong shift ulong to ulong
109if eq shift 0
110ret x
111end
112if gt shift 63
113ret 0
114end
115q = shr x shift
116mask = sub shl 1 shift 1
117r = and x mask
118half = shl 1 sub shift 1
119if or gt r half and eq r half ne and q 1 0
120q = add q 1
121end
122ret q
123end
124fn mul32 aa ulong bb ulong to ulong
125a = and aa 4294967295
126b = and bb 4294967295
127sign = and xor a b 2147483648
128ea = long and shr a 23 255
129eb = long and shr b 23 255
130ma = and a 8388607
131mb = and b 8388607
132if or and eq ea 255 ne ma 0 and eq eb 255 ne mb 0
133ret 2143289344
134end
135if or eq ea 255 eq eb 255
136if or eq and a 2147483647 0 eq and b 2147483647 0
137ret 2143289344
138end
139ret or sign 2139095040
140end
141if or eq and a 2147483647 0 eq and b 2147483647 0
142ret sign
143end
144if eq ea 0
145ea = 1
146while lt ma 8388608
147ma = shl ma 1
148ea = sub ea 1
149end
150else
151ma = or ma 8388608
152end
153if eq eb 0
154eb = 1
155while lt mb 8388608
156mb = shl mb 1
157eb = sub eb 1
158end
159else
160mb = or mb 8388608
161end
162product = mul ma mb
163e = sub add ea eb 127
164shift = long 23
165if ge product 140737488355328
166shift = 24
167e = add e 1
168end
169if lt e 1
170shift = add shift sub 1 e
171e = 0
172end
173q = mround product ulong shift
174if eq e 0
175if ge q 8388608
176e = 1
177end
178else
179if ge q 16777216
180q = shr q 1
181e = add e 1
182end
183end
184if ge e 255
185ret or sign 2139095040
186end
187q = and q 8388607
188e = shl e 23
189q = or q ulong e
190ret or sign q
191end
192note M20 metadata-v1. Integer metadata only; no allocator or numeric execution.
193note ED: schema,dtype,rank,elements,offset,slot,generation,reserved,shape8,stride8.
194note ES: live,retired,slot,generation,dtype,elements,reserved,reserved.
195note ES is the caller-owned allocator snapshot. It is not untrusted wire input.
196global ED ulong 24
197global ES ulong 8
198
199fn emshape to int
200rank = get ED 2
201if gt rank 8
202ret -2
203end
204n = ulong 1
205for d ulong rank
206size = get ED add 8 d
207if eq size 0
208ret -3
209end
210if gt size div 1073741824 n
211ret -8
212end
213n = mul n size
214end
215if ne get ED 3 n
216ret -3
217end
218ret 0
219end
220
221fn emlive slot ulong gen ulong to int
222if gt slot 4294967295
223ret -5
224end
225if or ne get ES 0 1 ne get ES 1 0
226ret -5
227end
228if or eq gen 0 ne slot get ES 2
229ret -5
230end
231if ne gen get ES 3
232ret -5
233end
234ret 0
235end
236
237fn embounds to int
238size = get ES 5
239offset = get ED 4
240if or eq size 0 gt size 1073741824
241ret -8
242end
243if ge offset size
244ret -6
245end
246note Compare against remaining extent before multiplication, never overflow.
247room = sub sub size 1 offset
248for d ulong get ED 2
249count = sub get ED add 8 d 1
250stride = get ED add 16 d
251if ne stride 0
252if gt count div room stride
253ret -6
254end
255room = sub room mul count stride
256end
257end
258ret 0
259end
260
261fn emcheck to int
262if or ne get ED 0 1 ne get ED 7 0
263ret -1
264end
265if or ne get ES 6 0 ne get ES 7 0
266ret -1
267end
268dtype = get ED 1
269if or lt dtype 1 gt dtype 3
270ret -4
271end
272status = emshape
273if ne status 0
274ret status
275end
276status = emlive get ED 5 get ED 6
277if ne status 0
278ret status
279end
280if ne dtype get ES 4
281ret -4
282end
283ret embounds
284end
285
286fn emrelease slot ulong gen ulong to int
287status = emlive slot gen
288if ne status 0
289ret status
290end
291note A maximal generation is retired, never wrapped into a valid old handle.
292if eq gen 18446744073709551615
293put ES 1 1
294else
295put ES 3 add gen 1
296end
297put ES 0 0
298ret 0
299end
300note SPDX-License-Identifier: AGPL-3.0-only
301note Bounded host FP32 consumer. Uses external pinned L720 add32/mul32 and M20 emcheck.
302note Eight independent tensors X,W,b,T,Y,dX,dW,db in 16-cell slots.
303note Values are IEEE binary32 bits in ulong carriers, not integer fixed-point values.
304note AD/AS are trusted local descriptor and allocator snapshots, not wire records.
305global AD ulong 192
306global AS ulong 64
307global AP ulong 128
308global AQ ulong 128
309global AL ulong 1
310
311fn afcount t ulong to ulong
312if or eq t 2 eq t 7
313ret 2
314end
315if or eq t 3 eq t 4
316ret 4
317end
318ret 6
319end
320
321fn afget t ulong i ulong to ulong
322ret get AP add mul t 16 i
323end
324
325fn afq t ulong i ulong to ulong
326ret get AQ add mul t 16 i
327end
328
329fn afput t ulong i ulong v ulong to void
330put AQ add mul t 16 i v
331end
332
333fn affinite x ulong to bool
334if gt x 4294967295
335ret false
336end
337ret lt and x 2147483647 2139095040
338end
339
340fn afvalidate to int
341for t ulong 8
342for i ulong 24
343put ED i get AD add mul t 24 i
344end
345for i ulong 8
346put ES i get AS add mul t 8 i
347end
348status = emcheck
349if ne status 0
350ret status
351end
352note Contiguous owned local carriers only. This does not claim strided numeric kernels.
353if or ne get ED 1 1 ne get ED 4 0
354ret -20
355end
356if or ne get ED 5 add t 1 ne get ES 5 afcount t
357ret -20
358end
359rank = ulong 2
360rows = ulong 2
361cols = ulong 3
362if or eq t 1 eq t 6
363rows = 3
364cols = 2
365end
366if or eq t 3 eq t 4
367cols = 2
368end
369if or eq t 2 eq t 7
370rank = 1
371cols = 1
372end
373note MUTANT omits the dimension admission checks
374end
375ret 0
376end
377
378fn afstep lr ulong to int
379status = afvalidate
380if ne status 0
381ret status
382end
383if not affinite lr
384ret -22
385end
386if ne and lr 2147483648 0
387ret -22
388end
389for t ulong 4
390for i ulong afcount t
391if not affinite afget t i
392ret -22
393end
394end
395end
396for i ulong 128
397put AQ i 0
398end
399loss = ulong 0
400for row ulong 2
401for col ulong 2
402v = afget 2 col
403for k ulong 3
404x = afget 0 add mul row 3 k
405w = afget 1 add mul k 2 col
406v = add32 v mul32 x w
407end
408pos = add mul row 2 col
409afput 4 pos v
410r = add32 v xor afget 3 pos 2147483648
411loss = add32 loss mul32 r r
412g = mul32 1073741824 r
413afput 7 col add32 afq 7 col g
414for k ulong 3
415xp = add mul row 3 k
416wp = add mul k 2 col
417gx = mul32 g afget 1 wp
418gw = mul32 g afget 0 xp
419afput 5 xp add32 afq 5 xp gx
420afput 6 wp add32 afq 6 wp gw
421end
422end
423end
424note Commit only after all finite-result checks; rejected steps preserve AP and AL.
425for i ulong 6
426delta = mul32 lr afq 6 i
427afput 1 i add32 afget 1 i xor delta 2147483648
428end
429for i ulong 2
430delta = mul32 lr afq 7 i
431afput 2 i add32 afget 2 i xor delta 2147483648
432end
433if not affinite loss
434ret -23
435end
436for t ulong 8
437if and ne t 0 ne t 3
438for i ulong afcount t
439if not affinite afq t i
440ret -23
441end
442end
443end
444end
445for t ulong 8
446if and ne t 0 ne t 3
447for i ulong afcount t
448put AP add mul t 16 i afq t i
449end
450end
451end
452put AL 0 loss
453ret 0
454end
455note SPDX-License-Identifier: AGPL-3.0-only
456note Independent exact rational oracle: X/8,W/16,b/128,T/128,learning rate1/32.
457note Only the test oracle uses integer rationals. Production calls IEEE add32/mul32.
458global C ulong 1
459global D uchar 24
460global RI long 18
461global RR long 4
462global SAV ulong 129
463global RNG ulong 1
464text PASS "NATIVE_AFFINE_FP32_PASS checks="
465text FAIL "NATIVE_AFFINE_FP32_FAIL check="
466text NL "\n"
467
468fn number n ulong to void
469if eq n 0
470put D 0 48
471w = write 1 D 0 1
472if ne w 1
473exit 90
474end
475ret
476end
477p = ulong 24
478while gt n 0 bound 24
479p = sub p 1
480put D p uchar add 48 rem n 10
481n = div n 10
482end
483w = write 1 D p sub 24 p
484if ne w long sub 24 p
485exit 90
486end
487end
488
489fn check ok bool to void
490put C 0 add get C 0 1
491if not ok
492w = write 1 FAIL 0 len FAIL
493number get C 0
494w = write 1 NL 0 1
495exit 1
496end
497end
498
499fn bits value long scale ulong to ulong
500note Exact binary32 encoding of small dyadic test numbers; no production primitive.
501if eq value 0
502ret 0
503end
504sign = ulong 0
505if lt value 0
506sign = 2147483648
507value = neg value
508end
509n = ulong value
510power = ulong 0
511q = n
512while gt q 1 bound 24
513q = shr q 1
514power = add power 1
515end
516check le power 23
517mantissa = sub shl n sub 23 power 8388608
518exponent = sub add power 127 scale
519ret or sign or shl exponent 23 mantissa
520end
521
522fn fixture to void
523for i ulong 192
524put AD i 0
525end
526for i ulong 64
527put AS i 0
528end
529for i ulong 128
530put AP i 0
531end
532put AL 0 0
533for t ulong 8
534rank = ulong 2
535rows = ulong 2
536cols = ulong 3
537count = ulong 6
538if or eq t 1 eq t 6
539rows = 3
540cols = 2
541end
542if or eq t 3 eq t 4
543cols = 2
544count = 4
545end
546if or eq t 2 eq t 7
547rank = 1
548cols = 1
549count = 2
550end
551p = mul t 24
552put AD p 1
553put AD add p 1 1
554put AD add p 2 rank
555put AD add p 3 count
556put AD add p 5 add t 1
557put AD add p 6 17
558put AD add p 8 rows
559put AD add p 16 cols
560if eq rank 2
561put AD add p 9 cols
562put AD add p 17 1
563end
564p = mul t 8
565put AS p 1
566put AS add p 2 add t 1
567put AS add p 3 17
568put AS add p 4 1
569put AS add p 5 count
570end
571end
572
573fn save to void
574for i ulong 128
575put SAV i get AP i
576end
577put SAV 128 get AL 0
578end
579
580fn unchanged to void
581for i ulong 128
582check eq get SAV i get AP i
583end
584check eq get SAV 128 get AL 0
585end
586
587fn loadinputs to void
588for i ulong 6
589put AP i bits get RI i 3
590put AP add 16 i bits get RI add 6 i 4
591end
592for i ulong 2
593put AP add 32 i bits get RI add 12 i 7
594end
595for i ulong 4
596put AP add 48 i bits get RI add 14 i 7
597end
598end
599
600fn oracle to void
601loss = long 0
602for row ulong 2
603for col ulong 2
604pos = add mul row 2 col
605y = get RI add 12 col
606for k ulong 3
607x = get RI add mul row 3 k
608w = get RI add 6 add mul k 2 col
609y = add y mul x w
610end
611check eq afget 4 pos bits y 7
612r = sub y get RI add 14 pos
613put RR pos r
614loss = add loss mul r r
615end
616end
617check eq get AL 0 bits loss 14
618for k ulong 3
619for col ulong 2
620g = long 0
621for row ulong 2
622r = get RR add mul row 2 col
623x = get RI add mul row 3 k
624g = add g mul r x
625end
626pos = add mul k 2 col
627check eq afget 6 pos bits g 9
628updated = sub mul get RI add 6 pos 1024 g
629check eq afget 1 pos bits updated 14
630end
631end
632for col ulong 2
633g = add get RR col get RR add 2 col
634check eq afget 7 col bits g 6
635updated = sub mul get RI add 12 col 16 g
636check eq afget 2 col bits updated 11
637end
638for row ulong 2
639for k ulong 3
640g = long 0
641for col ulong 2
642r = get RR add mul row 2 col
643w = get RI add 6 add mul k 2 col
644g = add g mul r w
645end
646pos = add mul row 3 k
647check eq afget 5 pos bits g 10
648end
649end
650note Inputs and targets remain byte-identical after a successful step.
651for i ulong 6
652check eq afget 0 i bits get RI i 3
653end
654for i ulong 4
655check eq afget 3 i bits get RI add 14 i 7
656end
657end
658
659fn direct to void
660fixture
661check eq afvalidate 0
662note X rows(1,-2,3),(2,0,-1); W(.5,-.25),(1,.75),(-.5,2).
663put RI 0 8
664put RI 1 -16
665put RI 2 24
666put RI 3 16
667put RI 4 0
668put RI 5 -8
669put RI 6 8
670put RI 7 -4
671put RI 8 16
672put RI 9 12
673put RI 10 -8
674put RI 11 32
675put RI 12 16
676put RI 13 -64
677put RI 14 32
678put RI 15 128
679put RI 16 -128
680put RI 17 64
681loadinputs
682check eq afstep 1023410176 0
683oracle
684note Independently hand-calculated loss36.46875, not merely decreasing loss.
685check eq get AL 0 1108467712
686end
687
688fn refusals to void
689fixture
690put AD 32 2
691put AD 33 3
692put AD 40 3
693save
694check eq afstep 1023410176 -21
695unchanged
696fixture
697put AS 11 18
698save
699check eq afstep 1023410176 -5
700unchanged
701fixture
702put AD 29 1
703put AS 10 1
704save
705check eq afstep 1023410176 -20
706unchanged
707fixture
708put AP 0 2139095040
709save
710check eq afstep 1023410176 -22
711unchanged
712fixture
713put AP 0 2143289344
714save
715check eq afstep 1023410176 -22
716unchanged
717fixture
718put AP 0 4294967296
719save
720check eq afstep 1023410176 -22
721unchanged
722fixture
723save
724check eq afstep 3170893824 -22
725unchanged
726fixture
727put AP 0 2139095039
728put AP 16 1073741824
729save
730check eq afstep 1023410176 -23
731unchanged
732end
733
734fn next to long
735n = add mul get RNG 0 1664525 1013904223
736n = and n 4294967295
737put RNG 0 n
738ret sub long rem shr n 12 17 8
739end
740
741fn rounding to void
742note Smallest subnormal through actual forward and input derivative, loss underflows.
743fixture
744put AP 0 1
745put AP 16 1065353216
746check eq afstep 0 0
747check eq afget 4 0 1
748check eq afget 5 0 2
749check eq afget 6 0 0
750check eq afget 7 0 2
751check eq get AL 0 0
752note Half a subnormal rounds to even zero.
753fixture
754put AP 0 1
755put AP 16 1056964608
756check eq afstep 0 0
757check eq afget 4 0 0
758note 1 + 2^-24 rounds to even1; 1 + 3*2^-24 rounds upward two ulps.
759fixture
760put AP 0 1065353216
761put AP 16 1065353216
762put AP 32 864026624
763check eq afstep 0 0
764check eq afget 4 0 1065353216
765check eq afget 1 0 1065353216
766fixture
767put AP 0 1065353216
768put AP 16 1065353216
769put AP 32 876609536
770check eq afstep 0 0
771check eq afget 4 0 1065353218
772end
773
774fn corpus to void
775put RNG 0 303660
776for trial ulong 4096
777fixture
778for i ulong 18
779put RI i next
780end
781loadinputs
782check eq afstep 1023410176 0
783oracle
784end
785end
786
787fn main to int
788direct
789refusals
790rounding
791corpus
792w = write 1 PASS 0 len PASS
793number get C 0
794w = write 1 NL 0 1
795if ne w 1
796ret 90
797end
798ret 0
799end