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 / tools / wdrive / wcheck.om

506 lines · 9324 bytes Raw Blame History
1note SPDX-License-Identifier: AGPL-3.0-only
2note wcheck.om (DRA-187, lane wsp): outside check of `wprobe save`. Composed after wbuild.om:
3note OMC=omc wbuild OUT/wcheck tools/omegallm/wdrive/wbuild.om@wbmain tools/omegallm/wdrive/wcheck.om
4note Usage: wcheck BUILD_DIR [MILLI] (BUILD_DIR holds ollm and wprobe)
5note In a fresh /tmp/wcheck-<realtime ns> directory it makes a small checkpoint
6note (ollm init base.ck 256 8 16 2 32 2 2 1 10 3000 1, then ollm train base.ck tr.bin 2 1 on 200 copies
7note of "abc abcd abcde" and a zero byte) and checks eight cases, printing CASE <name> PASS|FAIL each:
8note edit wprobe save base e1 1 1 1 1500 2 0 7 250 exits 0; header words 0..13 kept; word 14 is the
9note FNV-1a 64 of every byte after the header; the attention output rows of layer 1 head 1 are
10note the base value times MILLI/1000 (default 1500, so 1.5), the w2 rows of layer 0 neuron 7
11note times 0.25, every other weight and the whole optimizer state equal (f64 comparison)
12note f32 wprobe save base f32 5 0 0 0 exits 0; every weight is the base weight rounded to f32 and
13note back, and at least one differs from the base
14note exists save onto the existing e1 exits 63
15note act kind 3 (activation hook) exits 2
16note dec kind 4 (decoding hook) exits 2
17note badhook kind 1 at layer 2 of 2 exits 2
18note nofiles the three refused saves left no file
19note big a checkpoint with weight 5 set to 2.0e6 (payload FNV rewritten) exits 64, writes nothing
20note Rows (as tools/omegallm/wprobe/check.py had them): lay0 = V*D + T*D, lstr = 4*D*D + 2*D*F + 2*D,
21note wo(l) = lay0 + l*lstr + D + 3*D*D, w2(l) = lay0 + l*lstr + D + 4*D*D + D + D*F, E = D/H; the head
22note rows are [wo(1) + E*D, wo(1) + 2*E*D), the neuron rows [w2(0) + 7*D, w2(0) + 8*D).
23note Prints WPROBE_SAVE_CHECK PASS 8 cases and exits 0, or WPROBE_SAVE_CHECK FAIL <passed> of 8 cases
24note and exits 1. MILLI other than 1500 is the negative control: the edit case must then FAIL.
25note Exits 2 usage, 70 I/O, 1 also when the small checkpoint cannot be made (SETUP_FAIL).
26
27global wcb uchar 1048576
28global wcbn ulong 1
29global wcbd uchar 4096
30global wcbdn ulong 1
31global wctd uchar 256
32global wctdn ulong 1
33note wclay: head rows start, end, neuron rows start, end
34global wclay ulong 4
35global wcok ulong 1
36global wcnul int 1
37text wctmp "/tmp/wcheck-"
38text wcollm "ollm"
39text wcwp "wprobe"
40text wcinit "init"
41text wctrain "train"
42text wcsave "save"
43text wcfbase "base.ck"
44text wcftr "tr.bin"
45text wcfe1 "e1.ck"
46text wcff32 "f32.ck"
47text wcfa3 "a3.ck"
48text wcfa4 "a4.ck"
49text wcfbad "bad.ck"
50text wcfbig "big.ck"
51text wcfbo "big-out.ck"
52text wcnull "/dev/null"
53text wctrrec "abc abcd abcde"
54text wccase "CASE "
55text wcpass " PASS\n"
56text wcfail " FAIL\n"
57text wcsedit "edit"
58text wcsf32 "f32"
59text wcsex "exists"
60text wcsact "act"
61text wcsdec "dec"
62text wcsbad "badhook"
63text wcsnof "nofiles"
64text wcsbig "big"
65text wcok8 "WPROBE_SAVE_CHECK PASS 8 cases\n"
66text wcbad8 "WPROBE_SAVE_CHECK FAIL "
67text wcof8 " of 8 cases\n"
68text wcsetup "SETUP_FAIL "
69text wcnl "\n"
70text wcuse "usage: wcheck BUILD_DIR [MILLI]\n"
71
72fn wcusage to void
73wdoclr
74wdot wcuse
75wdoflush 2
76exit 2
77end
78
79note BUILD_DIR/t and TMP/t into the path builder
80fn wcpb t view uchar * to void
81wdpclr
82for j ulong get wcbdn 0
83wdpc ulong get wcbd j
84end
85wdpc 47
86wdpt t
87end
88
89fn wcpt t view uchar * to void
90wdpclr
91for j ulong get wctdn 0
92wdpc ulong get wctd j
93end
94wdpc 47
95wdpt t
96end
97
98fn wckt t view uchar * to void
99wcpt t
100wdkp
101end
102
103fn wckn v ulong to void
104wdpclr
105wdpd v
106wdkp
107end
108
109note run the packed list with stdout and stderr to /dev/null; its exit status
110fn wcrun to long
111pid = wdspawn -1 get wcnul 0 get wcnul 0
112ret wdwait pid
113end
114
115note wprobe save SRC OUT; the caller adds the hook words (wch4) before wcrun
116fn wcsv src view uchar * dst view uchar * to void
117wdkclr
118wcpb wcwp
119wdkp
120wdkt wcsave
121wckt src
122wckt dst
123end
124
125fn wch4 k ulong l ulong i ulong a ulong to void
126wckn k
127wckn l
128wckn i
129wckn a
130end
131
132fn wccase1 nm view uchar * ok bool to void
133wdoclr
134wdot wccase
135wdot nm
136if ok
137wdot wcpass
138put wcok 0 add get wcok 0 1
139else
140wdot wcfail
141end
142wdoflush 1
143end
144
145fn wcsetupf nm view uchar * to void
146wdoclr
147wdot wcsetup
148wdot nm
149wdot wcnl
150wdoflush 2
151wcclean
152exit 1
153end
154
155note little-endian u64 at byte o of wcb, of wdsrc; store into wdsrc
156fn wcbu o ulong to ulong
157x = ulong 0
158for k ulong 8
159x = or x shl ulong get wcb add o k mul k 8
160end
161ret x
162end
163
164fn wcsu o ulong to ulong
165x = ulong 0
166for k ulong 8
167x = or x shl ulong get wdsrc add o k mul k 8
168end
169ret x
170end
171
172fn wcsput o ulong v ulong to void
173for k ulong 8
174put wdsrc add o k uchar and shr v mul k 8 255
175end
176end
177
178fn wcbf i ulong to f64
179ret bitcast f64 wcbu add 120 mul i 8
180end
181
182fn wcsf i ulong to f64
183ret bitcast f64 wcsu add 120 mul i 8
184end
185
186note FNV-1a 64 of wdsrc[120 .. size)
187fn wcfnv to ulong
188x = ulong 14695981039346656037
189n = get wdsn 0
190i = ulong 120
191while lt i n bound 999999
192x = mul xor x ulong get wdsrc i 1099511628211
193i = add i 1
194end
195ret x
196end
197
198note load TMP/t into wdsrc; false unless it holds the header and 3 * P words
199fn wcload t view uchar * to bool
200wcpt t
201r = wdload
202if lt r 0
203ret false
204end
205if lt ulong r 120
206ret false
207end
208p = wcsu 96
209ret ge ulong r add 120 mul 24 p
210end
211
212fn wclayout to void
213v = wcbu 8
214t = wcbu 16
215d = wcbu 24
216h = wcbu 32
217f = wcbu 40
218ls = add add mul mul 4 d d mul mul 2 d f mul 2 d
219l0 = add mul v d mul t d
220wo1 = add add add l0 ls d mul mul 3 d d
221w20 = add add add add l0 d mul mul 4 d d d mul d f
222e = div d h
223put wclay 0 add wo1 mul e d
224put wclay 1 add wo1 mul mul 2 e d
225put wclay 2 add w20 mul 7 d
226put wclay 3 add w20 mul 8 d
227end
228
229fn wcwant i ulong a f64 s f64 to f64
230if and ge i get wclay 0 lt i get wclay 1
231ret mul a s
232end
233if and ge i get wclay 2 lt i get wclay 3
234ret mul a 0.25f64
235end
236ret a
237end
238
239note the edit case on e1 in wdsrc, expected head factor milli / 1000
240fn wcedit milli ulong to bool
241if ne get wdsn 0 get wcbn 0
242ret false
243end
244for i ulong 14
245if ne wcbu mul i 8 wcsu mul i 8
246ret false
247end
248end
249if ne wcsu 112 wcfnv
250ret false
251end
252s = div f64 milli 1000.0f64
253m = mul wcbu 96 3
254j = ulong 0
255while lt j m bound 999999
256if ne wcsf j wcwant j wcbf j s
257ret false
258end
259j = add j 1
260end
261ret true
262end
263
264fn wcf32 to bool
265n = wcbu 96
266d = ulong 0
267j = ulong 0
268while lt j n bound 999999
269a = wcbf j
270b = wcsf j
271if ne b f64 f32 a
272ret false
273end
274if ne b a
275d = add d 1
276end
277j = add j 1
278end
279ret gt d 0
280end
281
282note write wdsrc[0 .. size) to TMP/t
283fn wcwrite t view uchar * to void
284wcpt t
285fd = wdopen 577 420
286if lt fd 0
287exit 70
288end
289n = get wdsn 0
290k = ulong 0
291while lt k n bound 999999
292w = write fd wdsrc k sub n k
293if le w 0
294exit 70
295end
296k = add k ulong w
297end
298c = fclose fd
299end
300
301fn wcgone t view uchar * to bool
302wcpt t
303ret not wdexists
304end
305
306fn wcrm t view uchar * to void
307wcpt t
308u = unlink wdp 0 get wdpn 0
309end
310
311fn wcclean to void
312wcrm wcfbase
313wcrm wcftr
314wcrm wcfe1
315wcrm wcff32
316wcrm wcfa3
317wcrm wcfa4
318wcrm wcfbad
319wcrm wcfbig
320wcrm wcfbo
321wdpclr
322for j ulong get wctdn 0
323wdpc ulong get wctd j
324end
325r = rmdir wdp 0 get wdpn 0
326end
327
328note the small checkpoint: init, the training file, train; then base bytes into wcb
329fn wcmake to void
330wdkclr
331wcpb wcollm
332wdkp
333wdkt wcinit
334wckt wcfbase
335wckn 256
336wckn 8
337wckn 16
338wckn 2
339wckn 32
340wckn 2
341wckn 2
342wckn 1
343wckn 10
344wckn 3000
345wckn 1
346if ne wcrun 0
347wcsetupf wcinit
348end
349wcpt wcftr
350fd = wdopen 577 420
351if lt fd 0
352exit 70
353end
354wdoclr
355for i ulong 200
356wdot wctrrec
357wdoc 0
358end
359wdoflush fd
360c = fclose fd
361wdkclr
362wcpb wcollm
363wdkp
364wdkt wctrain
365wckt wcfbase
366wckt wcftr
367wckn 2
368wckn 1
369if ne wcrun 0
370wcsetupf wctrain
371end
372if not wcload wcfbase
373wcsetupf wcfbase
374end
375n = get wdsn 0
376if gt n 1048576
377wcsetupf wcfbase
378end
379for j ulong n
380put wcb j get wdsrc j
381end
382put wcbn 0 n
383wclayout
384end
385
386note the big-weight checkpoint from wcb
387fn wcmkbig to void
388n = get wcbn 0
389for j ulong n
390put wdsrc j get wcb j
391end
392put wdsn 0 n
393wcsput 160 bitcast ulong 2000000.0f64
394wcsput 112 wcfnv
395wcwrite wcfbig
396end
397
398fn wccases milli ulong to void
399wcsv wcfbase wcfe1
400wch4 1 1 1 1500
401wch4 2 0 7 250
402ok = eq wcrun 0
403if ok
404ok = wcload wcfe1
405end
406if ok
407ok = wcedit milli
408end
409wccase1 wcsedit ok
410wcsv wcfbase wcff32
411wch4 5 0 0 0
412ok2 = eq wcrun 0
413if ok2
414ok2 = wcload wcff32
415end
416if ok2
417ok2 = wcf32
418end
419wccase1 wcsf32 ok2
420wcsv wcfbase wcfe1
421wch4 1 1 1 1500
422wccase1 wcsex eq wcrun 63
423wcsv wcfbase wcfa3
424wch4 3 1 1 1500
425wccase1 wcsact eq wcrun 2
426wcsv wcfbase wcfa4
427wch4 4 0 46 1000
428wccase1 wcsdec eq wcrun 2
429wcsv wcfbase wcfbad
430wch4 1 2 0 1000
431wccase1 wcsbad eq wcrun 2
432wccase1 wcsnof and and wcgone wcfa3 wcgone wcfa4 wcgone wcfbad
433wcmkbig
434wcsv wcfbig wcfbo
435wch4 1 0 0 1000
436ok3 = eq wcrun 64
437wccase1 wcsbig and ok3 wcgone wcfbo
438end
439
440fn wcparse i ulong to ulong
441n = wdarg i
442if or eq n 0 gt n 9
443wcusage
444end
445v = ulong 0
446for j ulong n
447c = ulong get wdab j
448if or lt c 48 gt c 57
449wcusage
450end
451v = add mul v 10 sub c 48
452end
453ret v
454end
455
456fn main to int
457na = argcnt
458if or lt na 2 gt na 3
459wcusage
460end
461milli = ulong 1500
462if eq na 3
463milli = wcparse 2
464end
465n = wdarg 1
466if gt n 4000
467wcusage
468end
469for j ulong n
470put wcbd j get wdab j
471end
472put wcbdn 0 n
473wdpclr
474wdpt wctmp
475wdpd ulong realns
476for j2 ulong get wdpn 0
477put wctd j2 get wdp j2
478end
479put wctdn 0 get wdpn 0
480r = makedir wdp 0 get wdpn 0 448
481if ne r 0
482exit 70
483end
484wdpclr
485wdpt wcnull
486fd = wdopen 1 0
487if lt fd 0
488exit 70
489end
490put wcnul 0 fd
491wcmake
492wccases milli
493wcclean
494k = get wcok 0
495wdoclr
496if eq k 8
497wdot wcok8
498wdoflush 1
499ret 0
500end
501wdot wcbad8
502wdod k
503wdot wcof8
504wdoflush 1
505ret 1
506end