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 / frozen / unit.om

809 lines · 13544 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
373if or ne get ED 2 rank ne get ED 8 rows
374ret -21
375end
376if ne get ED 16 cols
377ret -21
378end
379if eq rank 2
380if or ne get ED 9 cols ne get ED 17 1
381ret -21
382end
383end
384end
385ret 0
386end
387
388fn afstep lr ulong to int
389status = afvalidate
390if ne status 0
391ret status
392end
393if not affinite lr
394ret -22
395end
396if ne and lr 2147483648 0
397ret -22
398end
399for t ulong 4
400for i ulong afcount t
401if not affinite afget t i
402ret -22
403end
404end
405end
406for i ulong 128
407put AQ i 0
408end
409loss = ulong 0
410for row ulong 2
411for col ulong 2
412v = afget 2 col
413for k ulong 3
414x = afget 0 add mul row 3 k
415w = afget 1 add mul k 2 col
416v = add32 v mul32 x w
417end
418pos = add mul row 2 col
419afput 4 pos v
420r = add32 v xor afget 3 pos 2147483648
421loss = add32 loss mul32 r r
422g = mul32 1073741824 r
423afput 7 col add32 afq 7 col g
424for k ulong 3
425xp = add mul row 3 k
426wp = add mul k 2 col
427gx = mul32 g afget 1 wp
428gw = mul32 g afget 0 xp
429afput 5 xp add32 afq 5 xp gx
430afput 6 wp add32 afq 6 wp gw
431end
432end
433end
434note Commit only after all finite-result checks; rejected steps preserve AP and AL.
435for i ulong 6
436delta = mul32 lr afq 6 i
437afput 1 i add32 afget 1 i xor delta 2147483648
438end
439for i ulong 2
440delta = mul32 lr afq 7 i
441afput 2 i add32 afget 2 i xor delta 2147483648
442end
443if not affinite loss
444ret -23
445end
446for t ulong 8
447if and ne t 0 ne t 3
448for i ulong afcount t
449if not affinite afq t i
450ret -23
451end
452end
453end
454end
455for t ulong 8
456if and ne t 0 ne t 3
457for i ulong afcount t
458put AP add mul t 16 i afq t i
459end
460end
461end
462put AL 0 loss
463ret 0
464end
465note SPDX-License-Identifier: AGPL-3.0-only
466note Independent exact rational oracle: X/8,W/16,b/128,T/128,learning rate1/32.
467note Only the test oracle uses integer rationals. Production calls IEEE add32/mul32.
468global C ulong 1
469global D uchar 24
470global RI long 18
471global RR long 4
472global SAV ulong 129
473global RNG ulong 1
474text PASS "NATIVE_AFFINE_FP32_PASS checks="
475text FAIL "NATIVE_AFFINE_FP32_FAIL check="
476text NL "\n"
477
478fn number n ulong to void
479if eq n 0
480put D 0 48
481w = write 1 D 0 1
482if ne w 1
483exit 90
484end
485ret
486end
487p = ulong 24
488while gt n 0 bound 24
489p = sub p 1
490put D p uchar add 48 rem n 10
491n = div n 10
492end
493w = write 1 D p sub 24 p
494if ne w long sub 24 p
495exit 90
496end
497end
498
499fn check ok bool to void
500put C 0 add get C 0 1
501if not ok
502w = write 1 FAIL 0 len FAIL
503number get C 0
504w = write 1 NL 0 1
505exit 1
506end
507end
508
509fn bits value long scale ulong to ulong
510note Exact binary32 encoding of small dyadic test numbers; no production primitive.
511if eq value 0
512ret 0
513end
514sign = ulong 0
515if lt value 0
516sign = 2147483648
517value = neg value
518end
519n = ulong value
520power = ulong 0
521q = n
522while gt q 1 bound 24
523q = shr q 1
524power = add power 1
525end
526check le power 23
527mantissa = sub shl n sub 23 power 8388608
528exponent = sub add power 127 scale
529ret or sign or shl exponent 23 mantissa
530end
531
532fn fixture to void
533for i ulong 192
534put AD i 0
535end
536for i ulong 64
537put AS i 0
538end
539for i ulong 128
540put AP i 0
541end
542put AL 0 0
543for t ulong 8
544rank = ulong 2
545rows = ulong 2
546cols = ulong 3
547count = ulong 6
548if or eq t 1 eq t 6
549rows = 3
550cols = 2
551end
552if or eq t 3 eq t 4
553cols = 2
554count = 4
555end
556if or eq t 2 eq t 7
557rank = 1
558cols = 1
559count = 2
560end
561p = mul t 24
562put AD p 1
563put AD add p 1 1
564put AD add p 2 rank
565put AD add p 3 count
566put AD add p 5 add t 1
567put AD add p 6 17
568put AD add p 8 rows
569put AD add p 16 cols
570if eq rank 2
571put AD add p 9 cols
572put AD add p 17 1
573end
574p = mul t 8
575put AS p 1
576put AS add p 2 add t 1
577put AS add p 3 17
578put AS add p 4 1
579put AS add p 5 count
580end
581end
582
583fn save to void
584for i ulong 128
585put SAV i get AP i
586end
587put SAV 128 get AL 0
588end
589
590fn unchanged to void
591for i ulong 128
592check eq get SAV i get AP i
593end
594check eq get SAV 128 get AL 0
595end
596
597fn loadinputs to void
598for i ulong 6
599put AP i bits get RI i 3
600put AP add 16 i bits get RI add 6 i 4
601end
602for i ulong 2
603put AP add 32 i bits get RI add 12 i 7
604end
605for i ulong 4
606put AP add 48 i bits get RI add 14 i 7
607end
608end
609
610fn oracle to void
611loss = long 0
612for row ulong 2
613for col ulong 2
614pos = add mul row 2 col
615y = get RI add 12 col
616for k ulong 3
617x = get RI add mul row 3 k
618w = get RI add 6 add mul k 2 col
619y = add y mul x w
620end
621check eq afget 4 pos bits y 7
622r = sub y get RI add 14 pos
623put RR pos r
624loss = add loss mul r r
625end
626end
627check eq get AL 0 bits loss 14
628for k ulong 3
629for col ulong 2
630g = long 0
631for row ulong 2
632r = get RR add mul row 2 col
633x = get RI add mul row 3 k
634g = add g mul r x
635end
636pos = add mul k 2 col
637check eq afget 6 pos bits g 9
638updated = sub mul get RI add 6 pos 1024 g
639check eq afget 1 pos bits updated 14
640end
641end
642for col ulong 2
643g = add get RR col get RR add 2 col
644check eq afget 7 col bits g 6
645updated = sub mul get RI add 12 col 16 g
646check eq afget 2 col bits updated 11
647end
648for row ulong 2
649for k ulong 3
650g = long 0
651for col ulong 2
652r = get RR add mul row 2 col
653w = get RI add 6 add mul k 2 col
654g = add g mul r w
655end
656pos = add mul row 3 k
657check eq afget 5 pos bits g 10
658end
659end
660note Inputs and targets remain byte-identical after a successful step.
661for i ulong 6
662check eq afget 0 i bits get RI i 3
663end
664for i ulong 4
665check eq afget 3 i bits get RI add 14 i 7
666end
667end
668
669fn direct to void
670fixture
671check eq afvalidate 0
672note X rows(1,-2,3),(2,0,-1); W(.5,-.25),(1,.75),(-.5,2).
673put RI 0 8
674put RI 1 -16
675put RI 2 24
676put RI 3 16
677put RI 4 0
678put RI 5 -8
679put RI 6 8
680put RI 7 -4
681put RI 8 16
682put RI 9 12
683put RI 10 -8
684put RI 11 32
685put RI 12 16
686put RI 13 -64
687put RI 14 32
688put RI 15 128
689put RI 16 -128
690put RI 17 64
691loadinputs
692check eq afstep 1023410176 0
693oracle
694note Independently hand-calculated loss36.46875, not merely decreasing loss.
695check eq get AL 0 1108467712
696end
697
698fn refusals to void
699fixture
700put AD 32 2
701put AD 33 3
702put AD 40 3
703save
704check eq afstep 1023410176 -21
705unchanged
706fixture
707put AS 11 18
708save
709check eq afstep 1023410176 -5
710unchanged
711fixture
712put AD 29 1
713put AS 10 1
714save
715check eq afstep 1023410176 -20
716unchanged
717fixture
718put AP 0 2139095040
719save
720check eq afstep 1023410176 -22
721unchanged
722fixture
723put AP 0 2143289344
724save
725check eq afstep 1023410176 -22
726unchanged
727fixture
728put AP 0 4294967296
729save
730check eq afstep 1023410176 -22
731unchanged
732fixture
733save
734check eq afstep 3170893824 -22
735unchanged
736fixture
737put AP 0 2139095039
738put AP 16 1073741824
739save
740check eq afstep 1023410176 -23
741unchanged
742end
743
744fn next to long
745n = add mul get RNG 0 1664525 1013904223
746n = and n 4294967295
747put RNG 0 n
748ret sub long rem shr n 12 17 8
749end
750
751fn rounding to void
752note Smallest subnormal through actual forward and input derivative, loss underflows.
753fixture
754put AP 0 1
755put AP 16 1065353216
756check eq afstep 0 0
757check eq afget 4 0 1
758check eq afget 5 0 2
759check eq afget 6 0 0
760check eq afget 7 0 2
761check eq get AL 0 0
762note Half a subnormal rounds to even zero.
763fixture
764put AP 0 1
765put AP 16 1056964608
766check eq afstep 0 0
767check eq afget 4 0 0
768note 1 + 2^-24 rounds to even1; 1 + 3*2^-24 rounds upward two ulps.
769fixture
770put AP 0 1065353216
771put AP 16 1065353216
772put AP 32 864026624
773check eq afstep 0 0
774check eq afget 4 0 1065353216
775check eq afget 1 0 1065353216
776fixture
777put AP 0 1065353216
778put AP 16 1065353216
779put AP 32 876609536
780check eq afstep 0 0
781check eq afget 4 0 1065353218
782end
783
784fn corpus to void
785put RNG 0 303660
786for trial ulong 4096
787fixture
788for i ulong 18
789put RI i next
790end
791loadinputs
792check eq afstep 1023410176 0
793oracle
794end
795end
796
797fn main to int
798direct
799refusals
800rounding
801corpus
802w = write 1 PASS 0 len PASS
803number get C 0
804w = write 1 NL 0 1
805if ne w 1
806ret 90
807end
808ret 0
809end