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