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

315 lines · 6184 bytes Raw Blame History
1note SPDX-License-Identifier: AGPL-3.0-only
2note wpolicy.om (DRA-187, lane wsp): PREREG section 9 driver. Composed after wbuild.om:
3note OMC=omc wbuild OUT/wpolicy tools/omegallm/wdrive/wbuild.om@wbmain tools/omegallm/wdrive/wpolicy.om
4note Usage: wpolicy prep|run BASE P0 P2 WORKDIR
5note BASE is the unedited checkpoint, P0 the edit with Adam m and v kept (wpatch policy 0 or wprobe save),
6note P2 the same edit applied by wpatch with policy 2 (m and v of the changed entries zeroed).
7note Both modes first run `WPROBE survive BASE P0 BASE P0 P2` and print its line after PRE: it exits 67
8note when P2's weights differ from P0's and 68 when P0 changes nothing. Then each of BASE, P0, P2 is
9note copied to WORKDIR/base.ck, p0.ck, p2.ck; its header word 9 (step) and word 10 (total) must both be
10note 600, and word 10 is set to 601 so that `ollm train` takes exactly one step (the payload FNV covers
11note only the payload, so it stays valid). Prints PREP NAME PATH per copy.
12note run then trains each copy one step on TRAIN, stdout to WORKDIR/NAME.train.log, printing
13note TRAIN NAME RC LOG, and prints the edit survival of each policy against the base's own step:
14note p0 S ... from WPROBE survive BASE P0 WORKDIR/base.ck WORKDIR/p0.ck P2
15note p2 S ... from WPROBE survive BASE P2 WORKDIR/base.ck WORKDIR/p2.ck
16note (wprobe's survive: changed count, survival <d1,d0>/<d0,d0>, largest |d1 - d0| / |d0|).
17note Every child runs under the pool lock LOCK (taken in this process with flock(2), at most 7200 s, as
18note `flock -w 7200 -o` did; a timeout counts as exit status 1), with an empty environment, as
19note /usr/bin/taskset -c POOL /usr/bin/nice -n 10 ...
20note Environment: HOME (required), POOL (default 19), LOCK (default HOME/handoffs/hive/queen/pool-POOL.lock),
21note OLLM (default HOME/work/wsp/build/ollm), WPROBE (default HOME/work/wsp/build/wprobe), TRAIN (default
22note HOME/handoffs/tool-omega-20261104/round40/data/train.tok).
23note Exits: 0 done, 1 a child exited nonzero (stderr FAIL STEP rc=N), 2 usage, 65 a header is not at
24note step 600 of 600 (stderr HEADER NAME STEP TOTAL), 70 I/O.
25
26note string slots (wdz, see wbuild.om): 0 HOME, 1 POOL, 2 LOCK, 3 OLLM, 4 WPROBE, 5 TRAIN, 6 BASE,
27note 7 P0, 8 P2, 9 WORKDIR, 10 11 12 the copies WORKDIR/base.ck, p0.ck, p2.ck
28text wptollm "OLLM"
29text wptwp "WPROBE"
30text wpttr "TRAIN"
31text wpdollm "/work/wsp/build/ollm"
32text wpdwp "/work/wsp/build/wprobe"
33text wpdtr "/handoffs/tool-omega-20261104/round40/data/train.tok"
34text wpprep "prep"
35text wprun "run"
36text wpsvt "survive"
37text wptrain "train"
38text wp601 "601"
39text wpone "1"
40text wpkb "base"
41text wpk0 "p0"
42text wpk2 "p2"
43text wpsck ".ck"
44text wpslog ".train.log"
45text wppre "PRE "
46text wpprp "PREP "
47text wptrn "TRAIN "
48text wphdr "HEADER "
49text wpfail "FAIL "
50text wprc " rc="
51text wpcantt "cannot open "
52text wpnl "\n"
53text wpuse "usage: wpolicy prep|run BASE P0 P2 WORKDIR\n"
54
55fn wpusage to void
56wdoclr
57wdot wpuse
58wdoflush 2
59exit 2
60end
61
62note argument bytes wdab[0 .. n) equal t
63fn wpargeq n ulong t view uchar * to bool
64if ne n len t
65ret false
66end
67for j ulong n
68if ne get wdab j get t j
69ret false
70end
71end
72ret true
73end
74
75note the name of copy i (0 base, 1 p0, 2 p2) to the output, to the path builder
76fn wponame i ulong to void
77if eq i 0
78wdot wpkb
79end
80if eq i 1
81wdot wpk0
82end
83if eq i 2
84wdot wpk2
85end
86end
87
88fn wppname i ulong to void
89if eq i 0
90wdpt wpkb
91end
92if eq i 1
93wdpt wpk0
94end
95if eq i 2
96wdpt wpk2
97end
98end
99
100note WORKDIR/NAME followed by sfx
101fn wpdst i ulong sfx view uchar * to void
102wdpclr
103wdzp 9
104wdpc 47
105wppname i
106wdpt sfx
107end
108
109fn wpslot k ulong to void
110wdpclr
111wdzp k
112wdkp
113end
114
115note the path in wdp could not be opened
116fn wpcant to void
117wdoclr
118wdot wpcantt
119wdop
120wdot wpnl
121wdoflush 2
122exit 70
123end
124
125fn wpfailx st view uchar * rc long to void
126wdoclr
127wdot wpfail
128wdot st
129wdot wprc
130wdod ulong rc
131wdot wpnl
132wdoflush 2
133exit 1
134end
135
136note survive BASE EDIT BASE1 EDIT1 [EDIT2] from slots; e2 0 leaves EDIT2 out. Prints pre first, then
137note wprobe's line follows on the same stdout.
138fn wpsurv a ulong b ulong c ulong d ulong e2 ulong to void
139wdkpre
140wpslot 4
141wdkt wpsvt
142wpslot a
143wpslot b
144wpslot c
145wpslot d
146if gt e2 0
147wpslot e2
148end
149rc = wdpoolrun -1 -1 -1
150if ne rc 0
151wpfailx wpsvt rc
152end
153end
154
155fn wpu64 h view uchar * o ulong to ulong
156x = ulong 0
157for k ulong 8
158x = or x shl ulong get h add o k mul k 8
159end
160ret x
161end
162
163note copy source slot 6 + i to WORKDIR/NAME.ck; check and raise the header's total
164fn wpcopy i ulong to void
165h = new uchar 120 0
166wdpclr
167wdzp add 6 i
168fi = wdopen 0 0
169if lt fi 0
170wpcant
171end
172wpdst i wpsck
173fo = wdopen 578 436
174if lt fo 0
175wpcant
176end
177wdcopyfd fi fo
178c = fclose fi
179r = pread fo h 0 120 0
180if ne r 120
181exit 70
182end
183st = wpu64 h 72
184tot = wpu64 h 80
185if or ne st 600 ne tot 600
186wdoclr
187wdot wphdr
188wponame i
189wdoc 32
190wdod st
191wdoc 32
192wdod tot
193wdot wpnl
194wdoflush 2
195exit 65
196end
197v = ulong 601
198for k ulong 8
199put h k uchar and shr v mul k 8 255
200end
201w = pwrite fo h 0 8 80
202if ne w 8
203exit 70
204end
205c2 = fclose fo
206if ne c2 0
207exit 70
208end
209wdoclr
210wdot wpprp
211wponame i
212wdoc 32
213wpdst i wpsck
214wdop
215wdot wpnl
216wdoflush 1
217end
218
219note one training step of WORKDIR/NAME.ck, stdout to WORKDIR/NAME.train.log
220fn wptrain1 i ulong to void
221wpdst i wpslog
222fo = wdopen 577 436
223if lt fo 0
224wpcant
225end
226wdkpre
227wpslot 3
228wdkt wptrain
229wpdst i wpsck
230wdkp
231wpslot 5
232wdkt wp601
233wdkt wpone
234rc = wdpoolrun -1 fo -1
235c = fclose fo
236wdoclr
237wdot wptrn
238wponame i
239wdoc 32
240wdod ulong rc
241wdoc 32
242wpdst i wpslog
243wdop
244wdot wpnl
245wdoflush 1
246if ne rc 0
247wpfailx wptrain rc
248end
249end
250
251note copy i's path into slot 10 + i
252fn wpsetdst i ulong to void
253wpdst i wpsck
254wdzsave add 10 i
255end
256
257fn wpsetup to void
258wdzpool
259wdzenv wptollm 3 wpdollm
260wdzenv wptwp 4 wpdwp
261wdzenv wpttr 5 wpdtr
262for i ulong 4
263wdpclr
264wdpa add i 2
265wdzsave add i 6
266end
267end
268
269fn main to int
270if ne argcnt 6
271wpusage
272end
273n = wdarg 1
274md = ulong 0
275if wpargeq n wpprep
276md = 1
277end
278if wpargeq n wprun
279md = 2
280end
281if eq md 0
282wpusage
283end
284wpsetup
285wdpclr
286wdzp 9
287m = makedir wdp 0 get wdpn 0 509
288for i ulong 3
289wpsetdst i
290end
291wdoclr
292wdot wppre
293wdoflush 1
294wpsurv 6 7 6 7 8
295for i2 ulong 3
296wpcopy i2
297end
298if eq md 1
299ret 0
300end
301for i3 ulong 3
302wptrain1 i3
303end
304wdoclr
305wdot wpk0
306wdoc 32
307wdoflush 1
308wpsurv 6 7 10 11 8
309wdoclr
310wdot wpk2
311wdoc 32
312wdoflush 1
313wpsurv 6 8 10 12 0
314ret 0
315end