interplane.Get Omega
Read in your language

omega-mv

Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.

Brought by drakestapleton

branch main Branches Tags History

omega-mv / train / omega-llm / native / cli.om

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