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 / native / omegese45 / core / run.om

311 lines · 5715 bytes Raw Blame History
1note SPDX-License-Identifier: AGPL-3.0-only
2note omegese45 core: data files, training schedule, dev metrics and decoding (aien-train #45,
3note pipeline lane). Needs vocab.om, msg.om, model.om, ckpt.om (and the SHA unit) before it.
4note Data file (.ids, written by native/omegese45/data/gen.om): records of one byte L (1 .. 176)
5note then L ids (< 41). Text files are OE45 v1 (docs/omegese45/CONTRACT.md).
6const OPDBN ulong 4194304
7const OPMAXE ulong 40000
8const OPBUD ulong 31
9global opdb uchar 4194305
10global opdn ulong 1
11global opeo ulong 40000
12global opne ulong 1
13global opperm ulong 40000
14global opfp uchar 4200
15global opst ulong 16
16global opln ulong 1
17global opsv uchar 256
18
19note opst: run statistics. 0 unused, 1 positions, 2 correct (teacher-forced argmax),
20note 3 messages, 4 exact U, 5 exact G, 6 epoch of opperm + 1.
21
22note argv[i] into opfp; returns its length.
23fn oppath i ulong to ulong
24r = argread i opfp 0 4096
25if or le r 0 gt r 4096
26exit 2
27end
28ret ulong r
29end
30
31fn opdecu i ulong to ulong
32n = oppath i
33v = ulong 0
34if or eq n 0 gt n 18
35exit 2
36end
37for k ulong n
38c = ulong get opfp k
39if or lt c 48 gt c 57
40exit 2
41end
42v = add mul v 10 sub c 48
43end
44ret v
45end
46
47note Read the file argv[i] whole into opdb (at most OPDBN bytes, else exit 2).
48fn opread i ulong to void
49n = oppath i
50fd = int fopen opfp 0 n 0 0
51if lt fd 0
52exit 70
53end
54p = ulong 0
55dn = false
56while not dn bound 5000
57r = read fd opdb p sub add OPDBN 1 p
58if lt r 0
59exit 70
60end
61if eq r 0
62dn = true
63else
64p = add p ulong r
65if gt p OPDBN
66exit 2
67end
68end
69end
70c = fclose fd
71put opdn 0 p
72end
73
74note Index the id records of opdb (exit 2 on a malformed file).
75fn opindex to void
76n = get opdn 0
77p = ulong 0
78e = ulong 0
79while lt p n bound 40001
80l = ulong get opdb p
81if or or eq l 0 gt l OPMAXL ge e OPMAXE
82exit 2
83end
84if gt add add p 1 l n
85exit 2
86end
87for k ulong l
88if ge ulong get opdb add add p 1 k OPV
89exit 2
90end
91end
92put opeo e p
93e = add e 1
94p = add add p 1 l
95end
96if eq e 0
97exit 2
98end
99put opne 0 e
100end
101
102note sha256 of opdb[0, opdn) into optds.
103fn ophdat to void
104c = new uchar 104 0
105b = new uchar 4096 0
106d = new uchar 32 0
107sha256_init c
108n = get opdn 0
109p = ulong 0
110while lt p n bound 1100
111k = sub n p
112if gt k 4096
113k = 4096
114end
115for i ulong k
116put b i get opdb add p i
117end
118sha256_update c part b 0 k
119p = add p k
120end
121sha256_final c d
122for i ulong 32
123put optds i get d i
124end
125end
126
127note Load the .ids file argv[i]: read, index, hash into optds.
128fn opldat i ulong to void
129opread i
130opindex
131ophdat
132end
133
134note Episode e into opseq / opsl.
135fn opepi e ulong to void
136o = get opeo e
137l = ulong get opdb o
138for k ulong l
139put opseq k get opdb add add o 1 k
140end
141put opsl 0 l
142end
143
144note Epoch order: a Fisher-Yates permutation of 0 .. N-1 from splitmix64 seeded with
145note orderseed + 1000003 * epoch, rebuilt from the step alone at resume.
146fn opperms ep ulong to void
147n = get opne 0
148put oprs 0 add get opmeta 5 mul ep 1000003
149for i ulong n
150put opperm i i
151end
152i = n
153while gt i 1 bound 40001
154j = rem opnext i
155i = sub i 1
156x = get opperm i
157put opperm i get opperm j
158put opperm j x
159end
160put opst 6 add ep 1
161end
162
163note Train from opmeta[1] to min(until, total), saving every `every` steps and at the end.
164note Prints `T step phase sum-loss-bits positions` at each save.
165fn optrain until ulong every ulong to void
166lr = bitcast f32 uint get opmeta 6
167s = get opmeta 1
168if gt until get opmeta 4
169until = get opmeta 4
170end
171n = get opne 0
172ls = 0.0f32
173np = ulong 0
174while lt s until bound 999999
175ep = div s n
176if ne get opst 6 add ep 1
177opperms ep
178end
179opepi get opperm rem s n
180ph = ulong 2
181if lt s get opmeta 3
182ph = 1
183end
184ls = add ls optrep ph lr
185np = add np opnpos ph
186s = add s 1
187put opmeta 1 s
188if or eq rem s every 0 eq s until
189opsave
190oprt s ph ls np
191ls = 0.0f32
192np = 0
193end
194end
195end
196
197note Trained positions of the current episode under phase ph.
198fn opnpos ph ulong to ulong
199if eq ph 1
200ret get opsl 0
201end
202c = ulong 0
203for t ulong get opsl 0
204c = add c ulong get opmk t
205end
206ret c
207end
208
209fn oprt s ulong ph ulong ls f32 np ulong to void
210ocputc 84
211ocputc 32
212ocputn s
213ocputc 32
214ocputn ph
215ocputc 32
216ocputn ulong bitcast uint ls
217ocputc 32
218ocputn np
219ocputc 10
220end
221
222note Decode after the prefix opseq[0, n) (mode 85 U, 71 G). Generated ids follow the prefix
223note in opseq. Returns 0 ok (count in opln), 50 invalid (U), 53 budget.
224fn opdecode n ulong md ulong to ulong
225st = ocstart 5
226put opln 0 0
227for i ulong OPBUD
228t = add n i
229opfeat t
230opfwd
231id = ulong 0
232if eq md 71
233if eq ocmask st 0
234ret 50
235end
236id = opargmx false
237else
238id = opargmx true
239end
240put opseq t uchar id
241put opln 0 add i 1
242st = ocstep st id
243if eq md 71
244if ocfinal st
245ret 0
246end
247else
248if eq id 5
249if ocfinal st
250ret 0
251end
252ret 50
253end
254end
255end
256ret 53
257end
258
259note Dev metrics for one episode: at every A/P message, teacher-forced argmax accuracy and
260note free decoding (U and G) from the true prefix; exact means the reference message.
261fn opdevep to void
262opmask
263n = get opsl 0
264for t ulong n
265if eq get opmk t 1
266opfeat t
267opfwd
268put opst 1 add get opst 1 1
269if eq opargmx true optgt t
270put opst 2 add get opst 2 1
271end
272end
273end
274s = ulong 0
275for t ulong n
276if eq get opseq t 5
277if eq get opmk s 1
278opdevmsg s add sub t s 1
279end
280s = add t 1
281end
282end
283end
284
285note Message at [s, s + l) of the current episode: decode U and G from its prefix. The
286note episode is kept in opsv; decoding may write up to OPBUD ids from s, restored after each.
287fn opdevmsg s ulong l ulong to void
288for k ulong get opsl 0
289put opsv k get opseq k
290end
291put opst 3 add get opst 3 1
292put opst 4 add get opst 4 opdevx s l 85
293put opst 5 add get opst 5 opdevx s l 71
294end
295
296fn opdevx s ulong l ulong md ulong to ulong
297rc = opdecode s md
298ok = and eq rc 0 eq get opln 0 l
299for k ulong l
300if ne get opseq add s k get opsv add s k
301ok = false
302end
303end
304for k ulong OPBUD
305put opseq add s k get opsv add s k
306end
307if ok
308ret 1
309end
310ret 0
311end