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/spec.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 / spec.om` 2194 lines ยท 40903 bytes Raw Blame History 1 note SPDX-License-Identifier: AGPL-3.0-only 2 note omegallm spec.om: Frozen-Core Specialist Training (trainf), Test-Time Fast-Weights 3 note (ttteval, tttsamp), and Layer-Contrastive Decoding (dolaeval). Pure seeded Omega. 4 5 global odl1 f64 4096 6 global odl2 f64 4096 7 global ottt_st ulong 8 8 global oens ulong 8 9 global ocl_st ulong 16 10 global ocl_k ulong 4 11 global ocl_a0 ulong 4 12 global ocl_sl ulong 4 13 global ocl_wo ulong 4 14 global ocl_wn ulong 4 15 global ocl_w f64 4 16 global ocl_ent f64 4 17 global ocl_al f64 4 18 19 note ---- 1. Frozen-Core Residual Specialist Training ---- 20 note trainf CK TOKS UNTIL EVERY FREEZE_LAYERS [BATCH] 21 note Freezes embeddings + layers 0..FREEZE_LAYERS-1 bit-identically while training newer layers. 22 fn cmdtrainf to void 23 na = oargc 24 if and ne na 7 ne na 8 25 exit 2 26 end 27 ockload 2 28 odopen 3 29 until = oargu 4 30 every = oargu 5 31 flay = oargu 6 32 if or eq every 0 gt flay get og 5 33 exit 2 34 end 35 if lt get odn 0 add get og 1 1 36 exit 23 37 end 38 put ottt_st 0 get og 6 39 put ottt_st 1 get og 44 40 if eq na 8 41 nb = oargu 7 42 if or eq nb 0 gt nb 64 43 exit 2 44 end 45 put og 6 nb 46 put og 44 1 47 end 48 fz = add get og 31 mul flay get og 32 49 put ofreeze 0 fz 50 put ofzlay 0 flay 51 put og 45 1 52 st = get og 41 53 while lt st until bound 999999 54 ls = ostep 55 st = get og 41 56 if or eq rem st every 0 eq st until 57 put og 6 get ottt_st 0 58 put og 44 get ottt_st 1 59 ocksave 2 60 if eq na 8 61 put og 6 oargu 7 62 put og 44 1 63 end 64 oputc 70 65 oputc 32 66 oputu st 67 oputc 32 68 oputu flay 69 oputc 32 70 oputl rmic ls 71 oputc 10 72 oflush 73 end 74 end 75 put og 6 get ottt_st 0 76 put og 44 get ottt_st 1 77 put ofreeze 0 0 78 put ofzlay 0 0 79 end 80 81 note ---- 2. Test-Time Fast-Weights (TTT-Omega) ---- 82 note Snapshot ow[fz..P) into cold store ocs[P + i] 83 fn ottt_snap fz ulong to void 84 c = ocsinit 85 p = get og 8 86 i = fz 87 note at most `16777216` passes, run as aligned chunks of 524288 (2^19): the seeded omc takes a while bound 88 note of at most 999999. 33 chunks cover any `16777216` consecutive values of i, so no run that the 89 note bound `16777216` allowed is refused here. 90 while lt i p bound 33 91 while lt i p bound 524288 92 ocsp add p i owg i 93 i = add i 1 94 if eq and i 524287 0 95 break 96 end 97 end 98 end 99 end 100 101 note Restore ow[fz..P) from cold store ocs[P + i] 102 fn ottt_rest fz ulong to void 103 p = get og 8 104 i = fz 105 note at most `16777216` passes, run as aligned chunks of 524288 (2^19): the seeded omc takes a while bound 106 note of at most 999999. 33 chunks cover any `16777216` consecutive values of i, so no run that the 107 note bound `16777216` allowed is refused here. 108 while lt i p bound 33 109 while lt i p bound 524288 110 owp i ocsg add p i 111 i = add i 1 112 if eq and i 524287 0 113 break 114 end 115 end 116 end 117 end 118 119 note Zero cold-store gradients ocs[0..P) 120 fn ottt_zg to void 121 p = get og 8 122 i = ulong 0 123 note at most `16777216` passes, run as aligned chunks of 524288 (2^19): the seeded omc takes a while bound 124 note of at most 999999. 33 chunks cover any `16777216` consecutive values of i, so no run that the 125 note bound `16777216` allowed is refused here. 126 while lt i p bound 33 127 while lt i p bound 524288 128 ocsp i 0.0f64 129 i = add i 1 130 if eq and i 524287 0 131 break 132 end 133 end 134 end 135 end 136 137 note One clipped SGD fast-weight step on ow[fz..P) using ocs[0..P) 138 fn ottt_sgd fz ulong lr f64 to void 139 p = get og 8 140 ss = 0.0f64 141 i = fz 142 note at most `16777216` passes, run as aligned chunks of 524288 (2^19): the seeded omc takes a while bound 143 note of at most 999999. 33 chunks cover any `16777216` consecutive values of i, so no run that the 144 note bound `16777216` allowed is refused here. 145 while lt i p bound 33 146 while lt i p bound 524288 147 g = ocsg i 148 ss = add ss mul g g 149 i = add i 1 150 if eq and i 524287 0 151 break 152 end 153 end 154 end 155 nr = fsqrt ss 156 sc = lr 157 if gt nr 1.0 158 sc = div lr nr 159 end 160 i = fz 161 note at most `16777216` passes, run as aligned chunks of 524288 (2^19): the seeded omc takes a while bound 162 note of at most 999999. 33 chunks cover any `16777216` consecutive values of i, so no run that the 163 note bound `16777216` allowed is refused here. 164 while lt i p bound 33 165 while lt i p bound 524288 166 w = owg i 167 owp i sub w mul sc ocsg i 168 i = add i 1 169 if eq and i 524287 0 170 break 171 end 172 end 173 end 174 end 175 176 note Evaluate suffix loss on sequence 0 over positions [pref..tt) after ofwd 0 177 fn ottt_suf pref ulong tt ulong to f64 178 ls = 0.0f64 179 t = pref 180 while lt t tt bound 1024 181 ls = add ls oheadr 0 t 182 t = add t 1 183 end 184 ret div ls f64 sub tt pref 185 end 186 187 note Run `steps` strictly-causal online gradient steps on prefix [0..pref) 188 fn ottt_adapt pref ulong steps ulong lr f64 fz ulong to void 189 put og 9 pref 190 put og 10 0 191 sc = div 1.0f64 f64 pref 192 s = ulong 0 193 while lt s steps bound 1024 194 ottt_zg 195 l0 = ofwd 0 196 obwd 0 sc 197 ottt_sgd fz lr 198 s = add s 1 199 end 200 end 201 202 note ttteval CK HELD W PREFIX STEPS LRMICRO LAYER_FROM 203 fn cmdttteval to void 204 if ne oargc 9 205 exit 2 206 end 207 ockload 2 208 odopen 3 209 ww = oargu 4 210 pref = oargu 5 211 steps = oargu 6 212 lrm = oargu 7 213 lfrom = oargu 8 214 tt = get og 1 215 if or eq ww 0 or eq pref 0 ge pref tt 216 exit 2 217 end 218 if gt lfrom get og 5 219 exit 2 220 end 221 if gt ww div sub get odn 0 1 tt 222 exit 23 223 end 224 fz = add get og 31 mul lfrom get og 32 225 lr = div f64 lrm `1000000`.0 226 b_sum = 0.0f64 227 t_sum = 0.0f64 228 for w ulong ww 229 obrow 0 mul w tt 230 put og 9 tt 231 l0 = ofwd 0 232 b_sum = add b_sum ottt_suf pref tt 233 ottt_snap fz 234 ottt_adapt pref steps lr fz 235 put og 9 tt 236 l1 = ofwd 0 237 t_sum = add t_sum ottt_suf pref tt 238 ottt_rest fz 239 end 240 put og 9 tt 241 b_lo = div b_sum f64 ww 242 t_lo = div t_sum f64 ww 243 oputc 84 244 oputc 84 245 oputc 84 246 oputc 32 247 oputu ww 248 oputc 32 249 oputu pref 250 oputc 32 251 oputu steps 252 oputc 32 253 oputu lrm 254 oputc 32 255 oputu lfrom 256 oputc 32 257 oputl rmic b_lo 258 oputc 32 259 oputl rmic t_lo 260 oputc 32 261 oputl rmic sub t_lo b_lo 262 oputc 10 263 oflush 264 end 265 266 fn ottt_prompt v ulong to void 267 put og 9 0 268 ocpush 0 269 if gt v 256 270 np = obprompt 6 271 for i ulong np 272 ocpush get obtk i 273 end 274 else 275 pl = oargr 6 276 if lt pl 0 277 exit 2 278 end 279 for i ulong ulong pl 280 ocpush ulong get oarg i 281 end 282 end 283 end 284 285 note tttsamp CK SEED N TEMPMILLI PROMPT MERGES STEPS LRMICRO LAYER_FROM 286 fn cmdtttsamp to void 287 if ne oargc 11 288 exit 2 289 end 290 ockload 2 291 v = get og 0 292 if gt v 256 293 obload 7 v 294 end 295 ottt_prompt v 296 nc = get og 9 297 fz = add get og 31 mul oargu 10 get og 32 298 lr = div f64 oargu 9 `1000000`.0 299 steps = oargu 8 300 ottt_snap fz 301 if and gt steps 0 gt nc 1 302 pref = sub nc 1 303 for j ulong pref 304 put oby j get obx add j 1 305 end 306 ottt_adapt pref steps lr fz 307 end 308 osampleloaded oargu 3 oargu 4 oargu 5 309 ottt_rest fz 310 end 311 312 note ---- 3. Layer-Contrastive Decoding (DoLa in pure Omega) ---- 313 note Compute log_softmax of oa[pr..pr+v) into odl1 (which=1) or odl2 (which=2) 314 note Note: osoft overwrites oa[pr..pr+v) with exp(x - m), so save raw logits first. 315 fn odl_lsm pr ulong v ulong which ulong to void 316 m = bitcast f64 ulong `18442240474082181120` 317 for j ulong v 318 x = get oa add pr j 319 m = fmax m x 320 if eq which 1 321 put odl1 j x 322 else 323 put odl2 j x 324 end 325 end 326 sm = osoft pr v m 327 lsm = flog sm 328 for j ulong v 329 if eq which 1 330 put odl1 j sub sub get odl1 j m lsm 331 else 332 put odl2 j sub sub get odl2 j m lsm 333 end 334 end 335 end 336 337 fn odl_mix pr ulong v ulong beta f64 to void 338 for j ulong v 339 put oa add pr j sub get odl1 j mul beta get odl2 j 340 end 341 end 342 343 fn odl_proj h ulong t ulong z ulong pr ulong which ulong to void 344 frms h get og 33 z add get og 16 t 345 klogit z pr get og 0 get og 2 346 odl_lsm pr get og 0 which 347 end 348 349 note Evaluate one row t with both baseline and DoLa (early layer el, contrast beta) 350 fn odl_row t ulong el ulong beta f64 to void 351 r = mul t get og 2 352 z = add get og 17 r 353 pr = add get og 18 mul t get og 0 354 odl_proj add get og 15 r t z pr 1 355 odl_proj add oahin el r t z pr 2 356 odl_mix pr get og 0 beta 357 y = get oby t 358 put odl1 0 sub 0.0f64 get odl1 y 359 put odl2 0 olossrow pr get og 0 y 360 end 361 362 fn odl_print ww ulong el ulong bm ulong b_lo f64 d_lo f64 to void 363 oputc 68 364 oputc 79 365 oputc 76 366 oputc 65 367 oputc 32 368 oputu ww 369 oputc 32 370 oputu el 371 oputc 32 372 oputu bm 373 oputc 32 374 oputl rmic b_lo 375 oputc 32 376 oputl rmic d_lo 377 oputc 32 378 oputl rmic sub d_lo b_lo 379 oputc 10 380 oflush 381 end 382 383 note dolaeval CK HELD W EARLY_LAYER BETA_MILLI 384 fn cmddolaeval to void 385 if ne oargc 7 386 exit 2 387 end 388 ockload 2 389 odopen 3 390 ww = oargu 4 391 el = oargu 5 392 bm = oargu 6 393 tt = get og 1 394 if or eq ww 0 or eq el 0 ge el get og 5 395 exit 2 396 end 397 if gt ww div sub get odn 0 1 tt 398 exit 23 399 end 400 beta = div f64 bm 1000.0 401 b_sum = 0.0f64 402 d_sum = 0.0f64 403 for w ulong ww 404 obrow 0 mul w tt 405 put og 9 tt 406 l0 = ofwd 0 407 for t ulong tt 408 odl_row t el beta 409 b_sum = add b_sum get odl1 0 410 d_sum = add d_sum get odl2 0 411 end 412 end 413 tot = f64 mul ww tt 414 odl_print ww el bm div b_sum tot div d_sum tot 415 end 416 417 418 note ---- 4. Swappable Specialist Layer Packs (OLLMSP01) ---- 419 const OSPMAG ulong `3544421225449933903` 420 421 note FNV-1a 64 over shapes (V,T,D,H,F,base_L) + frozen base weights ow[0..fz) 422 fn osp_fnvu h ulong v ulong to ulong 423 x = h 424 for k ulong 8 425 b = and shr v mul k 8 255 426 x = mul xor x b `1099511628211` 427 end 428 ret x 429 end 430 431 fn osp_basehash bl ulong fz ulong to ulong 432 h = ulong `14695981039346656037` 433 h = osp_fnvu h get og 0 434 h = osp_fnvu h get og 1 435 h = osp_fnvu h get og 2 436 h = osp_fnvu h get og 3 437 h = osp_fnvu h get og 4 438 h = osp_fnvu h bl 439 i = ulong 0 440 note at most `33554432` passes, run as aligned chunks of 524288 (2^19): the seeded omc takes a while bound 441 note of at most 999999. 65 chunks cover any `33554432` consecutive values of i, so no run that the 442 note bound `33554432` allowed is refused here. 443 while lt i fz bound 65 444 while lt i fz bound 524288 445 h = osp_fnvu h bitcast ulong owg i 446 i = add i 1 447 if eq and i 524287 0 448 break 449 end 450 end 451 end 452 ret h 453 end 454 455 note Stream ow[fz..fz+nspec) to open pack file starting at offset 48; returns payload FNV-1a 64 456 fn osp_wrpay fz ulong nspec ulong to ulong 457 h = ulong `14695981039346656037` 458 pos = ulong 48 459 done = ulong 0 460 while lt done nspec bound 1024 461 cnt = sub nspec done 462 if gt cnt OCKC 463 cnt = OCKC 464 end 465 for j ulong cnt 466 ocput8 mul j 8 bitcast ulong owg add fz add done j 467 end 468 nb = mul cnt 8 469 h = ocfnvk h nb 470 ocwput pos nb 471 pos = add pos nb 472 done = add done cnt 473 end 474 ret h 475 end 476 477 note Stream nspec f64s from arg ai at offset 48 into ow[fz..fz+nspec); returns payload FNV-1a 64 478 fn osp_rdpay ai ulong fz ulong nspec ulong to ulong 479 h = ulong `14695981039346656037` 480 pos = ulong 48 481 done = ulong 0 482 while lt done nspec bound 1024 483 cnt = sub nspec done 484 if gt cnt OCKC 485 cnt = OCKC 486 end 487 nb = mul cnt 8 488 if ne oprd ai pos 0 nb nb 489 exit 60 490 end 491 h = ocfnvw h nb 492 for j ulong cnt 493 owp add fz add done j bitcast f64 opw8 mul j 8 494 end 495 pos = add pos nb 496 done = add done cnt 497 end 498 ret h 499 end 500 501 note spext BASE.ck SPEC.ck PACK.sp: verify frozen base bit-identical, write OLLMSP01 specialist pack 502 fn cmdspext to void 503 if ne oargc 5 504 exit 2 505 end 506 ockload 2 507 bl = get og 5 508 fz = get og 33 509 bh = osp_basehash bl fz 510 put ottt_st 0 get og 0 511 put ottt_st 1 get og 1 512 put ottt_st 2 get og 2 513 put ottt_st 3 get og 3 514 put ottt_st 4 get og 4 515 put ottt_st 5 bl 516 put ottt_st 6 fz 517 put ottt_st 7 bh 518 ockload 3 519 for k ulong 5 520 if ne get og k get ottt_st k 521 exit 62 522 end 523 end 524 if le get og 5 get ottt_st 5 525 exit 62 526 end 527 if ne osp_basehash get ottt_st 5 get ottt_st 6 get ottt_st 7 528 exit 62 529 end 530 nspec = sub get og 8 get ottt_st 6 531 ocwopen 4 532 ph = osp_wrpay get ottt_st 6 nspec 533 ocput8 0 OSPMAG 534 ocput8 8 get ottt_st 5 535 ocput8 16 get og 5 536 ocput8 24 get ottt_st 7 537 ocput8 32 nspec 538 ocput8 40 ph 539 ocwput 0 48 540 ocwend 4 541 oputc 83 542 oputc 80 543 oputc 69 544 oputc 88 545 oputc 84 546 oputc 32 547 oputu get ottt_st 5 548 oputc 32 549 oputu get og 5 550 oputc 32 551 oputu nspec 552 oputc 10 553 oflush 554 end 555 556 fn osp_rdhdr ai ulong bl ulong bh ulong to void 557 sz = ofsz ai 558 if lt sz 48 559 exit 60 560 end 561 if ne oprd ai 0 0 48 48 562 exit 60 563 end 564 if ne opw8 0 OSPMAG 565 exit 60 566 end 567 if ne opw8 8 bl 568 exit 62 569 end 570 if le opw8 16 bl 571 exit 62 572 end 573 if ne opw8 24 bh 574 exit 62 575 end 576 nspec = opw8 32 577 if ne sz add 48 mul nspec 8 578 exit 60 579 end 580 put ottt_st 1 opw8 16 581 put ottt_st 3 nspec 582 put ottt_st 4 opw8 40 583 end 584 585 note Shared helper: verify base & pack hashes, attach specialist layers onto base in memory 586 fn osp_attach bkai ulong pkai ulong to void 587 ockload bkai 588 put ottt_st 0 get og 5 589 put ottt_st 2 get og 33 590 osp_rdhdr pkai get ottt_st 0 osp_basehash get ottt_st 0 get ottt_st 2 591 ogrowsnap get og 8 592 put og 5 get ottt_st 1 593 if not ogeom 594 exit 12 595 end 596 if ne sub get og 8 get ottt_st 2 get ottt_st 3 597 exit 62 598 end 599 ozerom mul 2 get og 8 600 ogrowcopy get ottt_st 2 601 if ne osp_rdpay pkai get ottt_st 2 get ottt_st 3 get ottt_st 4 602 exit 61 603 end 604 end 605 606 note spapp BASE.ck PACK.sp OUT.ck: verify base & pack hashes, attach specialist layers onto base 607 fn cmdspapp to void 608 if ne oargc 5 609 exit 2 610 end 611 osp_attach 2 3 612 ocksave 4 613 oputc 83 614 oputc 80 615 oputc 65 616 oputc 80 617 oputc 80 618 oputc 32 619 oputu get ottt_st 0 620 oputc 32 621 oputu get ottt_st 1 622 oputc 32 623 oputu get ottt_st 3 624 oputc 10 625 oflush 626 end 627 628 note spsamp BASE.ck PACK.sp N TEMPMILLI PROMPT SEED [MERGES] 629 note Attach specialist pack in memory (no 403 MB temp checkpoint) and sample from PROMPT (argv[6]) 630 fn cmdspsamp to void 631 na = oargc 632 if and ne na 8 ne na 9 633 exit 2 634 end 635 osp_attach 2 3 636 nn = oargu 4 637 if gt nn 999999 638 exit 2 639 end 640 tm = oargu 5 641 st = oargu 7 642 v = get og 0 643 if gt v 256 644 if eq na 8 645 exit 2 646 end 647 obload 8 v 648 end 649 ochipup 650 osampleloaded st nn tm 651 end 652 653 note speval BASE.ck PACK.sp HELD W [MERGES] 654 note Attach specialist pack in memory and evaluate W windows on HELD 655 fn cmdspeval to void 656 na = oargc 657 if and ne na 6 ne na 7 658 exit 2 659 end 660 osp_attach 2 3 661 ww = oargu 5 662 v = get og 0 663 if gt v 256 664 if eq na 6 665 exit 2 666 end 667 obload 6 v 668 end 669 odopen 4 670 tt = get og 1 671 m = get odn 0 672 if eq ww 0 673 exit 23 674 end 675 if gt ww div sub m 1 tt 676 exit 23 677 end 678 ls = 0.0f64 679 nb = ulong 0 680 for w ulong ww 681 obrow 0 mul w tt 682 ls = add ls ofwd 0 683 if gt v 256 684 nb = add nb oevnb tt 685 end 686 end 687 lo = div ls f64 ww 688 bp = div lo 0.`6931471805599453` 689 if gt v 256 690 bp = div mul bp f64 mul ww tt f64 nb 691 end 692 oputc 69 693 oputc 32 694 oputu get og 41 695 oputc 32 696 oputu ww 697 oputc 32 698 oputl rmic lo 699 oputc 32 700 oputl rmic bp 701 oputc 10 702 oflush 703 end 704 705 note ---- 5. Frozen-Base Hidden-State Cache (OLLMFH01: fcache, trainfc) ---- 706 const OFHMAG ulong `3544412373522336847` 707 708 note Write oa[src .. src + n) as little-endian f64s starting at file offset pos; returns new pos 709 fn ofh_wroa pos ulong src ulong n ulong to ulong 710 done = ulong 0 711 while lt done n bound 1024 712 cnt = sub n done 713 if gt cnt OCKC 714 cnt = OCKC 715 end 716 for j ulong cnt 717 ocput8 mul j 8 bitcast ulong get oa add src add done j 718 end 719 nb = mul cnt 8 720 ocwput pos nb 721 pos = add pos nb 722 done = add done cnt 723 end 724 ret pos 725 end 726 727 note Run frozen base on window starting at token offset o, apply optional mask mkai, write to cache 728 fn ofh_win mkai ulong o ulong pos ulong to ulong 729 tt = get og 1 730 bl = get og 5 731 obrow 0 o 732 if ne mkai 0 733 if ne oprd mkai add o 1 0 tt tt 734 exit 70 735 end 736 for tm ulong tt 737 if eq get opw tm 0 738 put oby tm or get oby tm 65536 739 end 740 end 741 end 742 put okv 0 0 743 put ogkm 1 0 744 oemb 0 745 for l ulong bl 746 olayf l 747 end 748 for t ulong tt 749 ocput8 mul t 8 get oby t 750 end 751 ocwput pos mul tt 8 752 pos = add pos mul tt 8 753 ret ofh_wroa pos get og 15 mul tt get og 2 754 end 755 756 note fcache / fcachem shared driver 757 fn ofh_run bkai ulong tkai ulong mkai ulong ww ulong outai ulong to void 758 ockload bkai 759 odopen tkai 760 tt = get og 1 761 bl = get og 5 762 if or eq ww 0 gt ww div sub get odn 0 1 tt 763 exit 23 764 end 765 if gt add tt mul tt get og 2 262144 766 exit 12 767 end 768 if ne mkai 0 769 if ne ofsz mkai get odn 0 770 exit 21 771 end 772 end 773 bh = osp_basehash bl get og 33 774 ocwopen outai 775 ocput8 0 OFHMAG 776 ocput8 8 ww 777 ocput8 16 tt 778 ocput8 24 get og 2 779 ocput8 32 bl 780 ocput8 40 bh 781 ocwput 0 48 782 pos = ulong 48 783 put og 9 tt 784 for w ulong ww 785 pos = ofh_win mkai mul w tt pos 786 end 787 ocwend outai 788 oputc 70 789 oputc 67 790 oputc 65 791 oputc 67 792 oputc 72 793 oputc 69 794 oputc 32 795 oputu ww 796 oputc 32 797 oputu tt 798 oputc 32 799 oputu get og 2 800 oputc 32 801 oputu bl 802 oputc 10 803 oflush 804 end 805 806 fn cmdfcache to void 807 if ne oargc 6 808 exit 2 809 end 810 ofh_run 2 3 0 oargu 4 5 811 end 812 813 note fcachem BASE.ck TOKS MASK W OUT.hc (MASK: 1 byte per token; 0 masks loss at target y[t]) 814 fn cmdfcachem to void 815 if ne oargc 7 816 exit 2 817 end 818 ofh_run 2 3 4 oargu 5 6 819 end 820 821 note Read and verify OLLMFH01 header at arg ai; stores W in ottt_st[2], rec_bytes in ottt_st[3] 822 fn ofh_rdhdr ai ulong flay ulong bh ulong to void 823 sz = ofsz ai 824 if lt sz 48 825 exit 60 826 end 827 if ne oprd ai 0 0 48 48 828 exit 60 829 end 830 if ne opw8 0 OFHMAG 831 exit 60 832 end 833 ww = opw8 8 834 if eq ww 0 835 exit 60 836 end 837 tt = get og 1 838 dd = get og 2 839 if ne opw8 16 tt 840 exit 62 841 end 842 if ne opw8 24 dd 843 exit 62 844 end 845 if ne opw8 32 flay 846 exit 62 847 end 848 if ne opw8 40 bh 849 exit 62 850 end 851 rec = mul add tt mul tt dd 8 852 if gt rec `2097152` 853 exit 12 854 end 855 if ne sz add 48 mul ww rec 856 exit 60 857 end 858 put ottt_st 2 ww 859 put ottt_st 3 rec 860 end 861 862 note Load cached window w from arg ai into oby[0..T) and oa[oahin(flay)..+T*D) 863 fn ofh_load ai ulong w ulong flay ulong to void 864 tt = get og 1 865 td = mul tt get og 2 866 rec = get ottt_st 3 867 pos = add 48 mul w rec 868 if ne oprd ai pos 0 rec rec 869 exit 60 870 end 871 for t ulong tt 872 put oby t opw8 mul t 8 873 end 874 dst = oahin flay 875 off = mul tt 8 876 for i ulong td 877 put oa add dst i bitcast f64 opw8 add off mul i 8 878 end 879 end 880 881 note Masked head forward + backward over unmasked positions (oby[t] < 65536). 882 note When all T positions are unmasked, matches ohead 0 + obwd 0 sc bit-for-bit. 883 fn ofh_hb flay ulong b ulong bb ulong to void 884 ct = get og 9 885 mc = ulong 0 886 ls = 0.0f64 887 for t ulong ct 888 if lt get oby t 65536 889 ls = add ls oheadr 0 t 890 mc = add mc 1 891 end 892 end 893 if eq mc 0 894 put olos b 0.0f64 895 ret 896 end 897 put olos b div ls f64 mc 898 sc = div 1.0f64 f64 mul mc bb 899 ozero get og 19 mul ct get og 2 900 for t2 ulong ct 901 if lt get oby t2 65536 902 ohbwd 0 t2 sc 903 end 904 end 905 ll = get og 5 906 for i ulong sub ll flay 907 olayb sub sub ll 1 i 908 end 909 end 910 911 note Forward+backward of one cached window w for batch slot b 912 fn ofh_one ai ulong w ulong flay ulong b ulong bb ulong to void 913 ofh_load ai w flay 914 put okv 0 0 915 put ogkm 1 0 916 nl = sub get og 5 flay 917 for j ulong nl 918 olayf add flay j 919 end 920 ofh_hb flay b bb 921 end 922 923 note One cached frozen-core step: skips embeddings + layers 0..flay-1 completely 924 fn ofh_step ai ulong flay ulong to f64 925 s = get og 41 926 bb = get og 6 927 p = get og 8 928 put og 9 get og 1 929 put og 10 p 930 ozerog p p 931 for b ulong bb 932 idx = add mul s bb b 933 w = rem smx xor get og 40 mul idx `11400714819323198485` get ottt_st 2 934 ofh_one ai w flay b bb 935 end 936 put og 10 0 937 ogfold true 938 ls = olsum 939 oadam 940 put og 41 add s 1 941 ret ls 942 end 943 944 note trainfc CK CACHE.hc UNTIL EVERY FREEZE_LAYERS [BATCH] 945 fn cmdtrainfc to void 946 na = oargc 947 if and ne na 7 ne na 8 948 exit 2 949 end 950 ockload 2 951 until = oargu 4 952 every = oargu 5 953 flay = oargu 6 954 if or eq every 0 ge flay get og 5 955 exit 2 956 end 957 fz = add get og 31 mul flay get og 32 958 ofh_rdhdr 3 flay osp_basehash flay fz 959 put ottt_st 0 get og 6 960 put ottt_st 1 get og 44 961 if eq na 8 962 nb = oargu 7 963 if or eq nb 0 gt nb 64 964 exit 2 965 end 966 put og 6 nb 967 put og 44 1 968 end 969 put ofreeze 0 fz 970 put ofzlay 0 flay 971 put og 45 1 972 st = get og 41 973 while lt st until bound 999999 974 ls = ofh_step 3 flay 975 st = get og 41 976 if or eq rem st every 0 eq st until 977 put og 6 get ottt_st 0 978 put og 44 get ottt_st 1 979 ocksave 2 980 if eq na 8 981 put og 6 oargu 7 982 put og 44 1 983 end 984 oputc 70 985 oputc 67 986 oputc 32 987 oputu st 988 oputc 32 989 oputu flay 990 oputc 32 991 oputl rmic ls 992 oputc 10 993 oflush 994 end 995 end 996 put og 6 get ottt_st 0 997 put og 44 get ottt_st 1 998 put ofreeze 0 0 999 put ofzlay 0 0 1000 end 1001 1002 note ---- 6. Pure-Omega Specialist Fusion (spmerge, spstack) ---- 1003 1004 note Stream ns f64s from arg ai at offset 48 into ocs[dst .. dst + ns); returns payload FNV-1a 64 1005 fn osp_rd2c ai ulong dst ulong ns ulong to ulong 1006 h = ulong `14695981039346656037` 1007 pos = ulong 48 1008 done = ulong 0 1009 while lt done ns bound 1024 1010 cnt = sub ns done 1011 if gt cnt OCKC 1012 cnt = OCKC 1013 end 1014 nb = mul cnt 8 1015 if ne oprd ai pos 0 nb nb 1016 exit 60 1017 end 1018 h = ocfnvw h nb 1019 for j ulong cnt 1020 ocsp add dst add done j bitcast f64 opw8 mul j 8 1021 end 1022 pos = add pos nb 1023 done = add done cnt 1024 end 1025 ret h 1026 end 1027 1028 note Load and verify pack payload from arg ai into ocs[dst .. dst + nspec); exits 60/61/62 on error 1029 fn osp_rd2ocs ai ulong dst ulong bl ulong bh ulong wantl ulong to ulong 1030 osp_rdhdr ai bl bh 1031 sl = get ottt_st 1 1032 if and ne wantl 0 ne sl wantl 1033 exit 62 1034 end 1035 if ne osp_rd2c ai dst get ottt_st 3 get ottt_st 4 1036 exit 61 1037 end 1038 ret sl 1039 end 1040 1041 note Write OLLMSP01 pack at arg outai from ow[fz .. fz + ns) with header (bl, sl, bh, ns) 1042 fn osp_wrpack outai ulong bl ulong sl ulong bh ulong fz ulong ns ulong to void 1043 ocwopen outai 1044 ph = osp_wrpay fz ns 1045 ocput8 0 OSPMAG 1046 ocput8 8 bl 1047 ocput8 16 sl 1048 ocput8 24 bh 1049 ocput8 32 ns 1050 ocput8 40 ph 1051 ocwput 0 48 1052 ocwend outai 1053 end 1054 1055 note Compute exact grow initial weights W_0 for L=sl into ocs[0 .. ns) 1056 fn osp_init0 bl ulong sl ulong fz ulong ns ulong to void 1057 c = ocsinit 1058 ogrowsnap get og 8 1059 put og 5 sl 1060 if not ogeom 1061 exit 12 1062 end 1063 oinit 1064 ogrowcopy fz 1065 for j ulong get og 2 1066 owp add get og 33 j ocsg add fz j 1067 end 1068 ogrowsilent bl 1069 i = ulong 0 1070 note at most `16777216` passes, run as aligned chunks of 524288 (2^19): the seeded omc takes a while bound 1071 note of at most 999999. 33 chunks cover any `16777216` consecutive values of i, so no run that the 1072 note bound `16777216` allowed is refused here. 1073 while lt i ns bound 33 1074 while lt i ns bound 524288 1075 ocsp i owg add fz i 1076 i = add i 1 1077 if eq and i 524287 0 1078 break 1079 end 1080 end 1081 end 1082 end 1083 1084 note Mode 0: weighted linear soup 1085 fn osp_m0 kk ulong fz ulong ns ulong to void 1086 sw = 0.0f64 1087 for k ulong kk 1088 sw = add sw get odl1 k 1089 end 1090 if le sw 0.0 1091 exit 2 1092 end 1093 i = ulong 0 1094 note at most `16777216` passes, run as aligned chunks of 524288 (2^19): the seeded omc takes a while bound 1095 note of at most 999999. 33 chunks cover any `16777216` consecutive values of i, so no run that the 1096 note bound `16777216` allowed is refused here. 1097 while lt i ns bound 33 1098 while lt i ns bound 524288 1099 acc = 0.0f64 1100 for k2 ulong kk 1101 acc = add acc mul get odl1 k2 ocsg add mul add k2 1 ns i 1102 end 1103 owp add fz i div acc sw 1104 i = add i 1 1105 if eq and i 524287 0 1106 break 1107 end 1108 end 1109 end 1110 end 1111 1112 note Mode 1: task-arithmetic sum over exact grow init W_0 1113 fn osp_m1 kk ulong fz ulong ns ulong to void 1114 i = ulong 0 1115 note at most `16777216` passes, run as aligned chunks of 524288 (2^19): the seeded omc takes a while bound 1116 note of at most 999999. 33 chunks cover any `16777216` consecutive values of i, so no run that the 1117 note bound `16777216` allowed is refused here. 1118 while lt i ns bound 33 1119 while lt i ns bound 524288 1120 w0 = ocsg i 1121 acc = w0 1122 for k ulong kk 1123 d = sub ocsg add mul add k 1 ns i w0 1124 acc = add acc mul get odl1 k d 1125 end 1126 owp add fz i acc 1127 i = add i 1 1128 if eq and i 524287 0 1129 break 1130 end 1131 end 1132 end 1133 end 1134 1135 note Compute TIES RMS threshold 0.5*rms(W_k - W_0) into odl2[k] 1136 fn osp_ties_tau kk ulong ns ulong to void 1137 for k ulong kk 1138 ss = 0.0f64 1139 off = mul add k 1 ns 1140 i = ulong 0 1141 note at most `16777216` passes, run as aligned chunks of 524288 (2^19): the seeded omc takes a while bound 1142 note of at most 999999. 33 chunks cover any `16777216` consecutive values of i, so no run that the 1143 note bound `16777216` allowed is refused here. 1144 while lt i ns bound 33 1145 while lt i ns bound 524288 1146 d = sub ocsg add off i ocsg i 1147 ss = add ss mul d d 1148 i = add i 1 1149 if eq and i 524287 0 1150 break 1151 end 1152 end 1153 end 1154 put odl2 k mul 0.5 fsqrt div ss f64 ns 1155 end 1156 end 1157 1158 note Elect TIES sign at i: 0=none, 1=pos, 2=neg 1159 fn osp_m2_sg kk ulong ns ulong i ulong to ulong 1160 w0 = ocsg i 1161 ps = 0.0f64 1162 ng = 0.0f64 1163 for k ulong kk 1164 d = sub ocsg add mul add k 1 ns i w0 1165 if ge fabs d get odl2 k 1166 if gt d 0.0 1167 ps = add ps mul get odl1 k d 1168 else 1169 ng = add ng mul get odl1 k sub 0.0f64 d 1170 end 1171 end 1172 end 1173 if and eq ps 0.0 eq ng 0.0 1174 ret 0 1175 end 1176 if ge ps ng 1177 ret 1 1178 end 1179 ret 2 1180 end 1181 1182 note Mode 2: TIES trimmed sign-consensus merge at parameter index i 1183 fn osp_m2_i kk ulong ns ulong i ulong to f64 1184 sg = osp_m2_sg kk ns i 1185 w0 = ocsg i 1186 if eq sg 0 1187 ret w0 1188 end 1189 num = 0.0f64 1190 den = 0.0f64 1191 for k ulong kk 1192 d = sub ocsg add mul add k 1 ns i w0 1193 if ge fabs d get odl2 k 1194 ag = false 1195 if and eq sg 1 gt d 0.0 1196 ag = true 1197 end 1198 if and eq sg 2 lt d 0.0 1199 ag = true 1200 end 1201 if ag 1202 wk = get odl1 k 1203 num = add num mul wk d 1204 den = add den wk 1205 end 1206 end 1207 end 1208 if eq den 0.0 1209 ret w0 1210 end 1211 ret add w0 div num den 1212 end 1213 1214 fn osp_m2 kk ulong fz ulong ns ulong to void 1215 osp_ties_tau kk ns 1216 i = ulong 0 1217 note at most `16777216` passes, run as aligned chunks of 524288 (2^19): the seeded omc takes a while bound 1218 note of at most 999999. 33 chunks cover any `16777216` consecutive values of i, so no run that the 1219 note bound `16777216` allowed is refused here. 1220 while lt i ns bound 33 1221 while lt i ns bound 524288 1222 owp add fz i osp_m2_i kk ns i 1223 i = add i 1 1224 if eq and i 524287 0 1225 break 1226 end 1227 end 1228 end 1229 end 1230 1231 fn osp_mgrun mode ulong kk ulong fz ulong ns ulong to void 1232 if eq mode 0 1233 osp_m0 kk fz ns 1234 ret 1235 end 1236 if eq mode 1 1237 osp_m1 kk fz ns 1238 ret 1239 end 1240 osp_m2 kk fz ns 1241 end 1242 1243 note spmerge BASE.ck MODE OUT.sp W1 P1.sp W2 P2.sp [W3 P3.sp [W4 P4.sp]] 1244 fn cmdspmerge to void 1245 na = oargc 1246 if or lt na 9 or gt na 13 ne rem sub na 5 2 0 1247 exit 2 1248 end 1249 kk = div sub na 5 2 1250 if gt oargu 3 2 1251 exit 2 1252 end 1253 ockload 2 1254 bl = get og 5 1255 fz = get og 33 1256 bh = osp_basehash bl fz 1257 osp_rdhdr 6 bl bh 1258 sl = get ottt_st 1 1259 ns = get ottt_st 3 1260 osp_init0 bl sl fz ns 1261 for k ulong kk 1262 put odl1 k div f64 oargu add 5 mul k 2 1000.0 1263 z = osp_rd2ocs add 6 mul k 2 mul add k 1 ns bl bh sl 1264 end 1265 osp_mgrun oargu 3 kk fz ns 1266 osp_wrpack 4 bl sl bh fz ns 1267 oputc 83 1268 oputc 80 1269 oputc 77 1270 oputc 82 1271 oputc 71 1272 oputc 32 1273 oputu oargu 3 1274 oputc 32 1275 oputu kk 1276 oputc 32 1277 oputu sl 1278 oputc 32 1279 oputu ns 1280 oputc 10 1281 oflush 1282 end 1283 1284 note Copy n f64s from ocs[src..) into ow[dst..) 1285 fn osp_c2w dst ulong src ulong n ulong to void 1286 i = ulong 0 1287 note at most `16777216` passes, run as aligned chunks of 524288 (2^19): the seeded omc takes a while bound 1288 note of at most 999999. 33 chunks cover any `16777216` consecutive values of i, so no run that the 1289 note bound `16777216` allowed is refused here. 1290 while lt i n bound 33 1291 while lt i n bound 524288 1292 owp add dst i ocsg add src i 1293 i = add i 1 1294 if eq and i 524287 0 1295 break 1296 end 1297 end 1298 end 1299 end 1300 1301 note Scale Wo and W2 of layers [l0 .. l0+cnt) in ow by sc 1302 fn osp_sclays l0 ulong cnt ulong sc f64 to void 1303 d = get og 2 1304 for k ulong cnt 1305 l = add l0 k 1306 oiscale opwo l mul d d sc 1307 oiscale opw2 l mul d get og 4 sc 1308 end 1309 end 1310 1311 fn osp_stkgf dst ulong o1 ulong o2 ulong to void 1312 for g ulong get og 2 1313 v = mul 0.5 add ocsg add o1 g ocsg add o2 g 1314 owp add dst g v 1315 end 1316 end 1317 1318 note Finish vertical stack copy + scaling + gf average + pack write; ottt_st[5..7] = bl, fz, bh 1319 fn osp_stkfin d1 ulong n1 ulong d2 ulong to void 1320 bl = get ottt_st 5 1321 fz = get ottt_st 6 1322 b1 = mul d1 get og 32 1323 b2 = mul d2 get og 32 1324 osp_c2w fz 0 b1 1325 osp_c2w add fz b1 n1 b2 1326 osp_sclays bl d1 div f64 oargu 5 1000.0 1327 osp_sclays add bl d1 d2 div f64 oargu 6 1000.0 1328 osp_stkgf add fz add b1 b2 b1 add n1 b2 1329 ns = add add b1 b2 get og 2 1330 osp_wrpack 7 bl get og 5 get ottt_st 7 fz ns 1331 oputc 83 1332 oputc 80 1333 oputc 83 1334 oputc 84 1335 oputc 75 1336 oputc 32 1337 oputu bl 1338 oputc 32 1339 oputu get og 5 1340 oputc 32 1341 oputu ns 1342 oputc 10 1343 oflush 1344 end 1345 1346 note spstack BASE.ck P1.sp P2.sp S1_MILLI S2_MILLI OUT.sp 1347 note Vertically stack P1 layers then P2 layers on top of frozen BASE.ck 1348 fn cmdspstack to void 1349 if ne oargc 8 1350 exit 2 1351 end 1352 c = ocsinit 1353 ockload 2 1354 bl = get og 5 1355 fz = get og 33 1356 bh = osp_basehash bl fz 1357 put ottt_st 5 bl 1358 put ottt_st 6 fz 1359 put ottt_st 7 bh 1360 d1 = sub osp_rd2ocs 3 0 bl bh 0 bl 1361 n1 = get ottt_st 3 1362 d2 = sub osp_rd2ocs 4 n1 bl bh 0 bl 1363 put og 5 add bl add d1 d2 1364 if not ogeom 1365 exit 12 1366 end 1367 osp_stkfin d1 n1 d2 1368 end 1369 1370 note ---- 7. LLaMA-Pro Block-Expansion Growth (growpro) ---- 1371 note Clones the last base layer's trained (g1, Wq, Wk, Wv, g2, W1) into each added layer 1372 note and zeroes only (Wo, W2) so step-0 output is bit-identical to base while starting at 1373 note the base layer's exact weight scale (44x sharper Q*K logits than random oinit). 1374 fn osp_clone oldl ulong ll ulong to void 1375 lstr = get og 32 1376 src = add get og 31 mul sub oldl 1 lstr 1377 for k ulong sub ll oldl 1378 dst = add get og 31 mul add oldl k lstr 1379 osp_c2w dst src lstr 1380 end 1381 end 1382 1383 fn cmdgrowpro to void 1384 if ne oargc 7 1385 exit 2 1386 end 1387 ockload 2 1388 ll = oargu 4 1389 tt = oargu 5 1390 lr = oargu 6 1391 if or le ll get og 5 or eq tt 0 gt tt 999999 1392 exit 12 1393 end 1394 if eq lr 0 1395 exit 12 1396 end 1397 oldl = get og 5 1398 oldg = get og 33 1399 ogrowsnap get og 8 1400 put og 5 ll 1401 if not ogeom 1402 exit 12 1403 end 1404 put og 41 0 1405 put og 42 tt 1406 put og 43 bitcast ulong div f64 lr `1000000`.0 1407 ozerom mul 2 get og 8 1408 ogrowcopy oldg 1409 for j ulong get og 2 1410 owp add get og 33 j ocsg add oldg j 1411 end 1412 osp_clone oldl ll 1413 ogrowsilent oldl 1414 ocksave 3 1415 oputc 71 1416 oputc 80 1417 oputc 32 1418 oputu oldl 1419 oputc 32 1420 oputu ll 1421 oputc 32 1422 oputu get og 8 1423 oputc 10 1424 oflush 1425 end 1426 1427 note ---- 8. Shared-Base Product-of-Experts Parallel Ensemble (spens) ---- 1428 note spens BASE.ck P1.sp P2.sp W1_MILLI N PROMPT TEMPMILLI SEED [MERGES] 1429 note Runs frozen base layers 0..bl-1 ONCE per token, then runs P1 and P2 specialist layers 1430 note in parallel over the shared H_base and fuses log_softmax(z1) & log_softmax(z2). 1431 note Works across DIFFERENT init basins (grow + growpro) with zero weight-averaging interference! 1432 1433 fn osp_hsnap dst ulong src ulong n ulong to void 1434 i = ulong 0 1435 while lt i n bound 262144 1436 ocsp add dst i get oa add src i 1437 i = add i 1 1438 end 1439 end 1440 1441 fn osp_hrest dst ulong src ulong n ulong to void 1442 i = ulong 0 1443 while lt i n bound 262144 1444 put oa add dst i ocsg add src i 1445 i = add i 1 1446 end 1447 end 1448 1449 note Run final norm + klogit + log_softmax on row nc-1 into odl1 (which=1) or odl2 (which=2) 1450 fn osp_ens_head which ulong nc ulong to void 1451 d = get og 2 1452 nc1 = sub nc 1 1453 r = mul nc1 d 1454 z = add get og 17 r 1455 hf = add get og 15 r 1456 s0 = add get og 16 nc1 1457 frms hf get og 33 z s0 1458 klogit z get og 27 get og 0 d 1459 odl_lsm get og 27 get og 0 which 1460 end 1461 1462 note Run one specialist branch (P1 if which=1 else P2) from cached H_base -> log_softmax in odl1/odl2 1463 fn osp_ens_br which ulong nc ulong to void 1464 bl = get oens 0 1465 sl = get oens 2 1466 if eq which 1 1467 osp_c2w get oens 1 get oens 3 get oens 4 1468 else 1469 sl = get oens 5 1470 osp_c2w get oens 1 get oens 6 get oens 7 1471 end 1472 ho = oahin bl 1473 hs = add get oens 6 get oens 7 1474 osp_hrest ho hs mul nc get og 2 1475 put og 9 nc 1476 put okv 0 0 1477 put ogkm 1 0 1478 for k ulong sub sl bl 1479 olayf add bl k 1480 end 1481 osp_ens_head which nc 1482 end 1483 1484 fn osp_ens_fuse w1 f64 to void 1485 pr = get og 27 1486 w2 = sub 1.0f64 w1 1487 for j ulong get og 0 1488 a = mul w1 get odl1 j 1489 b = mul w2 get odl2 j 1490 put oa add pr j add a b 1491 end 1492 end 1493 1494 note One PoE decode step: shared base 0..bl-1 once, then P1 + P2 branches, fused into TMP (og[27]) 1495 fn osp_ens_step w1 f64 st ulong tm ulong to ulong 1496 nc = get og 9 1497 bl = get oens 0 1498 put okv 0 0 1499 put ogkm 1 0 1500 oemb 0 1501 for l ulong bl 1502 olayf l 1503 end 1504 hs = add get oens 6 get oens 7 1505 ho = oahin bl 1506 osp_hsnap hs ho mul nc get og 2 1507 osp_ens_br 1 nc 1508 osp_ens_br 2 nc 1509 osp_ens_fuse w1 1510 if eq tm 0 1511 ret oargmax 1512 end 1513 ret odraw st div f64 tm 1000.0 1514 end 1515 1516 fn osp_ens_loop nn ulong w1 f64 st ulong tm ulong to void 1517 v = get og 0 1518 for g ulong nn 1519 c = osp_ens_step w1 st tm 1520 if ne tm 0 1521 st = add st `11400714819323198485` 1522 end 1523 if eq c 0 1524 break 1525 end 1526 if gt v 256 1527 obtput c 1528 else 1529 oputc c 1530 end 1531 oflush 1532 ocpush c 1533 end 1534 oflush 1535 end 1536 1537 fn osp_ens_init to void 1538 c = ocsinit 1539 ockload 2 1540 bl = get og 5 1541 fz = get og 33 1542 p0 = get og 8 1543 bh = osp_basehash bl fz 1544 ogrowsnap p0 1545 l1 = osp_rd2ocs 3 p0 bl bh 0 1546 n1 = get ottt_st 3 1547 l2 = osp_rd2ocs 4 add p0 n1 bl bh l1 1548 put oens 0 bl 1549 put oens 1 fz 1550 put oens 2 l1 1551 put oens 3 p0 1552 put oens 4 n1 1553 put oens 5 l2 1554 put oens 6 add p0 n1 1555 put oens 7 get ottt_st 3 1556 put og 5 l1 1557 if not ogeom 1558 exit 12 1559 end 1560 ogrowcopy fz 1561 end 1562 1563 note spens BASE.ck P1.sp P2.sp W1_MILLI PROMPT N TEMPMILLI SEED [MERGES] 1564 fn cmdspens to void 1565 na = oargc 1566 if and ne na 10 ne na 11 1567 exit 2 1568 end 1569 osp_ens_init 1570 v = get og 0 1571 if gt v 256 1572 if eq na 10 1573 exit 2 1574 end 1575 obload 10 v 1576 end 1577 ottt_prompt v 1578 osp_ens_loop oargu 7 div f64 oargu 5 1000.0 oargu 9 oargu 8 1579 end 1580 1581 note ---- 9. Multi-Link Merkle Specialist Chains (spchainapp, spchaineval, spchainsamp) ---- 1582 1583 note Chunked copy: ocs[dst..dst+n) = ow[src..src+n) 1584 fn osp_w2c dst ulong src ulong n ulong to void 1585 for q ulong ocn n 1586 i = mul q OCH 1587 ie = oce q n 1588 while lt i ie bound 999999 1589 ocsp add dst i owg add src i 1590 i = add i 1 1591 end 1592 end 1593 end 1594 1595 note Chunked copy: ow[dst..dst+n) = ocs[src..src+n) 1596 fn osp_c2wb dst ulong src ulong n ulong to void 1597 for q ulong ocn n 1598 i = mul q OCH 1599 ie = oce q n 1600 while lt i ie bound 999999 1601 owp add dst i ocsg add src i 1602 i = add i 1 1603 end 1604 end 1605 end 1606 1607 note Verify payload FNV-1a 64 of pack at argv[ai] without writing ow (exits 60/61 on error) 1608 fn osp_chkpay ai ulong ns ulong wantph ulong to void 1609 h = ulong `14695981039346656037` 1610 pos = ulong 48 1611 done = ulong 0 1612 while lt done ns bound 1024 1613 cnt = sub ns done 1614 if gt cnt OCKC 1615 cnt = OCKC 1616 end 1617 nb = mul cnt 8 1618 if ne oprd ai pos 0 nb nb 1619 exit 60 1620 end 1621 h = ocfnvw h nb 1622 pos = add pos nb 1623 done = add done cnt 1624 end 1625 if ne h wantph 1626 exit 61 1627 end 1628 end 1629 1630 note Verify and attach one OLLMSP01 pack at argv[ai] onto the running model in ow 1631 fn osp_chain_link ai ulong to void 1632 cur_l = get og 5 1633 cur_fz = get og 33 1634 osp_rdhdr ai cur_l osp_basehash cur_l cur_fz 1635 ogrowsnap get og 8 1636 put og 5 get ottt_st 1 1637 if not ogeom 1638 exit 12 1639 end 1640 if ne sub get og 8 cur_fz get ottt_st 3 1641 exit 62 1642 end 1643 ozerom mul 2 get og 8 1644 ogrowcopy cur_fz 1645 if ne osp_rdpay ai cur_fz get ottt_st 3 get ottt_st 4 1646 exit 61 1647 end 1648 end 1649 1650 note Load BASE.ck at argv[bkai] and sequentially attach K (1..8) Merkle-chained packs at argv[p0ai..] 1651 fn ospchainload bkai ulong k ulong p0ai ulong to void 1652 if or eq k 0 gt k 8 1653 exit 2 1654 end 1655 ockload bkai 1656 put ottt_st 0 get og 5 1657 for j ulong k 1658 osp_chain_link add p0ai j 1659 end 1660 end 1661 1662 note Load prompt from argv[pai] into obx with leading token 0 1663 fn osp_prompt pai ulong v ulong to void 1664 put og 9 0 1665 ocpush 0 1666 if gt v 256 1667 r = oargr pai 1668 if or lt r 0 gt r 4000 1669 exit 2 1670 end 1671 np = obprompt pai 1672 for i ulong np 1673 ocpush get obtk i 1674 end 1675 else 1676 r = oargr pai 1677 if or lt r 0 gt r 4096 1678 exit 2 1679 end 1680 for i ulong ulong r 1681 ocpush ulong get oarg i 1682 end 1683 end 1684 end 1685 1686 note Sample nn tokens from the currently loaded model + context 1687 fn osp_samploop seed ulong nn ulong tm ulong to void 1688 if gt nn 999999 1689 exit 2 1690 end 1691 st = seed 1692 v = get og 0 1693 for g ulong nn 1694 c = osstep st tm 1695 if ne tm 0 1696 st = add st `11400714819323198485` 1697 end 1698 if eq c 0 1699 break 1700 end 1701 if gt v 256 1702 obtput c 1703 else 1704 oputc c 1705 end 1706 oflush 1707 ocpush c 1708 end 1709 oflush 1710 end 1711 1712 note spchainapp BASE.ck OUT.ck K P1.sp ... PK.sp 1713 fn cmdspchainapp to void 1714 na = oargc 1715 if lt na 6 1716 exit 2 1717 end 1718 k = oargu 4 1719 if or eq k 0 or gt k 8 ne na add 5 k 1720 exit 2 1721 end 1722 ospchainload 2 k 5 1723 ocksave 3 1724 oputc 83 1725 oputc 80 1726 oputc 67 1727 oputc 72 1728 oputc 65 1729 oputc 80 1730 oputc 80 1731 oputc 32 1732 oputu get ottt_st 0 1733 oputc 32 1734 oputu get og 5 1735 oputc 32 1736 oputu k 1737 oputc 32 1738 oputu get og 8 1739 oputc 10 1740 oflush 1741 end 1742 1743 note spchaineval BASE.ck HELD W MERGES K P1.sp ... PK.sp 1744 fn cmdspchaineval to void 1745 na = oargc 1746 if lt na 8 1747 exit 2 1748 end 1749 k = oargu 6 1750 if or eq k 0 or gt k 8 ne na add 7 k 1751 exit 2 1752 end 1753 ospchainload 2 k 7 1754 ww = oargu 4 1755 v = get og 0 1756 if gt v 256 1757 obload 5 v 1758 end 1759 odopen 3 1760 tt = get og 1 1761 m = get odn 0 1762 if eq ww 0 1763 exit 23 1764 end 1765 if gt ww div sub m 1 tt 1766 exit 23 1767 end 1768 ls = 0.0f64 1769 nb = ulong 0 1770 for w ulong ww 1771 obrow 0 mul w tt 1772 ls = add ls ofwd 0 1773 if gt v 256 1774 nb = add nb oevnb tt 1775 end 1776 end 1777 lo = div ls f64 ww 1778 bp = div lo 0.`6931471805599453` 1779 if gt v 256 1780 bp = div mul bp f64 mul ww tt f64 nb 1781 end 1782 oputc 69 1783 oputc 32 1784 oputu get og 41 1785 oputc 32 1786 oputu ww 1787 oputc 32 1788 oputl rmic lo 1789 oputc 32 1790 oputl rmic bp 1791 oputc 10 1792 oflush 1793 end 1794 1795 note spchainsamp BASE.ck N TEMPMILLI PROMPT SEED MERGES K P1.sp ... PK.sp 1796 fn cmdspchainsamp to void 1797 na = oargc 1798 if lt na 10 1799 exit 2 1800 end 1801 k = oargu 8 1802 if or eq k 0 or gt k 8 ne na add 9 k 1803 exit 2 1804 end 1805 ospchainload 2 k 9 1806 nn = oargu 3 1807 if gt nn 999999 1808 exit 2 1809 end 1810 tm = oargu 4 1811 st = oargu 6 1812 v = get og 0 1813 if gt v 256 1814 obload 7 v 1815 end 1816 ochipup 1817 osp_prompt 5 v 1818 osp_samploop st nn tm 1819 end 1820 1821 note ---- 10. DNA-Style Multi-Helix Chain Clipping (spclip, S = 2..4 strands) ---- 1822 note spclip BASE.ck MODE PROMPT N TEMPMILLI SEED MERGES S W1 K1 A1..AK1 W2 K2 B1..BK2 [W3 K3 C1..CK3 [W4 K4 D1..DK4]] 1823 note MODE=0: normalized prior PoE (w_s / sum(w)); MODE=1: entropy-gated multi-helix (u_s = w_s / (H_s + 0.001)). 1824 1825 note Hidden-state output offset in oa after running layers 0..l-1 (l >= 1) 1826 fn osp_hout l ulong to ulong 1827 if lt l get og 5 1828 ret oahin l 1829 end 1830 ret get og 15 1831 end 1832 1833 note Parse spclip CLI arguments into ocl_st, ocl_w, ocl_k, ocl_a0 1834 fn osp_clip_parse to void 1835 na = oargc 1836 if lt na 16 1837 exit 2 1838 end 1839 md = oargu 3 1840 ss = oargu 9 1841 if or gt md 1 or lt ss 2 gt ss 4 1842 exit 2 1843 end 1844 put ocl_st 0 md 1845 put ocl_st 1 ss 1846 idx = ulong 10 1847 sw = 0.0f64 1848 for s ulong ss 1849 if gt add idx 2 na 1850 exit 2 1851 end 1852 ws = div f64 oargu idx 1000.0 1853 ks = oargu add idx 1 1854 if or eq ks 0 gt ks 8 1855 exit 2 1856 end 1857 if gt add add idx 2 ks na 1858 exit 2 1859 end 1860 put ocl_w s ws 1861 sw = add sw ws 1862 put ocl_k s ks 1863 put ocl_a0 s add idx 2 1864 idx = add add idx 2 ks 1865 end 1866 if or ne idx na le sw 0.0 1867 exit 2 1868 end 1869 end 1870 1871 note True iff all ss strands share an identical valid pack at link index j on top of current ow 1872 fn osp_clip_same j ulong ss ulong to bool 1873 bh = osp_basehash get og 5 get og 33 1874 osp_rdhdr add get ocl_a0 0 j get og 5 bh 1875 sl0 = get ottt_st 1 1876 ns0 = get ottt_st 3 1877 ph0 = get ottt_st 4 1878 s = ulong 1 1879 while lt s ss bound 4 1880 osp_rdhdr add get ocl_a0 s j get og 5 bh 1881 if ne get ottt_st 1 sl0 1882 ret false 1883 end 1884 if ne get ottt_st 3 ns0 1885 ret false 1886 end 1887 if ne get ottt_st 4 ph0 1888 ret false 1889 end 1890 s = add s 1 1891 end 1892 s = ulong 1 1893 while lt s ss bound 4 1894 osp_chkpay add get ocl_a0 s j ns0 ph0 1895 s = add s 1 1896 end 1897 ret true 1898 end 1899 1900 note Load longest common prefix of packs across all S strands into ow; save trunk_gf in odl2 1901 fn osp_clip_trunk to void 1902 ss = get ocl_st 1 1903 mink = get ocl_k 0 1904 for s ulong ss 1905 if lt get ocl_k s mink 1906 mink = get ocl_k s 1907 end 1908 end 1909 comm = ulong 0 1910 for j ulong mink 1911 if not osp_clip_same j ss 1912 break 1913 end 1914 osp_chain_link add get ocl_a0 0 j 1915 comm = add comm 1 1916 end 1917 put ocl_st 3 get og 5 1918 put ocl_st 4 get og 33 1919 put ocl_st 6 comm 1920 for g ulong get og 2 1921 put odl2 g owg add get og 33 g 1922 end 1923 end 1924 1925 note Peek final spec_L of each strand's last pack to find max_L across all S strands 1926 fn osp_clip_maxl to ulong 1927 ss = get ocl_st 1 1928 comm = get ocl_st 6 1929 ml = get ocl_st 3 1930 for s ulong ss 1931 ks = get ocl_k s 1932 if gt ks comm 1933 ai = add get ocl_a0 s sub ks 1 1934 if lt ofsz ai 48 1935 exit 60 1936 end 1937 if ne oprd ai 0 0 48 48 1938 exit 60 1939 end 1940 if ne opw8 0 OSPMAG 1941 exit 60 1942 end 1943 sl = opw8 16 1944 if gt sl ml 1945 ml = sl 1946 end 1947 end 1948 end 1949 if gt ml 16 1950 exit 12 1951 end 1952 ret ml 1953 end 1954 1955 note Load one non-shared link ai onto (cur_l, cur_fz); returns new spec_L 1956 fn osp_clip_1link ai ulong cur_l ulong cur_fz ulong to ulong 1957 osp_rdhdr ai cur_l osp_basehash cur_l cur_fz 1958 sl = get ottt_st 1 1959 ns = get ottt_st 3 1960 if gt sl get og 5 1961 exit 62 1962 end 1963 wn = mul sub sl cur_l get og 32 1964 if ne ns add wn get og 2 1965 exit 62 1966 end 1967 if ne osp_rdpay ai cur_fz ns get ottt_st 4 1968 exit 61 1969 end 1970 ret sl 1971 end 1972 1973 note Load remaining links comm..ks-1 of strand s into ow[fzt..); returns final depth cur_l 1974 fn osp_clip_slinks s ulong to ulong 1975 cur_l = get ocl_st 3 1976 cur_fz = get ocl_st 4 1977 j = get ocl_st 6 1978 ks = get ocl_k s 1979 while lt j ks bound 16 1980 sl = osp_clip_1link add get ocl_a0 s j cur_l cur_fz 1981 cur_l = sl 1982 cur_fz = add get og 31 mul sl get og 32 1983 j = add j 1 1984 end 1985 ret cur_l 1986 end 1987 1988 note Verify & store strand s's remaining layer weights + gf into ocs 1989 fn osp_clip_strand s ulong to void 1990 comm = get ocl_st 6 1991 ks = get ocl_k s 1992 tl = get ocl_st 3 1993 fzt = get ocl_st 4 1994 oc = get ocl_st 8 1995 d = get og 2 1996 cap = ocsinit 1997 if eq ks comm 1998 if gt add oc d cap 1999 exit 12 2000 end 2001 for g ulong d 2002 ocsp add oc g get odl2 g 2003 end 2004 put ocl_sl s tl 2005 put ocl_wo s oc 2006 put ocl_wn s 0 2007 put ocl_st 8 add oc d 2008 ret 2009 end 2010 cl = osp_clip_slinks s 2011 wn = mul sub cl tl get og 32 2012 ntot = add wn d 2013 if gt add oc ntot cap 2014 exit 12 2015 end 2016 osp_w2c oc fzt ntot 2017 put ocl_sl s cl 2018 put ocl_wo s oc 2019 put ocl_wn s wn 2020 put ocl_st 8 add oc ntot 2021 end 2022 2023 note Initialize spclip: load BASE.ck, common trunk, grow to max_L, store all S strand suffixes in ocs 2024 fn osp_clip_init to void 2025 c = ocsinit 2026 ockload 2 2027 put ocl_st 2 get og 5 2028 osp_clip_trunk 2029 ml = osp_clip_maxl 2030 put ocl_st 5 ml 2031 if gt ml get ocl_st 3 2032 ogrowsnap get og 8 2033 put og 5 ml 2034 if not ogeom 2035 exit 12 2036 end 2037 ogrowcopy get ocl_st 4 2038 end 2039 td = mul get og 1 get og 2 2040 put ocl_st 7 0 2041 put ocl_st 9 td 2042 put ocl_st 8 add td mul get ocl_st 1 get og 0 2043 for s ulong get ocl_st 1 2044 osp_clip_strand s 2045 end 2046 end 2047 2048 note Compute log_softmax of TMP[0..V) into ocs[logp_off + s*V .. +V) and Shannon entropy into ocl_ent[s] 2049 fn osp_clip_lsm s ulong to void 2050 pr = get og 27 2051 v = get og 0 2052 m = bitcast f64 ulong `18442240474082181120` 2053 for j ulong v 2054 x = get oa add pr j 2055 m = fmax m x 2056 put odl1 j x 2057 end 2058 sm = osoft pr v m 2059 lsm = flog sm 2060 dst = add get ocl_st 9 mul s v 2061 ent = 0.0f64 2062 for j2 ulong v 2063 lp = sub sub get odl1 j2 m lsm 2064 ocsp add dst j2 lp 2065 pj = get oa add pr j2 2066 if gt pj 0.0 2067 ent = sub ent mul pj lp 2068 end 2069 end 2070 if lt ent 0.0 2071 ent = 0.0f64 2072 end 2073 put ocl_ent s ent 2074 end 2075 2076 note Final norm + klogit on row nc-1 of osp_hout(ocl_sl[s]), then log_softmax + entropy 2077 fn osp_clip_head s ulong nc ulong to void 2078 d = get og 2 2079 nc1 = sub nc 1 2080 r = mul nc1 d 2081 z = add get og 17 r 2082 hf = add osp_hout get ocl_sl s r 2083 s0 = add get og 16 nc1 2084 frms hf get og 33 z s0 2085 klogit z get og 27 get og 0 d 2086 osp_clip_lsm s 2087 end 2088 2089 note Run strand s from cached H_trunk through layers trunk_L..L_s-1 and head 2090 fn osp_clip_br s ulong nc ulong to void 2091 tl = get ocl_st 3 2092 sl = get ocl_sl s 2093 wo = get ocl_wo s 2094 wn = get ocl_wn s 2095 if gt wn 0 2096 osp_c2wb get ocl_st 4 wo wn 2097 end 2098 osp_c2wb get og 33 add wo wn get og 2 2099 osp_hrest osp_hout tl get ocl_st 7 mul nc get og 2 2100 put og 9 nc 2101 put okv 0 0 2102 put ogkm 1 0 2103 for k ulong sub sl tl 2104 olayf add tl k 2105 end 2106 osp_clip_head s nc 2107 end 2108 2109 note Fuse S strands' log-probs in ocs into TMP[0..V) using MODE=0 (prior) or MODE=1 (entropy-gated) 2110 fn osp_clip_fuse to void 2111 md = get ocl_st 0 2112 ss = get ocl_st 1 2113 su = 0.0f64 2114 for s ulong ss 2115 u = get ocl_w s 2116 if eq md 1 2117 u = div u add get ocl_ent s 0.001 2118 end 2119 put ocl_al s u 2120 su = add su u 2121 end 2122 for s2 ulong ss 2123 put ocl_al s2 div get ocl_al s2 su 2124 end 2125 pr = get og 27 2126 v = get og 0 2127 lo = get ocl_st 9 2128 for j ulong v 2129 acc = 0.0f64 2130 for s3 ulong ss 2131 acc = add acc mul get ocl_al s3 ocsg add lo add mul s3 v j 2132 end 2133 put oa add pr j acc 2134 end 2135 end 2136 2137 note One DNA-clipped decode step: shared trunk ONCE, then S strands over H_trunk, fused into TMP 2138 fn osp_clip_step st ulong tm ulong to ulong 2139 nc = get og 9 2140 tl = get ocl_st 3 2141 put okv 0 0 2142 put ogkm 1 0 2143 oemb 0 2144 for l ulong tl 2145 olayf l 2146 end 2147 osp_hsnap get ocl_st 7 osp_hout tl mul nc get og 2 2148 for s ulong get ocl_st 1 2149 osp_clip_br s nc 2150 end 2151 osp_clip_fuse 2152 if eq tm 0 2153 ret oargmax 2154 end 2155 ret odraw st div f64 tm 1000.0 2156 end 2157 2158 fn osp_clip_loop nn ulong st ulong tm ulong to void 2159 v = get og 0 2160 for g ulong nn 2161 c = osp_clip_step st tm 2162 if ne tm 0 2163 st = add st `11400714819323198485` 2164 end 2165 if eq c 0 2166 break 2167 end 2168 if gt v 256 2169 obtput c 2170 else 2171 oputc c 2172 end 2173 oflush 2174 ocpush c 2175 end 2176 oflush 2177 end 2178 2179 fn cmdspclip to void 2180 osp_clip_parse 2181 nn = oargu 5 2182 if gt nn 999999 2183 exit 2 2184 end 2185 tm = oargu 6 2186 st = oargu 7 2187 osp_clip_init 2188 v = get og 0 2189 if gt v 256 2190 obload 8 v 2191 end 2192 osp_prompt 4 v 2193 osp_clip_loop nn st tm 2194 end