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 / omegallm / cli.om

1057 lines · 20372 bytes Raw Blame History
1note SPDX-License-Identifier: AGPL-3.0-only
2note omegallm cli.om (aien-train#52): the ollm commands (CONTRACT section 7). The platform unit
3note (lio.om or eio.om) follows it and holds main.
4note Command words are matched as little-endian u64 packings of their bytes (Wolfram
5note FromDigits[Reverse[ToCharacterCode[w]],256]): prep 1885696624, init 1953066601,
6note grad 1684107879, train 474214396532, eval 1818326629, base 1702060386, sample 111516417089907,
7note gcheck 118074647274343, mathck 118074698391917, adamck 118074781033569; v1: bpefit
8note 127996038312034, bpeenc 109325798699106, bpedec 109287127216226 (bpe.om); serve 435778905459
9note (serve.om on aarch64, noserve.om elsewhere). Fine-tune: tune 1701737844.
10note Exit codes: 0 ok; 2 usage; 10-15 checkpoint refusals (ckpt.om); 20 data file shorter than
11note T + 1 bytes; 21 data over 2^25 bytes or OFFS not exactly 8 B bytes; 22 an OFFS offset with
12note o + T >= N; 23 eval W = 0 or W T + 1 > M; 24 prep story over 999999 bytes; 40 gcheck over
13note tolerance; 41 adamck over tolerance; 42 mathck over tolerance; 70 I/O.
14
15fn ocmdw to ulong
16r = oargr 1
17if or le r 0 gt r 8
18ret 0
19end
20v = ulong 0
21for k ulong ulong r
22v = or v shl ulong get oarg k mul k 8
23end
24ret v
25end
26
27fn ocmdlo to ulong
28r = oargr 1
29if or le r 8 gt r 16
30ret 0
31end
32v = ulong 0
33for k ulong 8
34v = or v shl ulong get oarg k mul k 8
35end
36ret v
37end
38
39fn ocmdhi to ulong
40r = oargr 1
41if or le r 8 gt r 16
42ret 0
43end
44v = ulong 0
45n = sub ulong r 8
46for k ulong n
47v = or v shl ulong get oarg add 8 k mul k 8
48end
49ret v
50end
51
52note run the command named by argument 1; the platform main checks that it exists.
53fn ocmd to int
54w = ocmdw
55if eq w 1885696624
56cmdprep
57ret 0
58end
59if eq w 127996038312034
60cmdbpfit
61ret 0
62end
63if eq w 109325798699106
64cmdbpenc
65ret 0
66end
67if eq w 109287127216226
68cmdbpdec
69ret 0
70end
71if eq w 1953066601
72cmdinit
73ret 0
74end
75if eq w 1684107879
76cmdgrad
77ret 0
78end
79if eq w 474214396532
80cmdtrain
81ret 0
82end
83if eq w 1818326629
84cmdeval
85ret 0
86end
87if eq w 1702060386
88cmdbase
89ret 0
90end
91if eq w 111516417089907
92cmdsamp
93ret 0
94end
95if eq w 118074647274343
96cmdgchk
97ret 0
98end
99if eq w 118074698391917
100cmdmath
101ret 0
102end
103if eq w 118074781033569
104cmdadamck
105ret 0
106end
107if eq w 435778905459
108cmdserve
109ret 0
110end
111if eq w 1701737844
112cmdtune
113ret 0
114end
115note grow: append initially silent residual layers and restart training.
116if eq w 2003792487
117cmdgrow
118ret 0
119end
120note kvcmp (ham/ollm-speed) 482871572075
121if eq w 482871572075
122cmdkvcmp
123ret 0
124end
125if eq w 112624400429684
126cmdtrainf
127ret 0
128end
129if eq w 30506458620916852
130cmdttteval
131ret 0
132end
133if eq w 7809653406635421540
134cmddolaeval
135ret 0
136end
137if eq w 31645462707860596
138cmdtttsamp
139ret 0
140end
141if eq w 500236120179
142cmdspext
143ret 0
144end
145if eq w 482921771123
146cmdspapp
147ret 0
148end
149if eq w 123615088701555
150cmdspsamp
151ret 0
152end
153if eq w 119165853986931
154cmdspeval
155ret 0
156end
157if eq w 111499018330982
158cmdfcache
159ret 0
160end
161if eq w 27978647094784628
162cmdtrainfc
163ret 0
164end
165if eq w 30792271479792486
166cmdfcachem
167ret 0
168end
169if eq w 28542713673379955
170cmdspmerge
171ret 0
172end
173if eq w 30227092724740211
174cmdspstack
175ret 0
176end
177if eq w 31369549780578919
178cmdgrowpro
179ret 0
180end
181if eq w 495773380723
182cmdspens
183ret 0
184end
185if eq w 123598092333171
186cmdspclip
187ret 0
188end
189if eq w 0
190lo = ocmdlo
191hi = ocmdhi
192if and eq lo 7020664736201273459 eq hi 28784
193cmdspchainapp
194ret 0
195end
196if and eq lo 7308895112352985203 eq hi 7102838
197cmdspchaineval
198ret 0
199end
200if and eq lo 8317701428883976307 eq hi 7368033
201cmdspchainsamp
202ret 0
203end
204end
205exit 2
206end
207
208note init CK V T D H F L B SEED TOTAL LRMICRO [G]; lr = f64(LRMICRO)/1000000.0. Without G the file
209note is OLLMCK01 (G = 1); with G it is OLLMCK02 (CONTRACT-V1 section 6).
210fn cmdinit to void
211na = oargc
212if and ne na 13 ne na 14
213exit 2
214end
215for i ulong 7
216put og i oargu add 3 i
217end
218if not ogeom
219exit 12
220end
221put og 40 oargu 10
222tt = oargu 11
223if gt tt 999999
224exit 12
225end
226g = ulong 1
227put og 46 1
228if eq na 14
229g = oargu 13
230put og 46 2
231end
232if not ogok2 g
233exit 12
234end
235put og 44 g
236put og 42 tt
237put og 43 bitcast ulong div f64 oargu 12 1000000.0
238put og 41 0
239oinit
240ocksave 2
241oputc 73
242oputc 32
243oputu get og 8
244oputc 10
245oflush
246end
247
248note little-endian u64 at ochk[o..o+8)
249fn ochk64 o ulong to ulong
250v = ulong 0
251for k ulong 8
252x = ulong get ochk add o k
253v = or v shl x mul k 8
254end
255ret v
256end
257
258note row b from offset ochk[b] (checked by ooffok)
259fn ooffrow b ulong to void
260obrow b ochk64 mul b 8
261end
262
263note exit 22 when any offset has o >= N - T (written so that an offset near 2^64 cannot wrap)
264fn ooffok to void
265n = get odn 0
266tt = get og 1
267for b ulong get og 6
268if ge ochk64 mul b 8 sub n tt
269exit 22
270end
271end
272end
273
274note grad CK DATA OFFS OUT: the gradient of CONTRACT-V1 section 5 (G blocks, K = 1)
275fn cmdgrad to void
276if ne oargc 6
277exit 2
278end
279ockload 2
280odopen 3
281ooffrd 4
282ooffok
283for b ulong get og 6
284ooffrow b
285end
286ls = ograd
287ogrsave 5
288oputc 71
289oputc 32
290oputx bitcast ulong ls
291oputc 32
292oputl rmic ls
293oputc 10
294oflush
295end
296
297note train CK TRAIN UNTIL EVERY [K]: steps step .. min(UNTIL, TOTAL)-1; after step s, when
298note (s+1) mod EVERY = 0 or s+1 is the end, save CK and print `T s+1 loss_micro(step s)`.
299note K worker processes (CONTRACT-V1 section 5.1): K < 1, K > G or G mod K != 0 is exit 29.
300fn cmdtrain to void
301na = oargc
302if and ne na 6 ne na 7
303exit 2
304end
305ockload 2
306odopen 3
307un = oargu 4
308ev = oargu 5
309if eq ev 0
310exit 2
311end
312k = ulong 1
313if eq na 7
314k = oargu 6
315end
316gg = get og 44
317if or eq k 0 gt k gg
318exit 29
319end
320if ne rem gg k 0
321exit 29
322end
323put og 45 k
324en = get og 42
325if lt un en
326en = un
327end
328while lt get og 41 en bound 999999
329ls = ostep
330s1 = get og 41
331if or eq rem s1 ev 0 eq s1 en
332ocksave 2
333oputc 84
334oputc 32
335oputu s1
336oputc 32
337oputl rmic ls
338oputc 10
339oflush
340end
341end
342end
343
344note eval CK HELD W [MERGES]: windows at 0, T, .., (W-1)T; prints `E step W loss_micro bpb_micro`.
345note V > 256 needs MERGES (else exit 2); bpb = ((loss/ln2) f64(W T))/f64(nbytes) with nbytes the
346note decoded length of the W T targets (CONTRACT-V1 section 7.1); V = 256 keeps loss/ln2.
347fn cmdeval to void
348na = oargc
349if and ne na 5 ne na 6
350exit 2
351end
352ockload 2
353ww = oargu 4
354v = get og 0
355if gt v 256
356if eq na 5
357exit 2
358end
359obload 5 v
360end
361odopen 3
362tt = get og 1
363m = get odn 0
364note W T + 1 > N, tested as W > (N - 1) / T so that a huge W cannot wrap W T
365if eq ww 0
366exit 23
367end
368if gt ww div sub m 1 tt
369exit 23
370end
371ls = 0.0f64
372nb = ulong 0
373for w ulong ww
374obrow 0 mul w tt
375ls = add ls ofwd 0
376if gt v 256
377nb = add nb oevnb tt
378end
379end
380lo = div ls f64 ww
381bp = div lo 0.6931471805599453
382if gt v 256
383bp = div mul bp f64 mul ww tt f64 nb
384end
385oputc 69
386oputc 32
387oputu get og 41
388oputc 32
389oputu ww
390oputc 32
391oputl rmic lo
392oputc 32
393oputl rmic bp
394oputc 10
395oflush
396end
397
398note decoded bytes of the targets oby[0 .. n)
399fn oevnb n ulong to ulong
400s = ulong 0
401for t ulong n
402s = add s obtlen get oby t
403end
404ret s
405end
406
407note append token c to the context window obx[0 .. CT), keeping the last T tokens
408fn ocpush c ulong to void
409cn = get og 9
410tt = get og 1
411if lt cn tt
412put obx cn c
413put og 9 add cn 1
414else
415for i ulong sub tt 1
416put obx i get obx add i 1
417end
418put obx sub tt 1 c
419end
420end
421
422note sample CK SEED N TEMPMILLI PROMPT [MERGES]. Context = token 0, then PROMPT (bytes when V = 256,
423note its encoding when V > 256, CONTRACT-V1 section 7.2); the model reads the last T context tokens
424note at positions 0..; the next token comes from the logits at the last position.
425note TEMPMILLI 0: argmax (lowest index on ties), no draw. Otherwise softmax(logits/(TEMPMILLI/1000))
426note and u = (splitmix64 stream out >> 11) 2^-53 with state = SEED, out = mix(state += GOLD);
427note the token is the smallest c with u < p[0] + .. + p[c], else the last c with p[c] > 0.
428note A generated token 0 ends the output and is not written; another writes its decoded bytes.
429fn cmdsamp to void
430na = oargc
431if and ne na 7 ne na 8
432exit 2
433end
434ockload 2
435st = oargu 3
436nn = oargu 4
437if gt nn 999999
438exit 2
439end
440tm = oargu 5
441v = get og 0
442if gt v 256
443if eq na 7
444exit 2
445end
446obload 7 v
447end
448ochipup
449osampleloaded st nn tm
450end
451
452note Embedding entry: checkpoint and tokenizer already loaded; argument 6 supplies the prompt.
453note The caller keeps exclusive ownership of the model pools until this returns.
454fn osampleloaded seed ulong nn ulong tm ulong to void
455if gt nn 999999
456exit 2
457end
458st = seed
459v = get og 0
460put og 9 0
461ocpush 0
462if gt v 256
463r = oargr 6
464if or lt r 0 gt r 4000
465exit 2
466end
467np = obprompt 6
468for i ulong np
469ocpush get obtk i
470end
471else
472r = oargr 6
473if or lt r 0 gt r 4096
474exit 2
475end
476for i ulong ulong r
477ocpush ulong get oarg i
478end
479end
480for g ulong nn
481c = osstep st tm
482if ne tm 0
483st = add st 11400714819323198485
484end
485if eq c 0
486break
487end
488if gt v 256
489obtput c
490else
491oputc c
492end
493note Flush each decoded token so interactive consumers see progress. Bytes and sampling stay unchanged.
494oflush
495ocpush c
496end
497oflush
498end
499
500note one sampling step (cmdsamp, serve.om): the next token from the logits at the last context
501note position, argmax when TEMPMILLI tm is 0, else a draw with the splitmix64 stream state st.
502fn osstep st ulong tm ulong to ulong
503olastf
504if eq tm 0
505ret oargmax
506end
507ret odraw st div f64 tm 1000.0
508end
509
510note ogpu[0] = 1 when the per-token forward runs on the chip: gpu/gg.om's gserve and gsample set it
511note before cmdserve or cmdsamp; nogpu.om's ogchip and oglast refuse with exit 2 on the CPU targets.
512global ogpu ulong 1
513
514note after the checkpoint loads: on the chip path, open the chip and upload the parameters once
515fn ochipup to void
516if ne get ogpu 0 0
517ogchip
518end
519end
520
521note forward of the context in obx row 0, then its last position's logits into TMP[0..V) (oa),
522note on the chip when ogpu[0] = 1 (oglast), else on the CPU (ofwdi, model.om: only the rows past the
523note prefix the previous call computed, then olast)
524fn olastf to void
525if ne get ogpu 0 0
526oglast
527ret
528end
529t0 = ofwdi
530olast
531end
532
533note kvcmp CK N PROMPT MERGES (ham/ollm-speed, V > 256, N V <= 2^20): ofwdi against ofwd 0. Pass 1:
534note N greedy steps from token 0 then PROMPT's encoding with ofwdi then olast (the CPU decode), every
535note step's V logits kept in okvr; prints `KI step ct t0 tok ns`. Pass 2: the same contexts again
536note (pass 1's tokens pushed) with ofwd 0 then olast; prints `KF step ct tok ndiff ns`, ndiff = logits
537note whose f64 bits differ from pass 1's. Before step N/2 of both passes the context token at CT - 5
538note (when CT > 5) becomes its successor mod V, so ofwdi must find the changed prefix. Last line
539note `KVCMP N ndiff inc_ns full_ns` (forward and logits time summed over the steps); exit 43 when
540note ndiff > 0.
541global okvr f64 1048576
542global okvk ulong 4096
543fn kvstart to void
544put og 9 0
545ocpush 0
546np = obprompt 4
547for i ulong np
548ocpush get obtk i
549end
550end
551
552fn kvpert s ulong nn ulong to void
553ct = get og 9
554if and eq s div nn 2 gt ct 5
555i = sub ct 5
556put obx i rem add get obx i 1 get og 0
557end
558end
559
560fn kvline a ulong b ulong c ulong d ulong e long to void
561oputc 32
562oputu a
563oputc 32
564oputu b
565oputc 32
566oputu c
567oputc 32
568oputu d
569oputc 32
570oputl e
571oputc 10
572oflush
573end
574
575note kvcmp totals: okvs[0] pass 1 ns, [1] pass 2 ns, [2] differing logits
576global okvs ulong 3
577fn cmdkvcmp to void
578if ne oargc 6
579exit 2
580end
581ockload 2
582nn = oargu 3
583v = get og 0
584if or le v 256 or gt nn 4096 gt mul nn v 1048576
585exit 2
586end
587obload 5 v
588put okvs 0 0
589put okvs 1 0
590put okvs 2 0
591kvstart
592for s ulong nn
593kvpert s nn
594c = kvinc s
595ocpush c
596end
597kvstart
598for s2 ulong nn
599kvpert s2 nn
600kvfull s2
601ocpush get okvk s2
602end
603oputc 75
604oputc 86
605oputc 67
606oputc 77
607oputc 80
608oputc 32
609oputu nn
610oputc 32
611oputu get okvs 2
612oputc 32
613oputu get okvs 0
614oputc 32
615oputu get okvs 1
616oputc 10
617oflush
618if gt get okvs 2 0
619exit 43
620end
621end
622
623note pass 1 step s: ofwdi then olast, logits into okvr row s, KI line; returns the greedy token
624fn kvinc s ulong to ulong
625a = onsnow
626t0 = ofwdi
627olast
628e = sub onsnow a
629put okvs 0 add get okvs 0 e
630c = oargmax
631kvkeep s
632put okvk s c
633oputc 75
634oputc 73
635kvline s get og 9 t0 c long e
636ret c
637end
638
639note okvr row s = the V logits in TMP
640fn kvkeep s ulong to void
641v = get og 0
642tm = get og 27
643o = mul s v
644for j ulong v
645x = get oa add tm j
646put okvr add o j x
647end
648end
649
650note the logits in TMP whose f64 bits differ from okvr row s
651fn kvdiff s ulong to ulong
652v = get og 0
653tm = get og 27
654o = mul s v
655nd = ulong 0
656for j ulong v
657x = bitcast ulong get oa add tm j
658y = bitcast ulong get okvr add o j
659if ne x y
660nd = add nd 1
661end
662end
663ret nd
664end
665
666note pass 2 step s: ofwd 0 then olast, compared bit for bit with okvr row s, KF line
667fn kvfull s ulong to void
668a = onsnow
669lf = ofwd 0
670olast
671e = sub onsnow a
672put okvs 1 add get okvs 1 e
673nd = kvdiff s
674put okvs 2 add get okvs 2 nd
675oputc 75
676oputc 70
677kvline s get og 9 oargmax nd long e
678end
679
680note logits of the last context position into TMP[0..V) (oa)
681fn olast to void
682d = get og 2
683z = add get og 17 mul sub get og 9 1 d
684klogit z get og 27 get og 0 d
685end
686
687fn oargmax to ulong
688tm = get og 27
689b = ulong 0
690bv = get oa tm
691for c ulong get og 0
692if gt get oa add tm c bv
693bv = get oa add tm c
694b = c
695end
696end
697ret b
698end
699
700fn odraw st ulong tau f64 to ulong
701tm = get og 27
702v = get og 0
703m = bitcast f64 ulong 18442240474082181120
704for c ulong v
705x = div get oa add tm c tau
706put oa add tm c x
707m = fmax m x
708end
709sm = osoft tm v m
710u = mul f64 shr smx st 11 1.1102230246251565e-16
711acc = 0.0f64
712la = ulong 0
713for k ulong v
714pk = get oa add tm k
715acc = add acc pk
716if lt u acc
717ret k
718end
719if gt pk 0.0
720la = k
721end
722end
723ret la
724end
725
726note gcheck constants (derivation and Wolfram queries in docs/omegallm/README.md). GCH2 = GCH/4 is
727note the retry step for an index whose difference at GCH crossed a ReLU kink.
728const GCH f64 0.000001
729const GCH2 f64 0.00000025
730const GCFLOOR f64 0.000001
731const GCTOL f64 0.001
732note mathck: max relative error allowed against the correctly rounded reference
733const MCTOL f64 0.000000000000001
734
735note gcheck CK TRAIN: the hand gradient of the step loss for the batch of the header step is
736note compared with central differences (L(p+h) - L(p-h))/((p+h) - (p-h)) at 4 indices of every
737note tensor instance (wte, wpe, per layer g1 wq wk wv wo g2 w1 w2, gf), drawn by splitmix64.
738note rel = |num - g| / max(|num|, |g|, GCFLOOR). An index with rel > GCTOL at GCH is measured
739note again at GCH2 and keeps the smaller rel (a wrong hand gradient fails at both steps). Prints
740note one `c index g_e12 num_e12` line per index (num of the kept step), then
741note `C count maxrel_bits_hex maxrel_e9 worst_index retries`; exit 40 when maxrel > GCTOL.
742fn cmdgchk to void
743if ne oargc 4
744exit 2
745end
746ockload 2
747odopen 3
748obatch get og 41
749ls = ograd
750d = get og 2
751cnt = ulong 0
752put og 50 0
753put og 51 0
754put og 52 0
755put og 53 0
756ogcten 0 mul get og 0 d 0
757ogcten get og 30 mul get og 1 d 1
758for l ulong get og 5
759ogcten opg1 l d 2
760ogcten opwq l mul d d 3
761ogcten opwk l mul d d 4
762ogcten opwv l mul d d 5
763ogcten opwo l mul d d 6
764ogcten opg2 l d 7
765ogcten opw1 l mul d get og 4 8
766ogcten opw2 l mul d get og 4 9
767end
768ogcten get og 33 d 10
769mx = bitcast f64 get og 51
770oputc 67
771oputc 32
772oputu get og 50
773oputc 32
774oputx get og 51
775oputc 32
776oputl long mul mx 1000000000.0
777oputc 32
778oputu get og 52
779oputc 32
780oputu get og 53
781oputc 10
782oflush
783if gt mx GCTOL
784exit 40
785end
786end
787
788note step-loss for the batch in obx/oby without touching the gradient
789fn oloss to f64
790ls = 0.0f64
791for b ulong get og 6
792ls = add ls ofwd b
793end
794ret div ls f64 get og 6
795end
796
797fn ogcten o ulong n ulong tag ulong to void
798for j ulong 4
799i = add o rem smx xor get og 40 add mul get og 50 4 j n
800ogc1 i
801end
802end
803
804note central difference (L(p+h) - L(p-h))/((p+h) - (p-h)) at parameter i; restores p
805fn ogcnum i ulong h f64 to f64
806p0 = owg i
807pp = add p0 h
808pm = sub p0 h
809owp i pp
810lp = oloss
811owp i pm
812lm = oloss
813owp i p0
814ret div sub lp lm sub pp pm
815end
816
817fn ogcrel num f64 g f64 to f64
818den = fmax fmax fabs num fabs g GCFLOOR
819ret div fabs sub num g den
820end
821
822note one gradient check at parameter i; updates og[50] count, og[51] max rel bits, og[52] worst
823note index, og[53] retries at GCH2
824fn ogc1 i ulong to void
825g = ocsg i
826num = ogcnum i GCH
827rel = ogcrel num g
828if gt rel GCTOL
829put og 53 add get og 53 1
830n2 = ogcnum i GCH2
831r2 = ogcrel n2 g
832if lt r2 rel
833num = n2
834rel = r2
835end
836end
837oputc 99
838oputc 32
839oputu i
840oputc 32
841oputl long mul g 1000000000000.0
842oputc 32
843oputl long mul num 1000000000000.0
844oputc 10
845put og 50 add get og 50 1
846if gt rel bitcast f64 get og 51
847put og 51 bitcast ulong rel
848put og 52 i
849end
850end
851
852note mathck REF: REF lines are `e XBITS RBITS` or `l XBITS RBITS` (16 lowercase hex digits each,
853note 36 bytes per line); RBITS is the correctly rounded Wolfram value of exp or log at the exact
854note f64 XBITS. Prints `M e count max_ulp maxrel_bits_hex maxrel_e18` and the same for l;
855note exit 42 when a special value (r = 0, inf or NaN) differs in bits, maxrel > MCTOL, or REF has
856note no e line or no l line (a check that checked nothing fails).
857fn cmdmath to void
858if ne oargc 3
859exit 2
860end
861n = odread 2
862if ne rem n 36 0
863exit 21
864end
865for k ulong 6
866put og add 50 k 0
867end
868for i ulong div n 36
869omline mul i 36
870end
871omprint 101 0
872omprint 108 3
873if or gt bitcast f64 get og 52 MCTOL gt bitcast f64 get og 55 MCTOL
874exit 42
875end
876if or eq get og 50 0 eq get og 53 0
877exit 42
878end
879end
880
881fn ohex o ulong to ulong
882v = ulong 0
883for k ulong 16
884c = odb add o k
885if lt c 58
886v = or shl v 4 sub c 48
887else
888v = or shl v 4 sub c 87
889end
890end
891ret v
892end
893
894note og[50+b]: count, max ulp, max rel bits (b = 0 for exp, 3 for log)
895fn omline o ulong to void
896kd = odb o
897x = bitcast f64 ohex add o 2
898rb = ohex add o 19
899b = ulong 0
900y = 0.0f64
901if eq kd 101
902y = fexp x
903else
904b = ulong 3
905y = flog x
906end
907yb = bitcast ulong y
908put og add 50 b add get og add 50 b 1
909r = bitcast f64 rb
910if or or eq r 0.0 ne r r eq fabs r bitcast f64 ulong 9218868437227405312
911if ne yb rb
912exit 42
913end
914ret
915end
916ul = ulong 0
917if gt yb rb
918ul = sub yb rb
919else
920ul = sub rb yb
921end
922if gt ul get og add 51 b
923put og add 51 b ul
924end
925rel = div fabs sub y r fabs r
926if gt rel bitcast f64 get og add 52 b
927put og add 52 b bitcast ulong rel
928end
929end
930
931fn omprint c ulong b ulong to void
932oputc 77
933oputc 32
934oputc c
935oputc 32
936oputu get og add 50 b
937oputc 32
938oputu get og add 51 b
939oputc 32
940oputx get og add 52 b
941oputc 32
942oputl long mul bitcast f64 get og add 52 b 1e18
943oputc 10
944oflush
945end
946
947note tune CK OUT TOTAL LRMICRO: fine-tune entry. Load CK (any checkpoint ckpt.om accepts), keep
948note its shapes, G and weights, and start a new schedule on them: step 0, the given TOTAL and
949note lr = f64(LRMICRO)/1000000.0, Adam moments m = v = 0 (so warmup and bias correction restart).
950note Save to OUT with the loaded magic and print `U P`. train, gtrain and gtrainf then continue
951note from OUT on any token file. TOTAL 0 or over 999999 exits 12; wrong argument count exits 2.
952fn cmdtune to void
953if ne oargc 6
954exit 2
955end
956ockload 2
957tt = oargu 4
958if or eq tt 0 gt tt 999999
959exit 12
960end
961put og 41 0
962put og 42 tt
963put og 43 bitcast ulong div f64 oargu 5 1000000.0
964ozerom mul 2 get og 8
965ocksave 3
966oputc 85
967oputc 32
968oputu get og 8
969oputc 10
970oflush
971end
972
973
974note grow CK OUT L TOTAL LRMICRO: keep embeddings, old layers and final gain byte for byte.
975note Added layers use the own initializer with Wo and W2 zeroed, so both residual branches
976note initially contribute zero. Their input projections remain initialized and trainable.
977note The existing gradient cold store snapshots old weights while geometry changes; oinit
978note writes parameters and moments only. Since P grows, new moments cannot alias the snapshot.
979note Like tune, restart step and Adam, preserving seed, G, vocabulary and checkpoint format.
980note OUT uses normal checkpoint save semantics (an existing path is replaced).
981fn ogrowsnap n ulong to void
982for q ulong ocn n
983i = mul q OCH
984ie = oce q n
985while lt i ie bound 999999
986v = owg i
987note Reject non-finite source weights before attempting a growth operation.
988if eq and shr bitcast ulong v 52 2047 2047
989exit 54
990end
991ocsp i v
992i = add i 1
993end
994end
995end
996
997fn ogrowcopy n ulong to void
998for q ulong ocn n
999i = mul q OCH
1000ie = oce q n
1001while lt i ie bound 999999
1002owp i ocsg i
1003i = add i 1
1004end
1005end
1006end
1007
1008note Keep loop temporaries out of cmdgrow: every target must fit its register budget.
1009fn ogrowsilent first ulong to void
1010for j ulong sub get og 5 first
1011l = add first j
1012oiset opwo l mul get og 2 get og 2 0.0
1013oiset opw2 l mul get og 2 get og 4 0.0
1014end
1015end
1016
1017fn cmdgrow to void
1018if ne oargc 7
1019exit 2
1020end
1021ockload 2
1022ll = oargu 4
1023tt = oargu 5
1024lr = oargu 6
1025if or le ll get og 5 or eq tt 0 gt tt 999999
1026exit 12
1027end
1028if eq lr 0
1029exit 12
1030end
1031oldl = get og 5
1032oldg = get og 33
1033ogrowsnap get og 8
1034put og 5 ll
1035if not ogeom
1036exit 12
1037end
1038put og 41 0
1039put og 42 tt
1040put og 43 bitcast ulong div f64 lr 1000000.0
1041oinit
1042ogrowcopy oldg
1043for j ulong get og 2
1044owp add get og 33 j ocsg add oldg j
1045end
1046ogrowsilent oldl
1047ocksave 3
1048oputc 71
1049oputc 32
1050oputu oldl
1051oputc 32
1052oputu ll
1053oputc 32
1054oputu get og 8
1055oputc 10
1056oflush
1057end