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/aien-train/blob/main/tests/omegese45/core/main.om # 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 Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `aien-train / tests / omegese45 / core / main.om` 546 lines ยท 8847 bytes Raw Blame History 1 note SPDX-License-Identifier: AGPL-3.0-only 2 note oe45core test driver (aien-train #45, pipeline lane). Replaces core/cli.om in the 3 note build: SHA unit, vocab.om, msg.om, core/model.om, core/ckpt.om, core/run.om, this file. 4 note grad CKDIR TRAIN.ids finite-difference gradient check rc 0 | 86 5 note ldec CKDIR TRAIN.ids N loss over N episodes falls after one pass rc 0 | 87 6 note mask TRAIN.ids K dump target and A/P mask of K episodes rc 0 7 note leak CKDIR TRAIN.ids causal no-leak and its negative control rc 0 | 88 8 note force SRC DST K K 1: b2[mm] = 100, 2: b2[end] = 100, 3: wrong vocab pin 9 note rt SRC DST load SRC, save into DST rc 0 10 note vgen OE45 IDS every episode valid, ids == encoded text rc 0 | 40 11 note vok FILE count batch result lines and validate ok lines 12 note Finite-difference step eps = 2^-6 = 0.015625 (2 eps = 0.03125), exact in f32. 13 global optg ulong 1200 14 global optga f32 1200 15 global optn ulong 1 16 global opx2 uchar `4194305` 17 global opx2n ulong 1 18 global opcm uchar 16 19 text optgc "GC " 20 text optld "LD " 21 text optnl "NL " 22 text optvg "VG " 23 text optvk "VK " 24 text opth "oe45 v1\n" 25 26 fn opputb b bool to void 27 if b 28 ocputc 49 29 else 30 ocputc 48 31 end 32 end 33 34 note Replace the id at position p by another non-pad id (1 + (id + 7) mod 40). 35 fn opalt p ulong to void 36 v = ulong get opseq p 37 put opseq p uchar add 1 rem add v 7 40 38 end 39 40 fn opfabs x f32 to f32 41 if lt x 0.0f32 42 ret sub 0.0f32 x 43 end 44 ret x 45 end 46 47 fn opgadd i ulong g f32 to void 48 n = get optn 0 49 put optg n i 50 put optga n g 51 put optn 0 add n 1 52 end 53 54 fn oplos2 t ulong to f32 55 opfeat t 56 opfwd 57 ret oploss optgt t 58 end 59 60 note Record analytic gradients at position t: all of b2, and for sampled hidden units away 61 note from the ReLU kink: b1, nine W2 entries and the first and last active W1 rows. 62 fn opgrec t ulong to void 63 put optn 0 0 64 l = opgrad t 65 for v ulong OPV 66 opgadd add add OPW1N add OPH OPW2N v get opgy v 67 end 68 for q ulong 16 69 j = mul q 17 70 if gt opfabs get ophp j 0.`03125f32` 71 opgadd add OPW1N j get opgh j 72 for u ulong 9 73 v = mul u 5 74 q2 = add add OPW1N OPH add mul j OPV v 75 g2 = mul get oph j get opgy v 76 opgadd q2 g2 77 end 78 if gt get opfn 0 0 79 gv = get opgh j 80 fa = get opfx 0 81 opgadd add mul fa OPH j gv 82 fb = get opfx sub get opfn 0 1 83 opgadd add mul fb OPH j gv 84 end 85 end 86 end 87 end 88 89 note Central difference for parameter i at position t (restores the parameter). 90 fn opfd i ulong t ulong to f32 91 x = opgetp i 92 opsetp i add x 0.`015625f32` 93 lp = oplos2 t 94 opsetp i sub x 0.`015625f32` 95 lm = oplos2 t 96 opsetp i x 97 ret div sub lp lm 0.`03125f32` 98 end 99 100 note Tolerance |fd - g| <= 0.001 + 0.01 |g|. 101 fn opgok fd f32 g f32 to bool 102 tol = add 0.001f32 mul 0.01f32 opfabs g 103 ret le opfabs sub fd g tol 104 end 105 106 note Central differences for the recorded entries; returns the number of failures. 107 fn opgchk t ulong to ulong 108 bad = ulong 0 109 for k ulong get optn 0 110 fd = opfd get optg k t 111 if not opgok fd get optga k 112 bad = add bad 1 113 end 114 end 115 ret bad 116 end 117 118 fn optgrad to int 119 if ne argcnt 4 120 exit 2 121 end 122 opckdir 2 123 opload 124 opldat 3 125 opepi 0 126 n = get opsl 0 127 bad = ulong 0 128 tot = ulong 0 129 for q ulong 3 130 t = add 1 div mul q sub n 2 2 131 opgrec t 132 bad = add bad opgchk t 133 tot = add tot get optn 0 134 end 135 w = write 1 optgc 0 3 136 ocputn tot 137 ocputc 32 138 ocputn bad 139 ocputc 10 140 if ne bad 0 141 exit 86 142 end 143 ret 0 144 end 145 146 note Sum of per-position loss over episodes [0, n). 147 fn oplsum n ulong to f32 148 s = 0.0f32 149 for e ulong n 150 opepi e 151 for t ulong get opsl 0 152 s = add s oplos2 t 153 end 154 end 155 ret s 156 end 157 158 fn optldec to int 159 if ne argcnt 5 160 exit 2 161 end 162 opckdir 2 163 opload 164 opldat 3 165 n = opdecu 4 166 if or eq n 0 gt n get opne 0 167 exit 2 168 end 169 a = oplsum n 170 lr = bitcast f32 uint get opmeta 6 171 for e ulong n 172 opepi e 173 l = optrep 1 lr 174 end 175 b = oplsum n 176 w = write 1 optld 0 3 177 ocputn ulong bitcast uint a 178 ocputc 32 179 ocputn ulong bitcast uint b 180 ocputc 10 181 if ge b a 182 exit 87 183 end 184 ret 0 185 end 186 187 fn optmask to int 188 if ne argcnt 4 189 exit 2 190 end 191 opldat 2 192 k = opdecu 3 193 if gt k get opne 0 194 exit 2 195 end 196 for e ulong k 197 opepi e 198 opmask 199 for t ulong get opsl 0 200 ocputc 77 201 ocputc 32 202 ocputn e 203 ocputc 32 204 ocputn t 205 ocputc 32 206 ocputn optgt t 207 ocputc 32 208 ocputn ulong get opmk t 209 ocputc 10 210 end 211 end 212 ret 0 213 end 214 215 note 1 when the outputs equal the saved bits in opsv-like local copies. 216 fn opysame y edit f32 41 to bool 217 for v ulong OPV 218 if ne bitcast uint get opy v bitcast uint get y v 219 ret false 220 end 221 end 222 ret true 223 end 224 225 fn optleak to int 226 if ne argcnt 4 227 exit 2 228 end 229 opckdir 2 230 opload 231 opldat 3 232 opepi 0 233 n = get opsl 0 234 t = div n 2 235 y0 = new f32 41 0.0f32 236 opfeat t 237 opfwd 238 for v ulong OPV 239 put y0 v get opy v 240 end 241 for p ulong sub n t 242 q = add t p 243 opalt q 244 end 245 opfeat t 246 opfwd 247 same = opysame y0 248 opepi 0 249 opfeat add t 1 250 opfwd 251 for v ulong OPV 252 put y0 v get opy v 253 end 254 opalt t 255 opfeat add t 1 256 opfwd 257 ctl = not opysame y0 258 w = write 1 optnl 0 3 259 ocputn t 260 ocputc 32 261 opputb same 262 ocputc 32 263 opputb ctl 264 ocputc 10 265 if not and same ctl 266 exit 88 267 end 268 ret 0 269 end 270 271 fn optforce to int 272 if ne argcnt 5 273 exit 2 274 end 275 opckdir 2 276 opload 277 k = opdecu 4 278 if eq k 1 279 put opb2 6 100.0f32 280 end 281 if eq k 2 282 put opb2 5 100.0f32 283 end 284 if eq k 3 285 put opvp 0 uchar xor ulong get opvp 0 1 286 end 287 opckdir 3 288 opsave 289 ret 0 290 end 291 292 fn optrt to int 293 if ne argcnt 4 294 exit 2 295 end 296 opckdir 2 297 opload 298 opckdir 3 299 opsave 300 ret 0 301 end 302 303 note Read file argv[i] into opx2. 304 fn oprd2 i ulong to void 305 n = oppath i 306 fd = int fopen opfp 0 n 0 0 307 if lt fd 0 308 exit 70 309 end 310 r = read fd opx2 0 `4194305` 311 if or lt r 0 ge r `4194305` 312 exit 70 313 end 314 put opx2n 0 ulong r 315 c = fclose fd 316 end 317 318 fn ophdr2 a ulong b ulong to bool 319 if gt add a 8 b 320 ret false 321 end 322 for i ulong 8 323 if ne get opdb add a i get opth i 324 ret false 325 end 326 end 327 ret true 328 end 329 330 note Kind k may follow kind lk inside a complete episode (G (A R?)+ P). 331 fn opnxt2 lk ulong rf bool k ulong to bool 332 if eq lk 0 333 ret eq k 1 334 end 335 if eq lk 1 336 ret eq k 2 337 end 338 if eq lk 2 339 if rf 340 ret eq k 4 341 end 342 ret eq k 3 343 end 344 if eq lk 3 345 ret or eq k 2 eq k 4 346 end 347 ret false 348 end 349 350 note End of the line starting at opdb[p] (index of its LF); exits 40 when missing or long. 351 fn opeol p ulong b ulong to ulong 352 e = p 353 while and lt e b ne get opdb e 10 bound 4097 354 e = add e 1 355 end 356 if or ge e b gt sub e p 4095 357 exit 40 358 end 359 ret e 360 end 361 362 note Validate the message opdb[p, e) (kind inferred); returns its kind, exits 40. 363 fn opvmsg p ulong e ulong to ulong 364 for i ulong sub e p 365 put ocin i get opdb add p i 366 end 367 k = ocvline sub e p 0 368 if lt k 0 369 exit 40 370 end 371 ret ulong k 372 end 373 374 note vgen state: 0 text pos, 1 ids pos, 2 episodes, 3 messages, 4 last kind (4 = between 375 note episodes), 5 last A was a refusal, 6 ids left in the current record. 376 global opvs ulong 8 377 378 note One step of vgen at text position opvs[0]: a header or one message line. 379 fn opvstep b ulong to void 380 p = get opvs 0 381 x = get opvs 1 382 if eq get opvs 4 4 383 if not ophdr2 p b 384 exit 40 385 end 386 if ge x get opx2n 0 387 exit 40 388 end 389 put opvs 6 ulong get opx2 x 390 put opvs 0 add p 8 391 put opvs 1 add x 1 392 put opvs 4 0 393 put opvs 2 add get opvs 2 1 394 ret 395 end 396 e = opeol p b 397 k = opvmsg p e 398 if not opnxt2 get opvs 4 eq get opvs 5 1 k 399 exit 40 400 end 401 n = get ocnids 0 402 if gt n get opvs 6 403 exit 40 404 end 405 for i ulong n 406 if ne ulong get opx2 add x i get ocids i 407 exit 40 408 end 409 end 410 put opvs 5 0 411 if and eq k 2 eq get ocids 1 9 412 put opvs 5 1 413 end 414 put opvs 6 sub get opvs 6 n 415 if and eq k 4 ne get opvs 6 0 416 exit 40 417 end 418 put opvs 1 add x n 419 put opvs 3 add get opvs 3 1 420 put opvs 4 k 421 put opvs 0 add e 1 422 end 423 424 fn optvgen to int 425 if ne argcnt 4 426 exit 2 427 end 428 opread 2 429 oprd2 3 430 b = get opdn 0 431 put opvs 4 4 432 for z ulong b 433 if lt get opvs 0 b 434 opvstep b 435 end 436 end 437 if or ne get opvs 4 4 ne get opvs 1 get opx2n 0 438 exit 40 439 end 440 w = write 1 optvg 0 3 441 ocputn get opvs 2 442 ocputc 32 443 ocputn get opvs 3 444 ocputc 10 445 ret 0 446 end 447 448 note Batch result lines: ok lines are validated as kind 0 messages; counts printed as 449 note VK ok-valid ok-invalid err40 err50 err53 other. 450 fn optvok to int 451 if ne argcnt 3 452 exit 2 453 end 454 opread 2 455 b = get opdn 0 456 p = ulong 0 457 cnt = new ulong 6 0 458 for z ulong b 459 if lt p b 460 e = opeol p b 461 if lt sub e p 3 462 exit 40 463 end 464 c = opvkind p e 465 put cnt c add get cnt c 1 466 p = add e 1 467 end 468 end 469 w = write 1 optvk 0 3 470 for i ulong 5 471 ocputn get cnt i 472 ocputc 32 473 end 474 ocputn get cnt 5 475 ocputc 10 476 ret 0 477 end 478 479 note Class of batch line opdb[p, e): 0 ok and valid act/rep, 1 ok but invalid, 2.. errors. 480 fn opvkind p ulong e ulong to ulong 481 if ne get opdb p 111 482 ret opdecu2 add p 4 483 end 484 q = add p 3 485 for i ulong sub e q 486 put ocin i get opdb add q i 487 end 488 k = ocvline sub e q 0 489 if or eq k 2 eq k 4 490 ret 0 491 end 492 ret 1 493 end 494 495 note Error code at opdb[p]: 40 -> 2, 50 -> 3, 53 -> 4, other -> 5. 496 fn opdecu2 p ulong to ulong 497 a = get opdb p 498 c = get opdb add p 1 499 if and eq a 52 eq c 48 500 ret 2 501 end 502 if and eq a 53 eq c 48 503 ret 3 504 end 505 if and eq a 53 eq c 51 506 ret 4 507 end 508 ret 5 509 end 510 511 fn main to int 512 if lt argcnt 2 513 exit 2 514 end 515 n = argread 1 opcm 0 16 516 if lt n 2 517 exit 2 518 end 519 c0 = get opcm 0 520 c1 = get opcm 1 521 if eq c0 103 522 ret optgrad 523 end 524 if eq c0 108 525 if eq c1 100 526 ret optldec 527 end 528 ret optleak 529 end 530 if eq c0 109 531 ret optmask 532 end 533 if eq c0 102 534 ret optforce 535 end 536 if eq c0 114 537 ret optrt 538 end 539 if eq c0 118 540 if eq c1 103 541 ret optvgen 542 end 543 ret optvok 544 end 545 exit 2 546 end