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 / model.om

279 lines · 5723 bytes Raw Blame History
1note SPDX-License-Identifier: AGPL-3.0-only
2note omegese45 core model (aien-train #45, pipeline lane): a dense next-token model
3note over R45 ids. One hidden ReLU layer, 41 linear outputs, squared error to the one-hot
4note target, plain per-position SGD. Forward and backward are written out here because the
5note native tape (omega-mv native/autodiff664/tape.om @965fb762) holds at most 32 nodes of
6note at most 64 elements in a 2048-float arena (docs/omegese45/PIPELINE.md, "Why not the tape").
7note Causal input for position t, built only from ids at positions < t:
8note head slot p (0 <= p < 30, p < t): one-hot of id[p] feature p * 41 + id
9note tail slot k (0 <= k < 64, k < t): one-hot of id[t-1-k] feature (30 + k) * 41 + id
10note Arch: OPIN 3854 inputs, OPH 256 hidden, OPV 41 outputs. Parameters, payload order:
11note W1[f][j] f < 3854, j < 256 (row-major), b1[256], W2[j][v] (row-major), b2[41].
12note Init algorithm 1: splitmix64 from the init seed; W1 then W2 in payload order, each
13note value u = ((r >> 40) - 2^23) * 2^-23 scaled by 1/8 (W1) or 1/16 (W2); biases 0.
14note Every value is a dyadic rational, exact in binary32. Needs vocab.om (ocv) before it.
15const OPV ulong 41
16const OPHS ulong 30
17const OPTW ulong 64
18const OPIN ulong 3854
19const OPH ulong 256
20const OPW1N ulong 986624
21const OPW2N ulong 10496
22const OPNP ulong 997417
23const OPMAXL ulong 176
24global opw1 f32 986624
25global opb1 f32 256
26global opw2 f32 10496
27global opb2 f32 41
28global opseq uchar 256
29global opsl ulong 1
30global opmk uchar 256
31global opfx ulong 94
32global opfn ulong 1
33global ophp f32 256
34global oph f32 256
35global opy f32 41
36global opgy f32 41
37global opgh f32 256
38global oprs ulong 1
39
40note splitmix64 (Steele, Lea, Flood 2014).
41fn opnext to ulong
42x = add get oprs 0 11400714819323198485
43put oprs 0 x
44z = xor x shr x 30
45z = mul z 13787848793156543929
46z = xor z shr z 27
47z = mul z 10723151780598845931
48ret xor z shr z 31
49end
50
51note u in [-1, 1) on the 2^-23 grid, from the top 24 bits of the next generator value.
52fn opunif to f32
53k = long shr opnext 40
54ret mul f32 sub k 8388608 0.00000011920928955078125f32
55end
56
57fn opinit seed ulong to void
58put oprs 0 seed
59for i ulong OPW1N
60put opw1 i mul opunif 0.125f32
61end
62for i ulong OPW2N
63put opw2 i mul opunif 0.0625f32
64end
65for j ulong OPH
66put opb1 j 0.0f32
67end
68for v ulong OPV
69put opb2 v 0.0f32
70end
71end
72
73note Parameter i of the payload order.
74fn opgetp i ulong to f32
75if lt i OPW1N
76ret get opw1 i
77end
78j = sub i OPW1N
79if lt j OPH
80ret get opb1 j
81end
82j = sub j OPH
83if lt j OPW2N
84ret get opw2 j
85end
86ret get opb2 sub j OPW2N
87end
88
89fn opsetp i ulong x f32 to void
90if lt i OPW1N
91put opw1 i x
92ret
93end
94j = sub i OPW1N
95if lt j OPH
96put opb1 j x
97ret
98end
99j = sub j OPH
100if lt j OPW2N
101put opw2 j x
102ret
103end
104put opb2 sub j OPW2N x
105end
106
107note Active features of position t of opseq (ids at positions < t only).
108fn opfeat t ulong to void
109n = ulong 0
110hm = t
111if gt hm OPHS
112hm = OPHS
113end
114for p ulong hm
115id = ulong get opseq p
116if ne id 0
117put opfx n add mul p OPV id
118n = add n 1
119end
120end
121km = t
122if gt km OPTW
123km = OPTW
124end
125for k ulong km
126id = ulong get opseq sub sub t 1 k
127if ne id 0
128put opfx n add mul add OPHS k OPV id
129n = add n 1
130end
131end
132put opfn 0 n
133end
134
135fn opfwd to void
136for j ulong OPH
137put ophp j get opb1 j
138end
139for f ulong get opfn 0
140r = mul get opfx f OPH
141for j ulong OPH
142put ophp j add get ophp j get opw1 add r j
143end
144end
145for v ulong OPV
146put opy v get opb2 v
147end
148for j ulong OPH
149x = get ophp j
150put oph j 0.0f32
151if gt x 0.0f32
152put oph j x
153r = mul j OPV
154for v ulong OPV
155put opy v add get opy v mul x get opw2 add r v
156end
157end
158end
159end
160
161note Squared error to the one-hot of tg; dL/dy into opgy. Returns L.
162fn oploss tg ulong to f32
163l = 0.0f32
164for v ulong OPV
165d = get opy v
166if eq v tg
167d = sub d 1.0f32
168end
169put opgy v mul 2.0f32 d
170l = add l mul d d
171end
172ret l
173end
174
175note dL/dhp into opgh (ReLU derivative 1 where hp > 0), from W2 before its update.
176fn opbwd to void
177for j ulong OPH
178s = 0.0f32
179if gt get ophp j 0.0f32
180r = mul j OPV
181for v ulong OPV
182s = add s mul get opw2 add r v get opgy v
183end
184end
185put opgh j s
186end
187end
188
189note p = p - lr * dL/dp for every parameter with a nonzero gradient path.
190fn opupd lr f32 to void
191for j ulong OPH
192x = get oph j
193if gt x 0.0f32
194r = mul j OPV
195for v ulong OPV
196q = add r v
197g = mul lr mul x get opgy v
198put opw2 q sub get opw2 q g
199end
200end
201put opb1 j sub get opb1 j mul lr get opgh j
202end
203for v ulong OPV
204put opb2 v sub get opb2 v mul lr get opgy v
205end
206for f ulong get opfn 0
207r = mul get opfx f OPH
208for j ulong OPH
209q = add r j
210g = mul lr get opgh j
211put opw1 q sub get opw1 q g
212end
213end
214end
215
216note Target of position t: the id at t.
217fn optgt t ulong to ulong
218ret ulong get opseq t
219end
220
221note A/P mask of opseq: 1 at every position of a message whose frame id is act or rep.
222note Messages are split at `end` (id 5), which occurs only as a message terminator in R45.
223fn opmask to void
224n = get opsl 0
225fr = ulong 0
226st = true
227for t ulong n
228id = ulong get opseq t
229if st
230fr = id
231end
232put opmk t 0
233if or eq fr 2 eq fr 4
234put opmk t 1
235end
236st = eq id 5
237end
238end
239
240note One position: features, forward, loss, backward. Returns L.
241fn opgrad t ulong to f32
242opfeat t
243opfwd
244l = oploss optgt t
245opbwd
246ret l
247end
248
249note Train on the current episode: phase 1 every position, phase 2 the A/P positions.
250note Returns the summed loss of the trained positions (before each update).
251fn optrep ph ulong lr f32 to f32
252s = 0.0f32
253opmask
254for t ulong get opsl 0
255if or eq ph 1 eq get opmk t 1
256s = add s opgrad t
257opupd lr
258end
259end
260ret s
261end
262
263note Argmax of opy over ids with ocmk[id] = 1 (all = true ignores the mask); first wins.
264fn opargmx all bool to ulong
265b = ulong 0
266bv = 0.0f32
267have = false
268for v ulong OPV
269if or all eq get ocmk v 1
270x = get opy v
271if or not have gt x bv
272b = v
273bv = x
274have = true
275end
276end
277end
278ret b
279end