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