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

345 lines · 5775 bytes Raw Blame History
1note SPDX-License-Identifier: AGPL-3.0-only
2note Independent exact rational oracle: X/8,W/16,b/128,T/128,learning rate1/32.
3note Only the test oracle uses integer rationals. Production calls IEEE add32/mul32.
4global C ulong 1
5global D uchar 24
6global RI long 18
7global RR long 4
8global SAV ulong 129
9global RNG ulong 1
10text PASS "NATIVE_AFFINE_FP32_PASS checks="
11text FAIL "NATIVE_AFFINE_FP32_FAIL check="
12text NL "\n"
13
14fn number n ulong to void
15if eq n 0
16put D 0 48
17w = write 1 D 0 1
18if ne w 1
19exit 90
20end
21ret
22end
23p = ulong 24
24while gt n 0 bound 24
25p = sub p 1
26put D p uchar add 48 rem n 10
27n = div n 10
28end
29w = write 1 D p sub 24 p
30if ne w long sub 24 p
31exit 90
32end
33end
34
35fn check ok bool to void
36put C 0 add get C 0 1
37if not ok
38w = write 1 FAIL 0 len FAIL
39number get C 0
40w = write 1 NL 0 1
41exit 1
42end
43end
44
45fn bits value long scale ulong to ulong
46note Exact binary32 encoding of small dyadic test numbers; no production primitive.
47if eq value 0
48ret 0
49end
50sign = ulong 0
51if lt value 0
52sign = 2147483648
53value = neg value
54end
55n = ulong value
56power = ulong 0
57q = n
58while gt q 1 bound 24
59q = shr q 1
60power = add power 1
61end
62check le power 23
63mantissa = sub shl n sub 23 power 8388608
64exponent = sub add power 127 scale
65ret or sign or shl exponent 23 mantissa
66end
67
68fn fixture to void
69for i ulong 192
70put AD i 0
71end
72for i ulong 64
73put AS i 0
74end
75for i ulong 128
76put AP i 0
77end
78put AL 0 0
79for t ulong 8
80rank = ulong 2
81rows = ulong 2
82cols = ulong 3
83count = ulong 6
84if or eq t 1 eq t 6
85rows = 3
86cols = 2
87end
88if or eq t 3 eq t 4
89cols = 2
90count = 4
91end
92if or eq t 2 eq t 7
93rank = 1
94cols = 1
95count = 2
96end
97p = mul t 24
98put AD p 1
99put AD add p 1 1
100put AD add p 2 rank
101put AD add p 3 count
102put AD add p 5 add t 1
103put AD add p 6 17
104put AD add p 8 rows
105put AD add p 16 cols
106if eq rank 2
107put AD add p 9 cols
108put AD add p 17 1
109end
110p = mul t 8
111put AS p 1
112put AS add p 2 add t 1
113put AS add p 3 17
114put AS add p 4 1
115put AS add p 5 count
116end
117end
118
119fn save to void
120for i ulong 128
121put SAV i get AP i
122end
123put SAV 128 get AL 0
124end
125
126fn unchanged to void
127for i ulong 128
128check eq get SAV i get AP i
129end
130check eq get SAV 128 get AL 0
131end
132
133fn loadinputs to void
134for i ulong 6
135put AP i bits get RI i 3
136put AP add 16 i bits get RI add 6 i 4
137end
138for i ulong 2
139put AP add 32 i bits get RI add 12 i 7
140end
141for i ulong 4
142put AP add 48 i bits get RI add 14 i 7
143end
144end
145
146fn oracle to void
147loss = long 0
148for row ulong 2
149for col ulong 2
150pos = add mul row 2 col
151y = get RI add 12 col
152for k ulong 3
153x = get RI add mul row 3 k
154w = get RI add 6 add mul k 2 col
155y = add y mul x w
156end
157check eq afget 4 pos bits y 7
158r = sub y get RI add 14 pos
159put RR pos r
160loss = add loss mul r r
161end
162end
163check eq get AL 0 bits loss 14
164for k ulong 3
165for col ulong 2
166g = long 0
167for row ulong 2
168r = get RR add mul row 2 col
169x = get RI add mul row 3 k
170g = add g mul r x
171end
172pos = add mul k 2 col
173check eq afget 6 pos bits g 9
174updated = sub mul get RI add 6 pos 1024 g
175check eq afget 1 pos bits updated 14
176end
177end
178for col ulong 2
179g = add get RR col get RR add 2 col
180check eq afget 7 col bits g 6
181updated = sub mul get RI add 12 col 16 g
182check eq afget 2 col bits updated 11
183end
184for row ulong 2
185for k ulong 3
186g = long 0
187for col ulong 2
188r = get RR add mul row 2 col
189w = get RI add 6 add mul k 2 col
190g = add g mul r w
191end
192pos = add mul row 3 k
193check eq afget 5 pos bits g 10
194end
195end
196note Inputs and targets remain byte-identical after a successful step.
197for i ulong 6
198check eq afget 0 i bits get RI i 3
199end
200for i ulong 4
201check eq afget 3 i bits get RI add 14 i 7
202end
203end
204
205fn direct to void
206fixture
207check eq afvalidate 0
208note X rows(1,-2,3),(2,0,-1); W(.5,-.25),(1,.75),(-.5,2).
209put RI 0 8
210put RI 1 -16
211put RI 2 24
212put RI 3 16
213put RI 4 0
214put RI 5 -8
215put RI 6 8
216put RI 7 -4
217put RI 8 16
218put RI 9 12
219put RI 10 -8
220put RI 11 32
221put RI 12 16
222put RI 13 -64
223put RI 14 32
224put RI 15 128
225put RI 16 -128
226put RI 17 64
227loadinputs
228check eq afstep 1023410176 0
229oracle
230note Independently hand-calculated loss36.46875, not merely decreasing loss.
231check eq get AL 0 1108467712
232end
233
234fn refusals to void
235fixture
236put AD 32 2
237put AD 33 3
238put AD 40 3
239save
240check eq afstep 1023410176 -21
241unchanged
242fixture
243put AS 11 18
244save
245check eq afstep 1023410176 -5
246unchanged
247fixture
248put AD 29 1
249put AS 10 1
250save
251check eq afstep 1023410176 -20
252unchanged
253fixture
254put AP 0 2139095040
255save
256check eq afstep 1023410176 -22
257unchanged
258fixture
259put AP 0 2143289344
260save
261check eq afstep 1023410176 -22
262unchanged
263fixture
264put AP 0 4294967296
265save
266check eq afstep 1023410176 -22
267unchanged
268fixture
269save
270check eq afstep 3170893824 -22
271unchanged
272fixture
273put AP 0 2139095039
274put AP 16 1073741824
275save
276check eq afstep 1023410176 -23
277unchanged
278end
279
280fn next to long
281n = add mul get RNG 0 1664525 1013904223
282n = and n 4294967295
283put RNG 0 n
284ret sub long rem shr n 12 17 8
285end
286
287fn rounding to void
288note Smallest subnormal through actual forward and input derivative, loss underflows.
289fixture
290put AP 0 1
291put AP 16 1065353216
292check eq afstep 0 0
293check eq afget 4 0 1
294check eq afget 5 0 2
295check eq afget 6 0 0
296check eq afget 7 0 2
297check eq get AL 0 0
298note Half a subnormal rounds to even zero.
299fixture
300put AP 0 1
301put AP 16 1056964608
302check eq afstep 0 0
303check eq afget 4 0 0
304note 1 + 2^-24 rounds to even1; 1 + 3*2^-24 rounds upward two ulps.
305fixture
306put AP 0 1065353216
307put AP 16 1065353216
308put AP 32 864026624
309check eq afstep 0 0
310check eq afget 4 0 1065353216
311check eq afget 1 0 1065353216
312fixture
313put AP 0 1065353216
314put AP 16 1065353216
315put AP 32 876609536
316check eq afstep 0 0
317check eq afget 4 0 1065353218
318end
319
320fn corpus to void
321put RNG 0 303660
322for trial ulong 4096
323fixture
324for i ulong 18
325put RI i next
326end
327loadinputs
328check eq afstep 1023410176 0
329oracle
330end
331end
332
333fn main to int
334direct
335refusals
336rounding
337corpus
338w = write 1 PASS 0 len PASS
339number get C 0
340w = write 1 NL 0 1
341if ne w 1
342ret 90
343end
344ret 0
345end