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/native/omegallm/cli.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 / native / omegallm / cli.om` 1057 lines ยท 20372 bytes Raw Blame History 1 note SPDX-License-Identifier: AGPL-3.0-only 2 note omegallm cli.om (aien-train#52): the ollm commands (CONTRACT section 7). The platform unit 3 note (lio.om or eio.om) follows it and holds main. 4 note Command words are matched as little-endian u64 packings of their bytes (Wolfram 5 note FromDigits[Reverse[ToCharacterCode[w]],256]): prep `1885696624`, init `1953066601`, 6 note grad `1684107879`, train `474214396532`, eval `1818326629`, base `1702060386`, sample `111516417089907`, 7 note gcheck `118074647274343`, mathck `118074698391917`, adamck `118074781033569`; v1: bpefit 8 note `127996038312034`, bpeenc `109325798699106`, bpedec `109287127216226` (bpe.om); serve `435778905459` 9 note (serve.om on aarch64, noserve.om elsewhere). Fine-tune: tune `1701737844`. 10 note Exit codes: 0 ok; 2 usage; 10-15 checkpoint refusals (ckpt.om); 20 data file shorter than 11 note T + 1 bytes; 21 data over 2^25 bytes or OFFS not exactly 8 B bytes; 22 an OFFS offset with 12 note o + T >= N; 23 eval W = 0 or W T + 1 > M; 24 prep story over 999999 bytes; 40 gcheck over 13 note tolerance; 41 adamck over tolerance; 42 mathck over tolerance; 70 I/O. 14 15 fn ocmdw to ulong 16 r = oargr 1 17 if or le r 0 gt r 8 18 ret 0 19 end 20 v = ulong 0 21 for k ulong ulong r 22 v = or v shl ulong get oarg k mul k 8 23 end 24 ret v 25 end 26 27 fn ocmdlo to ulong 28 r = oargr 1 29 if or le r 8 gt r 16 30 ret 0 31 end 32 v = ulong 0 33 for k ulong 8 34 v = or v shl ulong get oarg k mul k 8 35 end 36 ret v 37 end 38 39 fn ocmdhi to ulong 40 r = oargr 1 41 if or le r 8 gt r 16 42 ret 0 43 end 44 v = ulong 0 45 n = sub ulong r 8 46 for k ulong n 47 v = or v shl ulong get oarg add 8 k mul k 8 48 end 49 ret v 50 end 51 52 note run the command named by argument 1; the platform main checks that it exists. 53 fn ocmd to int 54 w = ocmdw 55 if eq w `1885696624` 56 cmdprep 57 ret 0 58 end 59 if eq w `127996038312034` 60 cmdbpfit 61 ret 0 62 end 63 if eq w `109325798699106` 64 cmdbpenc 65 ret 0 66 end 67 if eq w `109287127216226` 68 cmdbpdec 69 ret 0 70 end 71 if eq w `1953066601` 72 cmdinit 73 ret 0 74 end 75 if eq w `1684107879` 76 cmdgrad 77 ret 0 78 end 79 if eq w `474214396532` 80 cmdtrain 81 ret 0 82 end 83 if eq w `1818326629` 84 cmdeval 85 ret 0 86 end 87 if eq w `1702060386` 88 cmdbase 89 ret 0 90 end 91 if eq w `111516417089907` 92 cmdsamp 93 ret 0 94 end 95 if eq w `118074647274343` 96 cmdgchk 97 ret 0 98 end 99 if eq w `118074698391917` 100 cmdmath 101 ret 0 102 end 103 if eq w `118074781033569` 104 cmdadamck 105 ret 0 106 end 107 if eq w `435778905459` 108 cmdserve 109 ret 0 110 end 111 if eq w `1701737844` 112 cmdtune 113 ret 0 114 end 115 note grow: append initially silent residual layers and restart training. 116 if eq w `2003792487` 117 cmdgrow 118 ret 0 119 end 120 note kvcmp (ham/ollm-speed) `482871572075` 121 if eq w `482871572075` 122 cmdkvcmp 123 ret 0 124 end 125 if eq w `112624400429684` 126 cmdtrainf 127 ret 0 128 end 129 if eq w `30506458620916852` 130 cmdttteval 131 ret 0 132 end 133 if eq w `7809653406635421540` 134 cmddolaeval 135 ret 0 136 end 137 if eq w `31645462707860596` 138 cmdtttsamp 139 ret 0 140 end 141 if eq w `500236120179` 142 cmdspext 143 ret 0 144 end 145 if eq w `482921771123` 146 cmdspapp 147 ret 0 148 end 149 if eq w `123615088701555` 150 cmdspsamp 151 ret 0 152 end 153 if eq w `119165853986931` 154 cmdspeval 155 ret 0 156 end 157 if eq w `111499018330982` 158 cmdfcache 159 ret 0 160 end 161 if eq w `27978647094784628` 162 cmdtrainfc 163 ret 0 164 end 165 if eq w `30792271479792486` 166 cmdfcachem 167 ret 0 168 end 169 if eq w `28542713673379955` 170 cmdspmerge 171 ret 0 172 end 173 if eq w `30227092724740211` 174 cmdspstack 175 ret 0 176 end 177 if eq w `31369549780578919` 178 cmdgrowpro 179 ret 0 180 end 181 if eq w `495773380723` 182 cmdspens 183 ret 0 184 end 185 if eq w `123598092333171` 186 cmdspclip 187 ret 0 188 end 189 if eq w 0 190 lo = ocmdlo 191 hi = ocmdhi 192 if and eq lo `7020664736201273459` eq hi 28784 193 cmdspchainapp 194 ret 0 195 end 196 if and eq lo `7308895112352985203` eq hi `7102838` 197 cmdspchaineval 198 ret 0 199 end 200 if and eq lo `8317701428883976307` eq hi `7368033` 201 cmdspchainsamp 202 ret 0 203 end 204 end 205 exit 2 206 end 207 208 note init CK V T D H F L B SEED TOTAL LRMICRO [G]; lr = f64(LRMICRO)/`1000000`.0. Without G the file 209 note is OLLMCK01 (G = 1); with G it is OLLMCK02 (CONTRACT-V1 section 6). 210 fn cmdinit to void 211 na = oargc 212 if and ne na 13 ne na 14 213 exit 2 214 end 215 for i ulong 7 216 put og i oargu add 3 i 217 end 218 if not ogeom 219 exit 12 220 end 221 put og 40 oargu 10 222 tt = oargu 11 223 if gt tt 999999 224 exit 12 225 end 226 g = ulong 1 227 put og 46 1 228 if eq na 14 229 g = oargu 13 230 put og 46 2 231 end 232 if not ogok2 g 233 exit 12 234 end 235 put og 44 g 236 put og 42 tt 237 put og 43 bitcast ulong div f64 oargu 12 `1000000`.0 238 put og 41 0 239 oinit 240 ocksave 2 241 oputc 73 242 oputc 32 243 oputu get og 8 244 oputc 10 245 oflush 246 end 247 248 note little-endian u64 at ochk[o..o+8) 249 fn ochk64 o ulong to ulong 250 v = ulong 0 251 for k ulong 8 252 x = ulong get ochk add o k 253 v = or v shl x mul k 8 254 end 255 ret v 256 end 257 258 note row b from offset ochk[b] (checked by ooffok) 259 fn ooffrow b ulong to void 260 obrow b ochk64 mul b 8 261 end 262 263 note exit 22 when any offset has o >= N - T (written so that an offset near 2^64 cannot wrap) 264 fn ooffok to void 265 n = get odn 0 266 tt = get og 1 267 for b ulong get og 6 268 if ge ochk64 mul b 8 sub n tt 269 exit 22 270 end 271 end 272 end 273 274 note grad CK DATA OFFS OUT: the gradient of CONTRACT-V1 section 5 (G blocks, K = 1) 275 fn cmdgrad to void 276 if ne oargc 6 277 exit 2 278 end 279 ockload 2 280 odopen 3 281 ooffrd 4 282 ooffok 283 for b ulong get og 6 284 ooffrow b 285 end 286 ls = ograd 287 ogrsave 5 288 oputc 71 289 oputc 32 290 oputx bitcast ulong ls 291 oputc 32 292 oputl rmic ls 293 oputc 10 294 oflush 295 end 296 297 note train CK TRAIN UNTIL EVERY [K]: steps step .. min(UNTIL, TOTAL)-1; after step s, when 298 note (s+1) mod EVERY = 0 or s+1 is the end, save CK and print `T s+1 loss_micro(step s)`. 299 note K worker processes (CONTRACT-V1 section 5.1): K < 1, K > G or G mod K != 0 is exit 29. 300 fn cmdtrain to void 301 na = oargc 302 if and ne na 6 ne na 7 303 exit 2 304 end 305 ockload 2 306 odopen 3 307 un = oargu 4 308 ev = oargu 5 309 if eq ev 0 310 exit 2 311 end 312 k = ulong 1 313 if eq na 7 314 k = oargu 6 315 end 316 gg = get og 44 317 if or eq k 0 gt k gg 318 exit 29 319 end 320 if ne rem gg k 0 321 exit 29 322 end 323 put og 45 k 324 en = get og 42 325 if lt un en 326 en = un 327 end 328 while lt get og 41 en bound 999999 329 ls = ostep 330 s1 = get og 41 331 if or eq rem s1 ev 0 eq s1 en 332 ocksave 2 333 oputc 84 334 oputc 32 335 oputu s1 336 oputc 32 337 oputl rmic ls 338 oputc 10 339 oflush 340 end 341 end 342 end 343 344 note eval CK HELD W [MERGES]: windows at 0, T, .., (W-1)T; prints `E step W loss_micro bpb_micro`. 345 note V > 256 needs MERGES (else exit 2); bpb = ((loss/ln2) f64(W T))/f64(nbytes) with nbytes the 346 note decoded length of the W T targets (CONTRACT-V1 section 7.1); V = 256 keeps loss/ln2. 347 fn cmdeval to void 348 na = oargc 349 if and ne na 5 ne na 6 350 exit 2 351 end 352 ockload 2 353 ww = oargu 4 354 v = get og 0 355 if gt v 256 356 if eq na 5 357 exit 2 358 end 359 obload 5 v 360 end 361 odopen 3 362 tt = get og 1 363 m = get odn 0 364 note W T + 1 > N, tested as W > (N - 1) / T so that a huge W cannot wrap W T 365 if eq ww 0 366 exit 23 367 end 368 if gt ww div sub m 1 tt 369 exit 23 370 end 371 ls = 0.0f64 372 nb = ulong 0 373 for w ulong ww 374 obrow 0 mul w tt 375 ls = add ls ofwd 0 376 if gt v 256 377 nb = add nb oevnb tt 378 end 379 end 380 lo = div ls f64 ww 381 bp = div lo 0.`6931471805599453` 382 if gt v 256 383 bp = div mul bp f64 mul ww tt f64 nb 384 end 385 oputc 69 386 oputc 32 387 oputu get og 41 388 oputc 32 389 oputu ww 390 oputc 32 391 oputl rmic lo 392 oputc 32 393 oputl rmic bp 394 oputc 10 395 oflush 396 end 397 398 note decoded bytes of the targets oby[0 .. n) 399 fn oevnb n ulong to ulong 400 s = ulong 0 401 for t ulong n 402 s = add s obtlen get oby t 403 end 404 ret s 405 end 406 407 note append token c to the context window obx[0 .. CT), keeping the last T tokens 408 fn ocpush c ulong to void 409 cn = get og 9 410 tt = get og 1 411 if lt cn tt 412 put obx cn c 413 put og 9 add cn 1 414 else 415 for i ulong sub tt 1 416 put obx i get obx add i 1 417 end 418 put obx sub tt 1 c 419 end 420 end 421 422 note sample CK SEED N TEMPMILLI PROMPT [MERGES]. Context = token 0, then PROMPT (bytes when V = 256, 423 note its encoding when V > 256, CONTRACT-V1 section 7.2); the model reads the last T context tokens 424 note at positions 0..; the next token comes from the logits at the last position. 425 note TEMPMILLI 0: argmax (lowest index on ties), no draw. Otherwise softmax(logits/(TEMPMILLI/1000)) 426 note and u = (splitmix64 stream out >> 11) 2^-53 with state = SEED, out = mix(state += GOLD); 427 note the token is the smallest c with u < p[0] + .. + p[c], else the last c with p[c] > 0. 428 note A generated token 0 ends the output and is not written; another writes its decoded bytes. 429 fn cmdsamp to void 430 na = oargc 431 if and ne na 7 ne na 8 432 exit 2 433 end 434 ockload 2 435 st = oargu 3 436 nn = oargu 4 437 if gt nn 999999 438 exit 2 439 end 440 tm = oargu 5 441 v = get og 0 442 if gt v 256 443 if eq na 7 444 exit 2 445 end 446 obload 7 v 447 end 448 ochipup 449 osampleloaded st nn tm 450 end 451 452 note Embedding entry: checkpoint and tokenizer already loaded; argument 6 supplies the prompt. 453 note The caller keeps exclusive ownership of the model pools until this returns. 454 fn osampleloaded seed ulong nn ulong tm ulong to void 455 if gt nn 999999 456 exit 2 457 end 458 st = seed 459 v = get og 0 460 put og 9 0 461 ocpush 0 462 if gt v 256 463 r = oargr 6 464 if or lt r 0 gt r 4000 465 exit 2 466 end 467 np = obprompt 6 468 for i ulong np 469 ocpush get obtk i 470 end 471 else 472 r = oargr 6 473 if or lt r 0 gt r 4096 474 exit 2 475 end 476 for i ulong ulong r 477 ocpush ulong get oarg i 478 end 479 end 480 for g ulong nn 481 c = osstep st tm 482 if ne tm 0 483 st = add st `11400714819323198485` 484 end 485 if eq c 0 486 break 487 end 488 if gt v 256 489 obtput c 490 else 491 oputc c 492 end 493 note Flush each decoded token so interactive consumers see progress. Bytes and sampling stay unchanged. 494 oflush 495 ocpush c 496 end 497 oflush 498 end 499 500 note one sampling step (cmdsamp, serve.om): the next token from the logits at the last context 501 note position, argmax when TEMPMILLI tm is 0, else a draw with the splitmix64 stream state st. 502 fn osstep st ulong tm ulong to ulong 503 olastf 504 if eq tm 0 505 ret oargmax 506 end 507 ret odraw st div f64 tm 1000.0 508 end 509 510 note ogpu[0] = 1 when the per-token forward runs on the chip: gpu/gg.om's gserve and gsample set it 511 note before cmdserve or cmdsamp; nogpu.om's ogchip and oglast refuse with exit 2 on the CPU targets. 512 global ogpu ulong 1 513 514 note after the checkpoint loads: on the chip path, open the chip and upload the parameters once 515 fn ochipup to void 516 if ne get ogpu 0 0 517 ogchip 518 end 519 end 520 521 note forward of the context in obx row 0, then its last position's logits into TMP[0..V) (oa), 522 note on the chip when ogpu[0] = 1 (oglast), else on the CPU (ofwdi, model.om: only the rows past the 523 note prefix the previous call computed, then olast) 524 fn olastf to void 525 if ne get ogpu 0 0 526 oglast 527 ret 528 end 529 t0 = ofwdi 530 olast 531 end 532 533 note kvcmp CK N PROMPT MERGES (ham/ollm-speed, V > 256, N V <= 2^20): ofwdi against ofwd 0. Pass 1: 534 note N greedy steps from token 0 then PROMPT's encoding with ofwdi then olast (the CPU decode), every 535 note step's V logits kept in okvr; prints `KI step ct t0 tok ns`. Pass 2: the same contexts again 536 note (pass 1's tokens pushed) with ofwd 0 then olast; prints `KF step ct tok ndiff ns`, ndiff = logits 537 note whose f64 bits differ from pass 1's. Before step N/2 of both passes the context token at CT - 5 538 note (when CT > 5) becomes its successor mod V, so ofwdi must find the changed prefix. Last line 539 note `KVCMP N ndiff inc_ns full_ns` (forward and logits time summed over the steps); exit 43 when 540 note ndiff > 0. 541 global okvr f64 `1048576` 542 global okvk ulong 4096 543 fn kvstart to void 544 put og 9 0 545 ocpush 0 546 np = obprompt 4 547 for i ulong np 548 ocpush get obtk i 549 end 550 end 551 552 fn kvpert s ulong nn ulong to void 553 ct = get og 9 554 if and eq s div nn 2 gt ct 5 555 i = sub ct 5 556 put obx i rem add get obx i 1 get og 0 557 end 558 end 559 560 fn kvline a ulong b ulong c ulong d ulong e long to void 561 oputc 32 562 oputu a 563 oputc 32 564 oputu b 565 oputc 32 566 oputu c 567 oputc 32 568 oputu d 569 oputc 32 570 oputl e 571 oputc 10 572 oflush 573 end 574 575 note kvcmp totals: okvs[0] pass 1 ns, [1] pass 2 ns, [2] differing logits 576 global okvs ulong 3 577 fn cmdkvcmp to void 578 if ne oargc 6 579 exit 2 580 end 581 ockload 2 582 nn = oargu 3 583 v = get og 0 584 if or le v 256 or gt nn 4096 gt mul nn v `1048576` 585 exit 2 586 end 587 obload 5 v 588 put okvs 0 0 589 put okvs 1 0 590 put okvs 2 0 591 kvstart 592 for s ulong nn 593 kvpert s nn 594 c = kvinc s 595 ocpush c 596 end 597 kvstart 598 for s2 ulong nn 599 kvpert s2 nn 600 kvfull s2 601 ocpush get okvk s2 602 end 603 oputc 75 604 oputc 86 605 oputc 67 606 oputc 77 607 oputc 80 608 oputc 32 609 oputu nn 610 oputc 32 611 oputu get okvs 2 612 oputc 32 613 oputu get okvs 0 614 oputc 32 615 oputu get okvs 1 616 oputc 10 617 oflush 618 if gt get okvs 2 0 619 exit 43 620 end 621 end 622 623 note pass 1 step s: ofwdi then olast, logits into okvr row s, KI line; returns the greedy token 624 fn kvinc s ulong to ulong 625 a = onsnow 626 t0 = ofwdi 627 olast 628 e = sub onsnow a 629 put okvs 0 add get okvs 0 e 630 c = oargmax 631 kvkeep s 632 put okvk s c 633 oputc 75 634 oputc 73 635 kvline s get og 9 t0 c long e 636 ret c 637 end 638 639 note okvr row s = the V logits in TMP 640 fn kvkeep s ulong to void 641 v = get og 0 642 tm = get og 27 643 o = mul s v 644 for j ulong v 645 x = get oa add tm j 646 put okvr add o j x 647 end 648 end 649 650 note the logits in TMP whose f64 bits differ from okvr row s 651 fn kvdiff s ulong to ulong 652 v = get og 0 653 tm = get og 27 654 o = mul s v 655 nd = ulong 0 656 for j ulong v 657 x = bitcast ulong get oa add tm j 658 y = bitcast ulong get okvr add o j 659 if ne x y 660 nd = add nd 1 661 end 662 end 663 ret nd 664 end 665 666 note pass 2 step s: ofwd 0 then olast, compared bit for bit with okvr row s, KF line 667 fn kvfull s ulong to void 668 a = onsnow 669 lf = ofwd 0 670 olast 671 e = sub onsnow a 672 put okvs 1 add get okvs 1 e 673 nd = kvdiff s 674 put okvs 2 add get okvs 2 nd 675 oputc 75 676 oputc 70 677 kvline s get og 9 oargmax nd long e 678 end 679 680 note logits of the last context position into TMP[0..V) (oa) 681 fn olast to void 682 d = get og 2 683 z = add get og 17 mul sub get og 9 1 d 684 klogit z get og 27 get og 0 d 685 end 686 687 fn oargmax to ulong 688 tm = get og 27 689 b = ulong 0 690 bv = get oa tm 691 for c ulong get og 0 692 if gt get oa add tm c bv 693 bv = get oa add tm c 694 b = c 695 end 696 end 697 ret b 698 end 699 700 fn odraw st ulong tau f64 to ulong 701 tm = get og 27 702 v = get og 0 703 m = bitcast f64 ulong `18442240474082181120` 704 for c ulong v 705 x = div get oa add tm c tau 706 put oa add tm c x 707 m = fmax m x 708 end 709 sm = osoft tm v m 710 u = mul f64 shr smx st 11 1.`1102230246251565e`-16 711 acc = 0.0f64 712 la = ulong 0 713 for k ulong v 714 pk = get oa add tm k 715 acc = add acc pk 716 if lt u acc 717 ret k 718 end 719 if gt pk 0.0 720 la = k 721 end 722 end 723 ret la 724 end 725 726 note gcheck constants (derivation and Wolfram queries in docs/omegallm/README.md). GCH2 = GCH/4 is 727 note the retry step for an index whose difference at GCH crossed a ReLU kink. 728 const GCH f64 0.000001 729 const GCH2 f64 0.`00000025` 730 const GCFLOOR f64 0.000001 731 const GCTOL f64 0.001 732 note mathck: max relative error allowed against the correctly rounded reference 733 const MCTOL f64 0.`000000000000001` 734 735 note gcheck CK TRAIN: the hand gradient of the step loss for the batch of the header step is 736 note compared with central differences (L(p+h) - L(p-h))/((p+h) - (p-h)) at 4 indices of every 737 note tensor instance (wte, wpe, per layer g1 wq wk wv wo g2 w1 w2, gf), drawn by splitmix64. 738 note rel = |num - g| / max(|num|, |g|, GCFLOOR). An index with rel > GCTOL at GCH is measured 739 note again at GCH2 and keeps the smaller rel (a wrong hand gradient fails at both steps). Prints 740 note one `c index g_e12 num_e12` line per index (num of the kept step), then 741 note `C count maxrel_bits_hex maxrel_e9 worst_index retries`; exit 40 when maxrel > GCTOL. 742 fn cmdgchk to void 743 if ne oargc 4 744 exit 2 745 end 746 ockload 2 747 odopen 3 748 obatch get og 41 749 ls = ograd 750 d = get og 2 751 cnt = ulong 0 752 put og 50 0 753 put og 51 0 754 put og 52 0 755 put og 53 0 756 ogcten 0 mul get og 0 d 0 757 ogcten get og 30 mul get og 1 d 1 758 for l ulong get og 5 759 ogcten opg1 l d 2 760 ogcten opwq l mul d d 3 761 ogcten opwk l mul d d 4 762 ogcten opwv l mul d d 5 763 ogcten opwo l mul d d 6 764 ogcten opg2 l d 7 765 ogcten opw1 l mul d get og 4 8 766 ogcten opw2 l mul d get og 4 9 767 end 768 ogcten get og 33 d 10 769 mx = bitcast f64 get og 51 770 oputc 67 771 oputc 32 772 oputu get og 50 773 oputc 32 774 oputx get og 51 775 oputc 32 776 oputl long mul mx `1000000000`.0 777 oputc 32 778 oputu get og 52 779 oputc 32 780 oputu get og 53 781 oputc 10 782 oflush 783 if gt mx GCTOL 784 exit 40 785 end 786 end 787 788 note step-loss for the batch in obx/oby without touching the gradient 789 fn oloss to f64 790 ls = 0.0f64 791 for b ulong get og 6 792 ls = add ls ofwd b 793 end 794 ret div ls f64 get og 6 795 end 796 797 fn ogcten o ulong n ulong tag ulong to void 798 for j ulong 4 799 i = add o rem smx xor get og 40 add mul get og 50 4 j n 800 ogc1 i 801 end 802 end 803 804 note central difference (L(p+h) - L(p-h))/((p+h) - (p-h)) at parameter i; restores p 805 fn ogcnum i ulong h f64 to f64 806 p0 = owg i 807 pp = add p0 h 808 pm = sub p0 h 809 owp i pp 810 lp = oloss 811 owp i pm 812 lm = oloss 813 owp i p0 814 ret div sub lp lm sub pp pm 815 end 816 817 fn ogcrel num f64 g f64 to f64 818 den = fmax fmax fabs num fabs g GCFLOOR 819 ret div fabs sub num g den 820 end 821 822 note one gradient check at parameter i; updates og[50] count, og[51] max rel bits, og[52] worst 823 note index, og[53] retries at GCH2 824 fn ogc1 i ulong to void 825 g = ocsg i 826 num = ogcnum i GCH 827 rel = ogcrel num g 828 if gt rel GCTOL 829 put og 53 add get og 53 1 830 n2 = ogcnum i GCH2 831 r2 = ogcrel n2 g 832 if lt r2 rel 833 num = n2 834 rel = r2 835 end 836 end 837 oputc 99 838 oputc 32 839 oputu i 840 oputc 32 841 oputl long mul g `1000000000000`.0 842 oputc 32 843 oputl long mul num `1000000000000`.0 844 oputc 10 845 put og 50 add get og 50 1 846 if gt rel bitcast f64 get og 51 847 put og 51 bitcast ulong rel 848 put og 52 i 849 end 850 end 851 852 note mathck REF: REF lines are `e XBITS RBITS` or `l XBITS RBITS` (16 lowercase hex digits each, 853 note 36 bytes per line); RBITS is the correctly rounded Wolfram value of exp or log at the exact 854 note f64 XBITS. Prints `M e count max_ulp maxrel_bits_hex maxrel_e18` and the same for l; 855 note exit 42 when a special value (r = 0, inf or NaN) differs in bits, maxrel > MCTOL, or REF has 856 note no e line or no l line (a check that checked nothing fails). 857 fn cmdmath to void 858 if ne oargc 3 859 exit 2 860 end 861 n = odread 2 862 if ne rem n 36 0 863 exit 21 864 end 865 for k ulong 6 866 put og add 50 k 0 867 end 868 for i ulong div n 36 869 omline mul i 36 870 end 871 omprint 101 0 872 omprint 108 3 873 if or gt bitcast f64 get og 52 MCTOL gt bitcast f64 get og 55 MCTOL 874 exit 42 875 end 876 if or eq get og 50 0 eq get og 53 0 877 exit 42 878 end 879 end 880 881 fn ohex o ulong to ulong 882 v = ulong 0 883 for k ulong 16 884 c = odb add o k 885 if lt c 58 886 v = or shl v 4 sub c 48 887 else 888 v = or shl v 4 sub c 87 889 end 890 end 891 ret v 892 end 893 894 note og[50+b]: count, max ulp, max rel bits (b = 0 for exp, 3 for log) 895 fn omline o ulong to void 896 kd = odb o 897 x = bitcast f64 ohex add o 2 898 rb = ohex add o 19 899 b = ulong 0 900 y = 0.0f64 901 if eq kd 101 902 y = fexp x 903 else 904 b = ulong 3 905 y = flog x 906 end 907 yb = bitcast ulong y 908 put og add 50 b add get og add 50 b 1 909 r = bitcast f64 rb 910 if or or eq r 0.0 ne r r eq fabs r bitcast f64 ulong `9218868437227405312` 911 if ne yb rb 912 exit 42 913 end 914 ret 915 end 916 ul = ulong 0 917 if gt yb rb 918 ul = sub yb rb 919 else 920 ul = sub rb yb 921 end 922 if gt ul get og add 51 b 923 put og add 51 b ul 924 end 925 rel = div fabs sub y r fabs r 926 if gt rel bitcast f64 get og add 52 b 927 put og add 52 b bitcast ulong rel 928 end 929 end 930 931 fn omprint c ulong b ulong to void 932 oputc 77 933 oputc 32 934 oputc c 935 oputc 32 936 oputu get og add 50 b 937 oputc 32 938 oputu get og add 51 b 939 oputc 32 940 oputx get og add 52 b 941 oputc 32 942 oputl long mul bitcast f64 get og add 52 b 1e18 943 oputc 10 944 oflush 945 end 946 947 note tune CK OUT TOTAL LRMICRO: fine-tune entry. Load CK (any checkpoint ckpt.om accepts), keep 948 note its shapes, G and weights, and start a new schedule on them: step 0, the given TOTAL and 949 note lr = f64(LRMICRO)/`1000000`.0, Adam moments m = v = 0 (so warmup and bias correction restart). 950 note Save to OUT with the loaded magic and print `U P`. train, gtrain and gtrainf then continue 951 note from OUT on any token file. TOTAL 0 or over 999999 exits 12; wrong argument count exits 2. 952 fn cmdtune to void 953 if ne oargc 6 954 exit 2 955 end 956 ockload 2 957 tt = oargu 4 958 if or eq tt 0 gt tt 999999 959 exit 12 960 end 961 put og 41 0 962 put og 42 tt 963 put og 43 bitcast ulong div f64 oargu 5 `1000000`.0 964 ozerom mul 2 get og 8 965 ocksave 3 966 oputc 85 967 oputc 32 968 oputu get og 8 969 oputc 10 970 oflush 971 end 972 973 974 note grow CK OUT L TOTAL LRMICRO: keep embeddings, old layers and final gain byte for byte. 975 note Added layers use the own initializer with Wo and W2 zeroed, so both residual branches 976 note initially contribute zero. Their input projections remain initialized and trainable. 977 note The existing gradient cold store snapshots old weights while geometry changes; oinit 978 note writes parameters and moments only. Since P grows, new moments cannot alias the snapshot. 979 note Like tune, restart step and Adam, preserving seed, G, vocabulary and checkpoint format. 980 note OUT uses normal checkpoint save semantics (an existing path is replaced). 981 fn ogrowsnap n ulong to void 982 for q ulong ocn n 983 i = mul q OCH 984 ie = oce q n 985 while lt i ie bound 999999 986 v = owg i 987 note Reject non-finite source weights before attempting a growth operation. 988 if eq and shr bitcast ulong v 52 2047 2047 989 exit 54 990 end 991 ocsp i v 992 i = add i 1 993 end 994 end 995 end 996 997 fn ogrowcopy n ulong to void 998 for q ulong ocn n 999 i = mul q OCH 1000 ie = oce q n 1001 while lt i ie bound 999999 1002 owp i ocsg i 1003 i = add i 1 1004 end 1005 end 1006 end 1007 1008 note Keep loop temporaries out of cmdgrow: every target must fit its register budget. 1009 fn ogrowsilent first ulong to void 1010 for j ulong sub get og 5 first 1011 l = add first j 1012 oiset opwo l mul get og 2 get og 2 0.0 1013 oiset opw2 l mul get og 2 get og 4 0.0 1014 end 1015 end 1016 1017 fn cmdgrow to void 1018 if ne oargc 7 1019 exit 2 1020 end 1021 ockload 2 1022 ll = oargu 4 1023 tt = oargu 5 1024 lr = oargu 6 1025 if or le ll get og 5 or eq tt 0 gt tt 999999 1026 exit 12 1027 end 1028 if eq lr 0 1029 exit 12 1030 end 1031 oldl = get og 5 1032 oldg = get og 33 1033 ogrowsnap get og 8 1034 put og 5 ll 1035 if not ogeom 1036 exit 12 1037 end 1038 put og 41 0 1039 put og 42 tt 1040 put og 43 bitcast ulong div f64 lr `1000000`.0 1041 oinit 1042 ogrowcopy oldg 1043 for j ulong get og 2 1044 owp add get og 33 j ocsg add oldg j 1045 end 1046 ogrowsilent oldl 1047 ocksave 3 1048 oputc 71 1049 oputc 32 1050 oputu oldl 1051 oputc 32 1052 oputu ll 1053 oputc 32 1054 oputu get og 8 1055 oputc 10 1056 oflush 1057 end