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 / adtrain / main.om

269 lines · 4024 bytes Raw Blame History
1note SPDX-License-Identifier: AGPL-3.0-only
2note adtrain driver. Reads one mode byte from fd 0:
3note T train 200 steps (L rows, P rows, loss gate 88), S train 120 and save,
4note R load and continue to 200, Z as S with data seed 29, G tape gradients
5note against central differences, D write the C-oracle fixture and K rows.
6note Exits: 90 bad mode, 65 corrupt checkpoint, 66 data-binding mismatch,
7note 88 loss not reduced, 1 gradient check failed; mlp.om adds 74/86/87.
8global AD uchar 24
9global AB uchar 4
10global AC ulong 2
11global AL f32 1
12text ATP "ADTRAIN_T_PASS\n"
13text ASP "ADTRAIN_S_PASS\n"
14text ARP "ADTRAIN_R_PASS\n"
15text AGP "ADTRAIN_G_PASS checked="
16text AGF "ADTRAIN_G_FAIL checked="
17text ADP "ADTRAIN_D_PASS\n"
18text ASK "skip"
19text AFL " failed="
20
21fn dout t uchar to void
22put AB 0 t
23w = write 1 AB 0 1
24if ne w 1
25exit 74
26end
27end
28
29fn dnum n ulong to void
30if eq n 0
31dout 48
32ret
33end
34p = ulong 24
35while gt n 0 bound 24
36p = sub p 1
37put AD p uchar add 48 rem n 10
38n = div n 10
39end
40w = write 1 AD p sub 24 p
41if ne w long sub 24 p
42exit 74
43end
44end
45
46fn dtext n ulong to void
47note n selects one of the fixed texts.
48if eq n 0
49w = write 1 ATP 0 len ATP
50end
51if eq n 1
52w = write 1 ASP 0 len ASP
53end
54if eq n 2
55w = write 1 ARP 0 len ARP
56end
57if eq n 3
58w = write 1 ADP 0 len ADP
59end
60end
61
62note "<tag> <a> <b>\n"
63fn dline tag uchar a ulong b ulong to void
64dout tag
65dout 32
66dnum a
67dout 32
68dnum b
69dout 10
70end
71
72fn dloss s ulong l f32 to void
73dline 76 s mlbits l
74end
75
76fn dparams to void
77for i ulong 58
78dline 80 i mlbits get MP i
79end
80end
81
82note Train from the current step up to `upto`, printing L rows, then L upto.
83note The loss at step 100 is kept in AL for the T loss gate.
84fn dtrain upto ulong to f32
85start = get MS 1
86for i ulong sub upto start
87s = add start i
88l = mlstep
89dloss s l
90if eq s 100
91put AL 0 l
92end
93end
94l = mlfwd
95dloss upto l
96ret l
97end
98
99fn mode_t to void
100mlinit 17
101l0 = mlfwd
102l200 = dtrain 200
103if not and lt l200 l0 lt l200 get AL 0
104exit 88
105end
106dparams
107dtext 0
108end
109
110fn mode_s seed ulong to void
111mlinit seed
112l = dtrain 120
113cksave l
114dtext 1
115end
116
117fn mode_r to void
118mlinit 17
119st = ckload
120if eq st -1
121exit 65
122end
123if eq st -2
124exit 66
125end
126if ne st 0
127exit 65
128end
129l = dtrain 200
130dparams
131dtext 2
132end
133
134note Gradient-check step h = 1/64 (exact in binary32, bits 0x3C800000). It is
135note its own constant, not the learning rate mllr, so a changed lr is caught
136note by the golden gate and not hidden in the finite-difference step. dgc
137note scales by 32.0 = 1/(2h); change both together.
138fn dgeps to f32
139ret div 1.0f32 64.0f32
140end
141
142note One central difference; returns 0 skipped, 1 agreed, 2 disagreed.
143fn dgc i ulong to ulong
144p = get MP i
145eps = dgeps
146put MP i add p eps
147fp = mlfwd
148okp = mlsame
149put MP i sub p eps
150fm = mlfwd
151okm = mlsame
152put MP i p
153dout 71
154dout 67
155dout 32
156dnum i
157dout 32
158if not and okp okm
159w = write 1 ASK 0 len ASK
160dout 10
161ret 0
162end
163d = mul sub fp fm 32.0f32
164g = get MG i
165e = fabs sub d g
166ok = le e eps
167if ge fabs g eps
168ok = le mul e 16.0f32 fabs g
169end
170dnum mlbits d
171dout 32
172if ok
173dout 49
174dout 10
175ret 1
176end
177dout 48
178dout 10
179ret 2
180end
181
182fn mode_g to void
183mlinit 17
184l = mlgrad
185mlmask
186for i ulong 58
187dline 71 i mlbits get MG i
188end
189put AC 0 0
190put AC 1 0
191for i ulong 58
192r = dgc i
193if eq r 1
194put AC 0 add get AC 0 1
195end
196if eq r 2
197put AC 1 add get AC 1 1
198end
199end
200ok = and ge get AC 0 50 eq get AC 1 0
201if ok
202w = write 1 AGP 0 len AGP
203else
204w = write 1 AGF 0 len AGF
205end
206dnum add get AC 0 get AC 1
207w = write 1 AFL 0 len AFL
208dnum get AC 1
209dout 10
210if not ok
211exit 1
212end
213end
214
215note K rows: the first ten generator values k (-8..8) of seed 17, for an
216note external re-implementation of the data generator.
217fn mode_d to void
218mlinit 17
219l = mlgrad
220mlfix
221put MS 0 17
222for i ulong 10
223k = mlk
224dout 75
225dout 32
226dnum i
227dout 32
228if lt k 0
229dout 45
230k = neg k
231end
232dnum ulong k
233dout 10
234end
235dtext 3
236end
237
238fn main to int
239n = read 0 AB 0 1
240if ne n 1
241exit 90
242end
243m = get AB 0
244if eq m 84
245mode_t
246ret 0
247end
248if eq m 83
249mode_s 17
250ret 0
251end
252if eq m 90
253mode_s 29
254ret 0
255end
256if eq m 82
257mode_r
258ret 0
259end
260if eq m 71
261mode_g
262ret 0
263end
264if eq m 68
265mode_d
266ret 0
267end
268exit 90
269end