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 / tools / omegallm / wpatch / wpbuild.om

798 lines · 15079 bytes Raw Blame History
1note SPDX-License-Identifier: AGPL-3.0-only
2note wpbuild: the Omega build driver for ollm, wpatch and its test driver wpcheck. CPU only.
3note Usage: wpbuild REPO OUT OMC OMEGA_MV CORE (all five required; CORE is a taskset core number).
4note Steps, in order (any failure prints one WPBUILD FAIL line and exits nonzero):
5note 1. Compiler pin: the sha256 of OMC (read from sha256sum) must equal OMCPIN.
6note 2. SHA-256: git show of om/sha256/sha256-om2.om at omega-mv pin e5b32567 into OUT/sha256-source.om;
7note its sha256 (read from sha256sum) must equal SHASRC.
8note 3. Vendoring, done here in Omega: the layout block (from the line `layout shactx 104` through the
9note next line `end`) goes to OUT/sha256-layout.om. Every other line except `om2` goes to
10note OUT/sha256-functions.om, with a leading `export fn ` made `fn `, and on lines that do not start
11note with `note` each whole word ([A-Za-z0-9_] run) in OLDW renamed to the word at the same position
12note in NEWW. OUT/sha256-vendored.om is `om2`, layout, functions; OUT/sha256.diff is diff -u of the
13note source against it (a review record, not an input).
14note 4. wpcheck: OUT/wpcheck-all.om is `om2`, layout, functions, wpcheck.om; compiled to OUT/wpcheck.
15note 5. Net pins: `OUT/wpcheck sum` (the vendored Omega SHA-256) of native/omegallm/net/http.om,
16note json.om and jsonw.om must equal NPHTTP, NPJSON and NPJSONW (the pins of the aarch64 ollm build).
17note 6. ollm: OUT/ollm.om is the line `om2`, then native/omegallm/ net/http.om net/json.om
18note net/jsonw.om math.om data.om lpool.om model.om adam.om ckpt.om bpe.om cli.om lio.om serve.om
19note nogpu.om, plain concatenation in that order (the aarch64 ollm source); compiled to OUT/ollm.
20note 7. wpatch: OUT/wpatch-all.om is `om2`, layout, OUT/ollm.om without its `om2` line and with
21note `fn main to int` (exactly one such line) renamed `fn wpollm to int`, functions, wpatch.om;
22note compiled to OUT/wpatch.
23note Each compile runs taskset -c CORE nice -n 19 OMC into a .new file, which is made executable and
24note renamed over the target. A compile error removes the .new file and exits with omc's status.
25note Finally sha256sum prints OMC, the SHA source, ollm.om, ollm, both compositions and both binaries.
26note Exit codes: 2 usage, 3 a pinned digest differs (compiler, SHA source or net source), 4 main
27note count, 5 I/O or capacity, 6 a tool failed (its status is printed), otherwise omc's own status.
28om2
29
30global sb uchar 65536
31global sl ulong 128
32global pb uchar 4096
33global pn ulong 1
34global av uchar 4096
35global ap ulong 2
36global stb uchar 4
37global inb uchar 8388608
38global bn ulong 1
39global ob uchar 8388608
40global obn ulong 1
41global lay uchar 4096
42global lan ulong 1
43global fns uchar 65536
44global fnn ulong 1
45global cap uchar 4096
46global capn ulong 1
47global dig uchar 32
48text PIN "e5b32567a7aff3ce594e3254a622a846a6cd190b:om/sha256/sha256-om2.om"
49text SHASRC "dbf002dd6aa36585632b9d01d98ac3f0bd2fa0f0475082940de53638847994bb"
50text OMCPIN "2c82480596bbdc50cda9626866209ef662d5834f278f839ff4ce0250c495029f"
51text NPHTTP "aff258ecd3858454056811a5e6fe1f660f9d650a7207d6c41885105110e046a7"
52text NPJSON "456254fc754ea35103ced480407b24fc1a3896d094b90ae0e9623e7b6594e2d2"
53text NPJSONW "464f649e8207495f5d67fe8795d31e42ea3ccebd9ed547274dab802d4f7c5f21"
54text SHTTP "/native/omegallm/net/http.om"
55text SJSON "/native/omegallm/net/json.om"
56text SJSONW "/native/omegallm/net/jsonw.om"
57text SMATH "/native/omegallm/math.om"
58text SDATA "/native/omegallm/data.om"
59text SLPOOL "/native/omegallm/lpool.om"
60text SMODEL "/native/omegallm/model.om"
61text SADAM "/native/omegallm/adam.om"
62text SCKPT "/native/omegallm/ckpt.om"
63text SBPE "/native/omegallm/bpe.om"
64text SCLI "/native/omegallm/cli.om"
65text SLIO "/native/omegallm/lio.om"
66text SSERVE "/native/omegallm/serve.om"
67text SNOGPU "/native/omegallm/nogpu.om"
68text CSUM "sum"
69text OLDW "kinit iv sched rounds compress run blocks finish tobuf absorb "
70text NEWW "wskinit wsiv wssched wsround wscomp wsrun wsblks wsfin wstobuf wsabsb "
71text GIT "/usr/bin/git"
72text GC "-C"
73text GSHOW "show"
74text SUM "/usr/bin/sha256sum"
75text DIFF "/usr/bin/diff"
76text DU "-u"
77text TSET "/usr/bin/taskset"
78text TC "-c"
79text NICE "/usr/bin/nice"
80text NN "-n"
81text N19 "19"
82text OM2 "om2"
83text LSTART "layout shactx 104"
84text LEND "end"
85text EXPFN "export fn "
86text NOTE "note"
87text MAINL "fn main to int"
88text WPOLLM "fn wpollm to int\n"
89text OM2NL "om2\n"
90text FSRC "/sha256-source.om"
91text FLAY "/sha256-layout.om"
92text FFNS "/sha256-functions.om"
93text FVEN "/sha256-vendored.om"
94text FDIF "/sha256.diff"
95text FOLLM "/ollm.om"
96text FONEW "/ollm.new"
97text FOL "/ollm"
98text FWPS "/tools/omegallm/wpatch/wpatch.om"
99text FCKS "/tools/omegallm/wpatch/wpcheck.om"
100text FWALL "/wpatch-all.om"
101text FCALL "/wpcheck-all.om"
102text FWNEW "/wpatch.new"
103text FCNEW "/wpcheck.new"
104text FWP "/wpatch"
105text FCK "/wpcheck"
106text MUSAGE "WPBUILD FAIL usage: wpbuild REPO OUT OMC OMEGA_MV CORE\n"
107text MIO "WPBUILD FAIL I/O or capacity: "
108text MTOOL "WPBUILD FAIL tool exit "
109text MSHA "WPBUILD FAIL SHA-256 source digest differs from the pin\n"
110text MOMCP "WPBUILD FAIL omc digest differs from the pin\n"
111text MNET "WPBUILD FAIL net source digest differs from the pin: "
112text MMAIN "WPBUILD FAIL ollm.om must hold exactly one line `fn main to int`, found "
113text MOMC "WPBUILD FAIL omc exit "
114text MOK "WPBUILD PASS\n"
115text NL "\n"
116
117note ---- output, slots and argument packets --------------------------------------------------
118fn say s view uchar * to void
119r = write 1 s 0 len s
120end
121fn saynum v ulong to void
122x = v
123n = ulong 0
124while ge x 10
125put dig n uchar add 48 rem x 10
126x = div x 10
127n = add n 1
128end
129put dig n uchar add 48 x
130for i ulong add n 1
131r = write 1 dig sub n i 1
132end
133end
134fn saypb to void
135r = write 1 pb 0 get pn 0
136end
137fn die c ulong m view uchar * to void
138say m
139exit int c
140end
141fn dieio to void
142say MIO
143saypb
144say NL
145exit 5
146end
147fn pclear to void
148put pn 0 0
149end
150fn pbyte b uchar to void
151n = get pn 0
152if ge n 4095
153dieio
154end
155put pb n b
156put pn 0 add n 1
157end
158fn ptext s view uchar * to void
159for i ulong len s
160pbyte get s i
161end
162end
163note Slot k is 512 bytes of sb at k * 512, its length in sl.
164fn pslot k ulong to void
165o = mul k 512
166for i ulong get sl k
167pbyte get sb add o i
168end
169end
170fn keepat k ulong to void
171n = get pn 0
172if gt n 512
173dieio
174end
175o = mul k 512
176for i ulong n
177put sb add o i get pb i
178end
179put sl k n
180end
181fn argslot i ulong k ulong to void
182r = argread i pb 0 512
183if le r 0
184die 2 MUSAGE
185end
186put pn 0 ulong r
187keepat k
188end
189note slot k = slot base followed by text s
190fn under k ulong base ulong s view uchar * to void
191pclear
192pslot base
193ptext s
194keepat k
195end
196fn aclear to void
197put ap 0 2
198put ap 1 0
199end
200fn apb to void
201p = get ap 0
202n = get pn 0
203if or gt add add p n 2 len av ge get ap 1 64
204dieio
205end
206put av p uchar and n 255
207put av add p 1 uchar shr n 8
208for i ulong n
209put av add add p 2 i get pb i
210end
211put ap 0 add add p 2 n
212put ap 1 add get ap 1 1
213end
214fn atext s view uchar * to void
215pclear
216ptext s
217apb
218end
219fn aslot k ulong to void
220pclear
221pslot k
222apb
223end
224fn popen k ulong fl int to int
225pclear
226pslot k
227r = fopen pb 0 get pn 0 fl 420
228if lt r 0
229dieio
230end
231ret int r
232end
233fn redir s int d int to void
234if ne s d
235if ne dupfd s d 0 long d
236exit 127
237end
238end
239end
240note Run the packet in av with stdin fi and stdout fo (-1 inherits); return the exit status, or
241note 256 + the signal number when the child was killed.
242fn spawn fi int fo int to ulong
243put av 0 uchar and get ap 1 255
244put av 1 uchar shr get ap 1 8
245pid = fork
246if lt pid 0
247dieio
248end
249if eq pid 0
250if ge fi 0
251redir fi 0
252end
253if ge fo 0
254redir fo 1
255end
256r = execprog av 0 get ap 0
257exit 127
258end
259if ge fi 0
260r = fclose fi
261end
262if ge fo 0
263r = fclose fo
264end
265w = waitpid int pid stb 0 4 0
266if ne w long pid
267dieio
268end
269if ne get stb 0 0
270ret add 256 ulong and get stb 0 127
271end
272ret ulong get stb 1
273end
274fn tool fi int fo int to void
275x = spawn fi fo
276if ne x 0
277say MTOOL
278saynum x
279say NL
280exit 6
281end
282end
283fn waitok pid long to void
284w = waitpid int pid stb 0 4 0
285bad = or ne get stb 0 0 ne get stb 1 0
286if or ne w pid bad
287say MTOOL
288saynum ulong get stb 1
289say NL
290exit 6
291end
292end
293note Run the packet with stdout read back through a pipe into cap (at most 4096 bytes).
294fn capture to void
295put av 0 uchar and get ap 1 255
296put av 1 uchar shr get ap 1 8
297pf = new uchar 8 0
298if ne pipefds pf 0 8 0 0
299dieio
300end
301rd = int or ulong get pf 0 shl ulong get pf 1 8
302wr = int or ulong get pf 4 shl ulong get pf 5 8
303pid = fork
304if lt pid 0
305dieio
306end
307if eq pid 0
308r = fclose rd
309redir wr 1
310r = execprog av 0 get ap 0
311exit 127
312end
313r = fclose wr
314n = ulong 0
315k = long 1
316while gt k 0
317k = read rd cap n sub len cap n
318if gt k 0
319n = add n ulong k
320end
321end
322r = fclose rd
323put capn 0 n
324waitok pid
325end
326
327note ---- whole files ---------------------------------------------------------------------------
328fn slurp k ulong to void
329fd = popen k 0
330n = ulong 0
331k2 = long 1
332while gt k2 0
333if eq n len inb
334dieio
335end
336k2 = read fd inb n sub len inb n
337if lt k2 0
338dieio
339end
340n = add n ulong k2
341end
342r = fclose fd
343put bn 0 n
344end
345fn obyte b uchar to void
346n = get obn 0
347if ge n len ob
348dieio
349end
350put ob n b
351put obn 0 add n 1
352end
353fn otext s view uchar * to void
354for i ulong len s
355obyte get s i
356end
357end
358fn obig o ulong n ulong to void
359for i ulong n
360obyte get inb add o i
361end
362end
363fn olay to void
364for i ulong get lan 0
365obyte get lay i
366end
367end
368fn ofns to void
369for i ulong get fnn 0
370obyte get fns i
371end
372end
373note Write ob to slot k, created or truncated.
374fn spill k ulong to void
375fd = popen k 577
376n = get obn 0
377p = ulong 0
378while lt p n
379r = write fd ob p sub n p
380if le r 0
381dieio
382end
383p = add p ulong r
384end
385if ne fclose fd 0
386dieio
387end
388put obn 0 0
389end
390
391note ---- line tests on inb -----------------------------------------------------------------------
392note end of the line starting at o (index of its LF, or bn)
393fn eol o ulong to ulong
394n = get bn 0
395e = o
396while lt e n
397if eq get inb e 10
398ret e
399end
400e = add e 1
401end
402ret n
403end
404fn lineis o ulong e ulong s view uchar * to bool
405if ne sub e o len s
406ret false
407end
408for i ulong len s
409if ne get inb add o i get s i
410ret false
411end
412end
413ret true
414end
415fn starts o ulong e ulong s view uchar * to bool
416if lt sub e o len s
417ret false
418end
419for i ulong len s
420if ne get inb add o i get s i
421ret false
422end
423end
424ret true
425end
426fn wordch c ulong to bool
427a = and ge c 48 le c 57
428b = and ge c 65 le c 90
429d = and ge c 97 le c 122
430ret or or a b or d eq c 95
431end
432note position (0..9) of inb[o..e) among the words of OLDW, or 10
433fn oldword o ulong e ulong to ulong
434w = ulong 0
435s = ulong 0
436for i ulong len OLDW
437if eq get OLDW i 32
438if eq sub i s sub e o
439same = true
440for j ulong sub i s
441if ne get OLDW add s j get inb add o j
442same = false
443end
444end
445if same
446ret w
447end
448end
449w = add w 1
450s = add i 1
451end
452end
453ret 10
454end
455fn fbyte b uchar to void
456n = get fnn 0
457if ge n len fns
458dieio
459end
460put fns n b
461put fnn 0 add n 1
462end
463fn newword w ulong to void
464k = ulong 0
465for i ulong len NEWW
466c = get NEWW i
467if eq c 32
468k = add k 1
469else
470if eq k w
471fbyte c
472end
473end
474end
475end
476note one functions line inb[o..e) plus its LF (when e < bn)
477fn fnline o ulong e ulong to void
478p = o
479if starts o e EXPFN
480p = add o 7
481end
482if starts o e NOTE
483for i ulong sub e p
484fbyte get inb add p i
485end
486else
487while lt p e
488if wordch ulong get inb p
489q = p
490while and lt q e wordch ulong get inb q
491q = add q 1
492end
493w = oldword p q
494if lt w 10
495newword w
496else
497for i ulong sub q p
498fbyte get inb add p i
499end
500end
501p = q
502else
503fbyte get inb p
504p = add p 1
505end
506end
507end
508if lt e get bn 0
509fbyte 10
510end
511end
512fn lbyte b uchar to void
513n = get lan 0
514if ge n len lay
515dieio
516end
517put lay n b
518put lan 0 add n 1
519end
520note Split the SHA source in inb into lay and fns (step 3).
521fn split to void
522n = get bn 0
523put lan 0 0
524put fnn 0 0
525o = ulong 0
526inl = false
527while lt o n
528e = eol o
529if inl
530for i ulong sub e o
531lbyte get inb add o i
532end
533lbyte 10
534if lineis o e LEND
535inl = false
536end
537else
538if lineis o e LSTART
539inl = true
540for i ulong sub e o
541lbyte get inb add o i
542end
543lbyte 10
544else
545if not lineis o e OM2
546fnline o e
547end
548end
549end
550o = add e 1
551end
552end
553note Append ollm.om (in inb) to ob without `om2` and with main renamed; return the main count.
554fn oollm to ulong
555n = get bn 0
556c = ulong 0
557o = ulong 0
558while lt o n
559e = eol o
560if lineis o e MAINL
561otext WPOLLM
562c = add c 1
563else
564if not lineis o e OM2
565obig o sub e o
566if lt e n
567obyte 10
568end
569end
570end
571o = add e 1
572end
573ret c
574end
575
576note ---- steps -----------------------------------------------------------------------------------
577note slots: 0 REPO, 1 OUT, 2 OMC, 3 OMEGA_MV, 4 CORE, 5 scratch, 6 source, 7 vendored, 8 all, 9 new
578note true when the captured output starts with the 64 hex digits s
579fn capis s view uchar * to bool
580if lt get capn 0 64
581ret false
582end
583for i ulong 64
584if ne get cap i get s i
585ret false
586end
587end
588ret true
589end
590fn stepomc to void
591aclear
592atext SUM
593aslot 2
594capture
595if not capis OMCPIN
596die 3 MOMCP
597end
598end
599fn stepsrc to void
600under 6 1 FSRC
601aclear
602atext GIT
603atext GC
604aslot 3
605atext GSHOW
606atext PIN
607tool -1 popen 6 577
608aclear
609atext SUM
610aslot 6
611capture
612if not capis SHASRC
613die 3 MSHA
614end
615end
616note `OUT/wpcheck sum REPO s` (vendored Omega SHA-256) must print the pin p.
617fn netpin s view uchar * p view uchar * to void
618under 5 1 FCK
619aclear
620aslot 5
621atext CSUM
622under 5 0 s
623aslot 5
624capture
625if not capis p
626say MNET
627pclear
628pslot 5
629saypb
630say NL
631exit 3
632end
633end
634note append the whole file REPO s to ob
635fn ofile s view uchar * to void
636under 5 0 s
637slurp 5
638obig 0 get bn 0
639end
640fn stepollm to void
641netpin SHTTP NPHTTP
642netpin SJSON NPJSON
643netpin SJSONW NPJSONW
644otext OM2NL
645ofile SHTTP
646ofile SJSON
647ofile SJSONW
648ofile SMATH
649ofile SDATA
650ofile SLPOOL
651ofile SMODEL
652ofile SADAM
653ofile SCKPT
654ofile SBPE
655ofile SCLI
656ofile SLIO
657ofile SSERVE
658ofile SNOGPU
659under 8 1 FOLLM
660spill 8
661under 9 1 FONEW
662compile FOL
663end
664fn stepvend to void
665slurp 6
666split
667under 5 1 FLAY
668olay
669spill 5
670under 5 1 FFNS
671ofns
672spill 5
673under 7 1 FVEN
674otext OM2NL
675olay
676ofns
677spill 7
678under 5 1 FDIF
679aclear
680atext DIFF
681atext DU
682aslot 6
683aslot 7
684x = spawn -1 popen 5 577
685if ne x 1
686say MTOOL
687saynum x
688say NL
689exit 6
690end
691end
692fn compose to void
693under 5 1 FOLLM
694slurp 5
695otext OM2NL
696olay
697c = oollm
698if ne c 1
699say MMAIN
700saynum c
701say NL
702exit 4
703end
704ofns
705under 5 0 FWPS
706slurp 5
707obig 0 get bn 0
708under 8 1 FWALL
709spill 8
710end
711fn composeck to void
712otext OM2NL
713olay
714ofns
715under 5 0 FCKS
716slurp 5
717obig 0 get bn 0
718under 8 1 FCALL
719spill 8
720end
721note Compile slot 8 into slot 9 (the .new file), then rename it to dst (a text under OUT).
722fn compile dst view uchar * to void
723aclear
724atext TSET
725atext TC
726aslot 4
727atext NICE
728atext NN
729atext N19
730aslot 2
731x = spawn popen 8 0 popen 9 577
732if ne x 0
733pclear
734pslot 9
735r = unlink pb 0 get pn 0
736say MOMC
737saynum x
738say NL
739exit int x
740end
741pclear
742pslot 9
743if ne chmod pb 0 get pn 0 493 0
744dieio
745end
746under 5 1 dst
747aclear
748aslot 9
749aslot 5
750put av 0 2
751put av 1 0
752if ne renames av 0 get ap 0 0 0
753dieio
754end
755end
756fn main to int
757if ne argcnt 6
758die 2 MUSAGE
759end
760for i ulong 5
761argslot add i 1 i
762end
763pclear
764pslot 1
765r = makedir pb 0 get pn 0 493
766if and lt r 0 ne r -17
767dieio
768end
769stepomc
770stepsrc
771stepvend
772composeck
773under 9 1 FCNEW
774compile FCK
775stepollm
776compose
777under 9 1 FWNEW
778compile FWP
779aclear
780atext SUM
781aslot 2
782aslot 6
783under 5 1 FOLLM
784aslot 5
785under 5 1 FOL
786aslot 5
787under 5 1 FCALL
788aslot 5
789under 5 1 FCK
790aslot 5
791under 5 1 FWALL
792aslot 5
793under 5 1 FWP
794aslot 5
795tool -1 -1
796say MOK
797ret 0
798end