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-sovereign-core-mv/blob/main/om/golden/ollm/gate.om # aien-sovereign-core-mv AienOS host runtime: inference scheduling, paged KV state, the aien CLI and Spark verification tooling. Its inference engine is in alpha testing (DGX Spark GB10); Omega is the implementation destination. 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-sovereign-core-mv / om / golden / ollm / gate.om` 954 lines ยท 14618 bytes Raw Blame History 1 note SPDX-License-Identifier: Apache-2.0 2 note om/golden/ollm/gate.om: golden-token record and comparator for the own Omega LLM (DRA-52, 3 note Core #853). Every judgment of the gate is made here; gate.sh and record.sh only sequence. 4 note Build (om/golden/build.sh does this): 5 note { printf 'om2\n'; cat om/vendor/json.om om/vendor/sha256.om om/golden/ollm/gate.om; } | omc 6 note Modes: 7 note gate rec CPUOUT CK MERGES PROMPTS MAXTOK FLOOR_E9 DRIFT_E9 ENGINE SOURCE HOST UTC LABEL 8 note turns a gdec.om gtcpu run (CPUOUT) into one aien-golden-ollm/1 record on stdout. The 9 note checkpoint, merges and prompt file are hashed here. Prompt k keeps its leading steps whose 10 note top-1 margin is at least FLOOR_E9 (10^-9 logit units); the first step below the floor and 11 note everything after it are dropped, and a generated id 0 is kept and ends the prompt. Each prompt 12 note must keep at least RMIN steps (exit 5 ambiguous otherwise). 13 note gate cmp REF CANDOUT CK MERGES PROMPTS 14 note compares a gdec.om gtgpu run with the record: the three files must hash to the record's 15 note identities (exit 3 NOTCOMPARABLE otherwise). For every kept step the candidate id must 16 note equal the reference id (DIVERGE) and its top-1 logit must be within DRIFT_E9 of the 17 note reference's (DRIFT). Prints MATCH, DIVERGE or DRIFT per prompt and a summary line. 18 note Exit: 0 written or every prompt matches, 1 a DIVERGE or DRIFT, 2 usage or bad argument, 19 note 3 not comparable, 4 file or format refusal, 5 ambiguous prompt (rec). Formats: README.md. 20 21 const KMAX ulong 64 22 const SMAX ulong 4096 23 const RMIN ulong 4 24 const BUFCAP ulong `4194304` 25 26 global gb uchar `4194304` 27 global gbn ulong 1 28 global gcur ulong 1 29 global gw ulong 2 30 global gpa uchar 4352 31 global gh uchar 65536 32 global gsha uchar 192 33 global go uchar 65536 34 global gon ulong 1 35 global gid ulong 262144 36 global gtop long 262144 37 global gmar long 262144 38 global gcnt ulong 64 39 global gend ulong 64 40 global grid ulong 262144 41 global grtop long 262144 42 global grn ulong 64 43 global ghd ulong 16 44 global gstr uchar 1024 45 global gstl ulong 8 46 global gsum ulong 8 47 global gmd long 2 48 49 text tmrec "rec" 50 text tmcmp "cmp" 51 text tpre "golden-ollm: refused " 52 text tuse "usage: gate rec CPUOUT CK MERGES PROMPTS MAXTOK FLOOR_E9 DRIFT_E9 ENGINE SOURCE HOST UTC LABEL | gate cmp REF CANDOUT CK MERGES PROMPTS" 53 text tio "io" 54 text tbig "too-large" 55 text tfmt "format" 56 text tamb "ambiguous-prompt" 57 text tbarg "bad-argument" 58 text tschema "aien-golden-ollm/1" 59 text tk0 "label" 60 text tk1 "ckpt_sha256" 61 text tk2 "merges_sha256" 62 text tk3 "prompts_sha256" 63 text tk4 "prompts" 64 text tk5 "max_tokens" 65 text tk6 "margin_floor_e9" 66 text tk7 "drift_bound_e9" 67 text tk8 "ref_decoder" 68 text tk9 "ref_engine_sha256" 69 text tk10 "ref_source" 70 text tk11 "host_id" 71 text tk12 "utc" 72 text tgtcpu "gtcpu" 73 text tend "end" 74 text tgte "GTE" 75 text tcpu "cpu" 76 text tgpu "gpu" 77 text treal "REAL" 78 text tfake "FAKE" 79 text tsyn "SYNTHETIC" 80 text tnc "NOTCOMPARABLE " 81 text tmatch "MATCH " 82 text tdiv "DIVERGE " 83 text tdrift "DRIFT " 84 text tsumm "golden-ollm cmp prompts=" 85 text tn " n=" 86 text tmd " maxdrift_e9=" 87 text tix " index=" 88 text tref " ref=" 89 text tcand " cand=" 90 text tcend "end" 91 text ts1 " compared=" 92 text ts2 " match=" 93 text ts3 " diverge=" 94 text ts4 " drift=" 95 96 note ---- output 97 98 fn oflsh to void 99 n = get gon 0 100 p = ulong 0 101 while lt p n bound 65537 102 w = write 1 go p sub n p 103 if le w 0 104 exit 4 105 end 106 p = add p ulong w 107 end 108 put gon 0 0 109 end 110 111 fn oc c ulong to void 112 n = get gon 0 113 if ge n 65536 114 oflsh 115 n = ulong 0 116 end 117 put go n uchar and c 255 118 put gon 0 add n 1 119 end 120 121 fn ot t view uchar * to void 122 for i ulong len t 123 oc ulong get t i 124 end 125 end 126 127 fn ou v ulong to void 128 d = new uchar 24 0 129 n = ulong 0 130 x = v 131 while true bound 21 132 put d n uchar add rem x 10 48 133 n = add n 1 134 x = div x 10 135 if eq x 0 136 break 137 end 138 end 139 for i ulong n 140 oc ulong get d sub sub n 1 i 141 end 142 end 143 144 fn ol v long to void 145 if lt v 0 146 oc 45 147 if eq v -`9223372036854775808` 148 ou `9223372036854775808` 149 else 150 ou ulong neg v 151 end 152 else 153 ou ulong v 154 end 155 end 156 157 fn osp to void 158 oc 32 159 end 160 161 fn onl to void 162 oc 10 163 end 164 165 note refusal: message on stderr, exit code 166 fn die code int why view uchar * to void 167 oflsh 168 w = write 2 tpre 0 len tpre 169 w = write 2 why 0 len why 170 m = new uchar 1 10 171 w = write 2 m 0 1 172 exit code 173 end 174 175 fn usage to void 176 oflsh 177 w = write 2 tuse 0 len tuse 178 m = new uchar 1 10 179 w = write 2 m 0 1 180 exit 2 181 end 182 183 note ---- arguments and files 184 185 note argv[i] into gpa; returns its length or exits 2 186 fn arg i ulong to ulong 187 r = argread i gpa 0 4096 188 if or le r 0 gt r 4096 189 usage 190 end 191 ret ulong r 192 end 193 194 note the whole file named by argv[i] into gb[0 .. gbn); exits 4 on I/O or when it exceeds BUFCAP 195 fn fload i ulong to void 196 n = arg i 197 fd = fopen gpa 0 n 0 0 198 if lt fd 0 199 die 4 tio 200 end 201 t = ulong 0 202 while true bound 999999 203 if ge t BUFCAP 204 die 4 tbig 205 end 206 k = read int fd gb t sub BUFCAP t 207 if lt k 0 208 die 4 tio 209 end 210 if eq k 0 211 break 212 end 213 t = add t ulong k 214 end 215 c = fclose int fd 216 put gbn 0 t 217 put gcur 0 0 218 end 219 220 note sha256 of the file named by argv[i] into gsha[slot 64 ..) 221 fn fhash i ulong slot ulong to void 222 n = arg i 223 fd = fopen gpa 0 n 0 0 224 if lt fd 0 225 die 4 tio 226 end 227 hreset 228 while true bound 999999 229 k = read int fd gh 0 65536 230 if lt k 0 231 die 4 tio 232 end 233 if eq k 0 234 break 235 end 236 for j ulong ulong k 237 b = hpush get gh j 238 end 239 end 240 c = fclose int fd 241 if not hfinal 242 die 4 tio 243 end 244 for j ulong 64 245 put gsha add mul slot 64 j get hd j 246 end 247 end 248 249 note ---- line and word scanning over gb[gcur ..) 250 251 note next word: gw = (start, length); words end at a space or a line end; returns false at a line end 252 note or the end of the buffer (no word) 253 fn word to bool 254 c = get gcur 0 255 n = get gbn 0 256 if ge c n 257 ret false 258 end 259 if eq get gb c 10 260 ret false 261 end 262 s = c 263 while lt c n bound 999999 264 x = get gb c 265 if or eq x 32 eq x 10 266 break 267 end 268 c = add c 1 269 end 270 put gw 0 s 271 put gw 1 sub c s 272 if eq get gw 1 0 273 die 4 tfmt 274 end 275 if lt c n 276 if eq get gb c 32 277 c = add c 1 278 end 279 end 280 put gcur 0 c 281 ret true 282 end 283 284 note the line must end here: consumes the newline, exits 4 otherwise 285 fn eol to void 286 c = get gcur 0 287 if ge c get gbn 0 288 die 4 tfmt 289 end 290 if ne get gb c 10 291 die 4 tfmt 292 end 293 put gcur 0 add c 1 294 end 295 296 fn wneed to void 297 if not word 298 die 4 tfmt 299 end 300 end 301 302 note the current word equals t 303 fn wis t view uchar * to bool 304 if ne get gw 1 len t 305 ret false 306 end 307 s = get gw 0 308 for i ulong len t 309 if ne get gb add s i get t i 310 ret false 311 end 312 end 313 ret true 314 end 315 316 fn wexp t view uchar * to void 317 wneed 318 if not wis t 319 die 4 tfmt 320 end 321 end 322 323 note the current word as an unsigned decimal of 1 .. 19 digits 324 fn wu to ulong 325 n = get gw 1 326 if gt n 19 327 die 4 tfmt 328 end 329 s = get gw 0 330 v = ulong 0 331 for i ulong n 332 x = get gb add s i 333 if or lt x 48 gt x 57 334 die 4 tfmt 335 end 336 v = add mul v 10 ulong sub x 48 337 end 338 ret v 339 end 340 341 fn wl to long 342 s = get gw 0 343 if eq get gb s 45 344 put gw 0 add s 1 345 put gw 1 sub get gw 1 1 346 if eq get gw 1 0 347 die 4 tfmt 348 end 349 v = wu 350 if gt v `9223372036854775807` 351 die 4 tfmt 352 end 353 ret neg long v 354 end 355 v = wu 356 if gt v `9223372036854775807` 357 die 4 tfmt 358 end 359 ret long v 360 end 361 362 fn nu to ulong 363 wneed 364 ret wu 365 end 366 367 fn nl to long 368 wneed 369 ret wl 370 end 371 372 note the current word is 64 lowercase hex and equals gsha[slot 64 ..) when chk; copies it there 373 note otherwise 374 fn whex slot ulong chk bool to bool 375 if ne get gw 1 64 376 die 4 tfmt 377 end 378 s = get gw 0 379 ok = true 380 for i ulong 64 381 x = get gb add s i 382 if not or and ge x 48 le x 57 and ge x 97 le x 102 383 die 4 tfmt 384 end 385 o = add mul slot 64 i 386 if chk 387 if ne get gsha o x 388 ok = false 389 end 390 else 391 put gsha o x 392 end 393 end 394 ret ok 395 end 396 397 note the argument i as a decimal: 1 .. 19 digits 398 fn argu i ulong to ulong 399 n = arg i 400 if gt n 19 401 die 2 tbarg 402 end 403 v = ulong 0 404 for j ulong n 405 x = get gpa j 406 if or lt x 48 gt x 57 407 die 2 tbarg 408 end 409 v = add mul v 10 ulong sub x 48 410 end 411 ret v 412 end 413 414 fn idch x uchar to bool 415 if and ge x 48 le x 57 416 ret true 417 end 418 if and ge x 65 le x 90 419 ret true 420 end 421 if and ge x 97 le x 122 422 ret true 423 end 424 if or or eq x 46 eq x 95 or eq x 47 eq x 64 425 ret true 426 end 427 ret or or eq x 58 eq x 43 eq x 45 428 end 429 430 note the argument i must be 1 .. 128 of [A-Za-z0-9._/@:+-]; copied into gstr[slot 128 ..), length 431 note gstl[slot] 432 fn argid i ulong slot ulong to void 433 n = arg i 434 if gt n 128 435 die 2 tbarg 436 end 437 for j ulong n 438 x = get gpa j 439 if not idch x 440 die 2 tbarg 441 end 442 put gstr add mul slot 128 j x 443 end 444 put gstl slot n 445 end 446 447 fn ostr slot ulong to void 448 for j ulong get gstl slot 449 oc ulong get gstr add mul slot 128 j 450 end 451 end 452 453 fn osha slot ulong to void 454 for j ulong 64 455 oc ulong get gsha add mul slot 64 j 456 end 457 end 458 459 note ---- gdec.om output: T k s id top1 margin lines, then GTE cpu|gpu K steps ns 460 461 note parse gb as a gdec run of the decoder named t; fills gid/gtop/gmar, gcnt, gend; returns K 462 fn dparse t view uchar * to ulong 463 for k ulong KMAX 464 put gcnt k 0 465 put gend k 0 466 end 467 steps = ulong 0 468 while true bound 262146 469 wneed 470 if wis tgte 471 break 472 end 473 if or ne get gw 1 1 ne get gb get gw 0 84 474 die 4 tfmt 475 end 476 dline 477 steps = add steps 1 478 end 479 wexp t 480 kk = nu 481 st = nu 482 ns = nu 483 eol 484 if lt get gcur 0 get gbn 0 485 die 4 tfmt 486 end 487 if or or eq kk 0 gt kk KMAX ne st steps 488 die 4 tfmt 489 end 490 for k ulong KMAX 491 if and ge k kk ne get gcnt k 0 492 die 4 tfmt 493 end 494 end 495 ret kk 496 end 497 498 note one T line after its T word: steps of prompt k must arrive in order 0, 1, ..; nothing after an 499 note id 0 500 fn dline to void 501 k = nu 502 s = nu 503 if or ge k KMAX ge s SMAX 504 die 4 tfmt 505 end 506 if or ne s get gcnt k ne get gend k 0 507 die 4 tfmt 508 end 509 o = add mul k SMAX s 510 c = nu 511 put gid o c 512 put gtop o nl 513 put gmar o nl 514 eol 515 put gcnt k add s 1 516 if eq c 0 517 put gend k 1 518 end 519 end 520 521 note ---- rec 522 523 fn reckey t view uchar * to void 524 ot t 525 osp 526 end 527 528 fn reclab to void 529 n = arg 13 530 for j ulong n 531 oc ulong get gpa j 532 end 533 end 534 535 note kept steps of prompt k under floor f: leading steps with margin >= f; an id 0 ends it 536 fn keep k ulong f long to ulong 537 n = ulong 0 538 for s ulong get gcnt k 539 o = add mul k SMAX s 540 if lt get gmar o f 541 break 542 end 543 n = add n 1 544 if eq get gid o 0 545 break 546 end 547 end 548 ret n 549 end 550 551 fn recrow tag ulong k ulong n ulong which ulong to void 552 oc tag 553 osp 554 ou k 555 osp 556 ou n 557 for s ulong n 558 o = add mul k SMAX s 559 osp 560 if eq which 0 561 ou get gid o 562 end 563 if eq which 1 564 ol get gtop o 565 end 566 if eq which 2 567 ol get gmar o 568 end 569 end 570 onl 571 end 572 573 fn rec to void 574 if ne ulong argcnt 14 575 usage 576 end 577 mx = argu 6 578 fl = argu 7 579 dr = argu 8 580 if or or eq mx 0 gt mx SMAX or eq fl 0 eq dr 0 581 die 2 tbarg 582 end 583 if or gt fl `1000000000000` gt dr `1000000000000` 584 die 2 tbarg 585 end 586 argid 9 0 587 argid 10 1 588 argid 11 2 589 argid 12 3 590 ok = or or argis 13 treal argis 13 tfake argis 13 tsyn 591 if not ok 592 die 2 tbarg 593 end 594 fload 2 595 kk = dparse tcpu 596 for k ulong kk 597 if lt get gcnt k mx 598 if eq get gend k 0 599 die 4 tfmt 600 end 601 end 602 if gt get gcnt k mx 603 die 4 tfmt 604 end 605 end 606 fhash 3 0 607 fhash 4 1 608 fhash 5 2 609 for k ulong kk 610 if lt keep k long fl RMIN 611 die 5 tamb 612 end 613 end 614 recout kk mx fl dr 615 end 616 617 fn recout kk ulong mx ulong fl ulong dr ulong to void 618 ot tschema 619 onl 620 reckey tk0 621 reclab 622 onl 623 reckey tk1 624 osha 0 625 onl 626 reckey tk2 627 osha 1 628 onl 629 reckey tk3 630 osha 2 631 onl 632 reckey tk4 633 ou kk 634 onl 635 reckey tk5 636 ou mx 637 onl 638 reckey tk6 639 ou fl 640 onl 641 reckey tk7 642 ou dr 643 onl 644 reckey tk8 645 ot tgtcpu 646 onl 647 recid tk9 0 648 recid tk10 1 649 recid tk11 2 650 recid tk12 3 651 for k ulong kk 652 n = keep k long fl 653 recrow 80 k n 0 654 recrow 76 k n 1 655 recrow 77 k n 2 656 end 657 ot tend 658 onl 659 oflsh 660 end 661 662 fn recid t view uchar * slot ulong to void 663 reckey t 664 ostr slot 665 onl 666 end 667 668 note ---- cmp 669 670 note one header line KEY VALUE; hex slots are compared with the hashed files 671 fn hkey t view uchar * to void 672 wexp t 673 wneed 674 end 675 676 fn hsha t view uchar * slot ulong to bool 677 hkey t 678 ok = whex slot true 679 eol 680 ret ok 681 end 682 683 note record line TAG k n v0 .. v(n-1); which 0 ids into grid, 1 top1 into grtop, 2 margins (each 684 note must meet the record's floor). As rec writes it: RMIN <= n <= max_tokens (<= SMAX). 685 fn rrow tag ulong k ulong which ulong to void 686 wneed 687 if or ne get gw 1 1 ne ulong get gb get gw 0 tag 688 die 4 tfmt 689 end 690 if ne nu k 691 die 4 tfmt 692 end 693 n = nu 694 if or lt n RMIN gt n get ghd 1 695 die 4 tfmt 696 end 697 if eq which 0 698 put grn k n 699 end 700 if ne n get grn k 701 die 4 tfmt 702 end 703 for s ulong n 704 o = add mul k SMAX s 705 if eq which 0 706 put grid o nu 707 end 708 if eq which 1 709 put grtop o nl 710 end 711 if eq which 2 712 if lt nl long get ghd 2 713 die 4 tfmt 714 end 715 end 716 end 717 eol 718 end 719 720 fn hshas t view uchar * slot ulong to void 721 put ghd add 4 slot 0 722 if hsha t slot 723 put ghd add 4 slot 1 724 end 725 end 726 727 note parse the record in gb against the file hashes in gsha slots 0..2: ghd[4 + slot] = 1 when the 728 note record's checkpoint, merges or prompts hash equals the file's; ghd 1 max_tokens, 2 floor, 729 note 3 drift bound; returns K 730 fn rparse to ulong 731 wexp tschema 732 eol 733 hkey tk0 734 if not or or wis treal wis tfake wis tsyn 735 die 4 tfmt 736 end 737 eol 738 hshas tk1 0 739 hshas tk2 1 740 hshas tk3 2 741 hkey tk4 742 kk = wu 743 eol 744 hkey tk5 745 put ghd 1 wu 746 eol 747 hkey tk6 748 put ghd 2 wu 749 eol 750 hkey tk7 751 put ghd 3 wu 752 eol 753 mtk = get ghd 1 754 if or or eq mtk 0 gt mtk SMAX or eq get ghd 2 0 eq get ghd 3 0 755 die 4 tfmt 756 end 757 if or gt get ghd 2 `1000000000000` gt get ghd 3 `1000000000000` 758 die 4 tfmt 759 end 760 hkey tk8 761 if not wis tgtcpu 762 die 4 tfmt 763 end 764 eol 765 rskip tk9 766 rskip tk10 767 rskip tk11 768 rskip tk12 769 if or eq kk 0 gt kk KMAX 770 die 4 tfmt 771 end 772 for k ulong kk 773 rrow 80 k 0 774 rrow 76 k 1 775 rrow 77 k 2 776 end 777 wexp tend 778 eol 779 if lt get gcur 0 get gbn 0 780 die 4 tfmt 781 end 782 ret kk 783 end 784 785 fn rskip t view uchar * to void 786 hkey t 787 eol 788 end 789 790 fn onc t view uchar * to void 791 ot tnc 792 ot t 793 onl 794 oflsh 795 exit 3 796 end 797 798 fn absd a long b long to ulong 799 if gt a b 800 ret ulong sub a b 801 end 802 ret ulong sub b a 803 end 804 805 note compare prompt k; prints its verdict; returns 0 match, 1 diverge, 2 drift 806 fn cmpk k ulong dr ulong to ulong 807 n = get grn k 808 mxd = ulong 0 809 for s ulong n 810 o = add mul k SMAX s 811 if ge s get gcnt k 812 cdiv k s get grid o false 0 813 ret 1 814 end 815 if ne get gid o get grid o 816 cdiv k s get grid o true get gid o 817 ret 1 818 end 819 d = absd get gtop o get grtop o 820 if gt d dr 821 cdrift k s get grtop o get gtop o 822 ret 2 823 end 824 if gt d mxd 825 mxd = d 826 end 827 end 828 ot tmatch 829 ou k 830 ot tn 831 ou n 832 ot tmd 833 ou mxd 834 onl 835 if gt mxd get gsum 4 836 put gsum 4 mxd 837 end 838 ret 0 839 end 840 841 842 fn cdiv k ulong s ulong r ulong has bool c ulong to void 843 ot tdiv 844 ou k 845 ot tix 846 ou s 847 ot tref 848 ou r 849 ot tcand 850 if has 851 ou c 852 else 853 ot tcend 854 end 855 onl 856 end 857 858 fn cdrift k ulong s ulong r long c long to void 859 ot tdrift 860 ou k 861 ot tix 862 ou s 863 ot tref 864 ol r 865 ot tcand 866 ol c 867 onl 868 end 869 870 871 fn cmp to void 872 if ne ulong argcnt 7 873 usage 874 end 875 fhash 4 0 876 fhash 5 1 877 fhash 6 2 878 fload 2 879 kk = rparse 880 dr = get ghd 3 881 if eq get ghd 4 0 882 onc tk1 883 end 884 if eq get ghd 5 0 885 onc tk2 886 end 887 if eq get ghd 6 0 888 onc tk3 889 end 890 fload 3 891 ck = dparse tgpu 892 if ne ck kk 893 onc tk4 894 end 895 for i ulong 8 896 put gsum i 0 897 end 898 for k ulong kk 899 v = cmpk k dr 900 put gsum v add get gsum v 1 901 put gsum 3 add get gsum 3 get grn k 902 end 903 csum kk 904 end 905 906 fn csum kk ulong to void 907 ot tsumm 908 ou kk 909 ot ts1 910 ou get gsum 3 911 ot ts2 912 ou get gsum 0 913 ot ts3 914 ou get gsum 1 915 ot ts4 916 ou get gsum 2 917 ot tmd 918 ou get gsum 4 919 onl 920 oflsh 921 if ne get gsum 0 kk 922 exit 1 923 end 924 exit 0 925 end 926 927 fn argis i ulong t view uchar * to bool 928 r = argread i gpa 0 4096 929 if ne r long len t 930 ret false 931 end 932 for j ulong len t 933 if ne get gpa j get t j 934 ret false 935 end 936 end 937 ret true 938 end 939 940 fn main to int 941 if lt ulong argcnt 2 942 usage 943 end 944 if argis 1 tmrec 945 rec 946 ret 0 947 end 948 if argis 1 tmcmp 949 cmp 950 ret 0 951 end 952 usage 953 ret 2 954 end