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/evidence/ECOSYSTEM6/attempt-1/unit.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 / evidence / ECOSYSTEM6 / attempt-1 / unit.om` 770 lines ยท 12749 bytes Raw Blame History 1 note SPDX-License-Identifier: AGPL-3.0-only 2 note Native IEEE binary32 addition over bit patterns, RNE and gradual underflow. 3 note Canonical positive quiet NaN; no foreign floating runtime or compiler f32 type. 4 fn ajam x ulong n ulong to ulong 5 if eq n 0 6 ret x 7 end 8 if ge n 64 9 if ne x 0 10 ret 1 11 end 12 ret 0 13 end 14 q = shr x n 15 mask = sub shl 1 n 1 16 if ne and x mask 0 17 q = or q 1 18 end 19 ret q 20 end 21 fn add32 aa ulong bb ulong to ulong 22 a = and aa `4294967295` 23 b = and bb `4294967295` 24 if or gt and a `2147483647` `2139095040` gt and b `2147483647` `2139095040` 25 ret `2143289344` 26 end 27 if lt and a `2147483647` and b `2147483647` 28 t = a 29 a = b 30 b = t 31 end 32 if eq and a `2147483647` `2139095040` 33 if and eq and b `2147483647` `2139095040` ne and xor a b `2147483648` 0 34 ret `2143289344` 35 end 36 ret a 37 end 38 if eq and b `2147483647` 0 39 if eq and a `2147483647` 0 40 ret and and a b `2147483648` 41 end 42 ret a 43 end 44 sign = and a `2147483648` 45 ea = and shr a 23 255 46 eb = and shr b 23 255 47 ma = and a `8388607` 48 mb = and b `8388607` 49 if eq ea 0 50 ea = 1 51 else 52 ma = or ma `8388608` 53 end 54 if eq eb 0 55 eb = 1 56 else 57 mb = or mb `8388608` 58 end 59 ma = shl ma 3 60 mb = shl mb 3 61 mb = ajam mb sub ea eb 62 if eq and xor a b `2147483648` 0 63 ma = add ma mb 64 if ge ma `134217728` 65 ma = ajam ma 1 66 ea = add ea 1 67 end 68 else 69 ma = sub ma mb 70 if eq ma 0 71 ret 0 72 end 73 while and lt ma `67108864` gt ea 1 74 ma = shl ma 1 75 ea = sub ea 1 76 end 77 end 78 q = shr ma 3 79 r = and ma 7 80 if gt r 4 81 q = add q 1 82 else 83 if eq r 4 84 if ne and q 1 0 85 q = add q 1 86 end 87 end 88 end 89 if ge q `16777216` 90 q = shr q 1 91 ea = add ea 1 92 end 93 if ge ea 255 94 ret or sign `2139095040` 95 end 96 if lt q `8388608` 97 ea = 0 98 end 99 q = and q `8388607` 100 ea = shl ea 23 101 q = or q ea 102 ret or sign q 103 end 104 note SPDX-License-Identifier: AGPL-3.0-only 105 note Native IEEE binary32 multiplication represented as bits; no host floating runtime. 106 note Round-to-nearest ties-to-even, gradual underflow, signed zeros and infinities. 107 note Canonical positive quiet NaN for every NaN result. Inputs are low32 bits. 108 fn mround x ulong shift ulong to ulong 109 if eq shift 0 110 ret x 111 end 112 if gt shift 63 113 ret 0 114 end 115 q = shr x shift 116 mask = sub shl 1 shift 1 117 r = and x mask 118 half = shl 1 sub shift 1 119 if or gt r half and eq r half ne and q 1 0 120 q = add q 1 121 end 122 ret q 123 end 124 fn mul32 aa ulong bb ulong to ulong 125 a = and aa `4294967295` 126 b = and bb `4294967295` 127 sign = and xor a b `2147483648` 128 ea = long and shr a 23 255 129 eb = long and shr b 23 255 130 ma = and a `8388607` 131 mb = and b `8388607` 132 if or and eq ea 255 ne ma 0 and eq eb 255 ne mb 0 133 ret `2143289344` 134 end 135 if or eq ea 255 eq eb 255 136 if or eq and a `2147483647` 0 eq and b `2147483647` 0 137 ret `2143289344` 138 end 139 ret or sign `2139095040` 140 end 141 if or eq and a `2147483647` 0 eq and b `2147483647` 0 142 ret sign 143 end 144 if eq ea 0 145 ea = 1 146 while lt ma `8388608` 147 ma = shl ma 1 148 ea = sub ea 1 149 end 150 else 151 ma = or ma `8388608` 152 end 153 if eq eb 0 154 eb = 1 155 while lt mb `8388608` 156 mb = shl mb 1 157 eb = sub eb 1 158 end 159 else 160 mb = or mb `8388608` 161 end 162 product = mul ma mb 163 e = sub add ea eb 127 164 shift = long 23 165 if ge product `140737488355328` 166 shift = 24 167 e = add e 1 168 end 169 if lt e 1 170 shift = add shift sub 1 e 171 e = 0 172 end 173 q = mround product ulong shift 174 if eq e 0 175 if ge q `8388608` 176 e = 1 177 end 178 else 179 if ge q `16777216` 180 q = shr q 1 181 e = add e 1 182 end 183 end 184 if ge e 255 185 ret or sign `2139095040` 186 end 187 q = and q `8388607` 188 e = shl e 23 189 q = or q ulong e 190 ret or sign q 191 end 192 note M20 metadata-v1. Integer metadata only; no allocator or numeric execution. 193 note ED: schema,dtype,rank,elements,offset,slot,generation,reserved,shape8,stride8. 194 note ES: live,retired,slot,generation,dtype,elements,reserved,reserved. 195 note ES is the caller-owned allocator snapshot. It is not untrusted wire input. 196 global ED ulong 24 197 global ES ulong 8 198 199 fn emshape to int 200 rank = get ED 2 201 if gt rank 8 202 ret -2 203 end 204 n = ulong 1 205 for d ulong rank 206 size = get ED add 8 d 207 if eq size 0 208 ret -3 209 end 210 if gt size div `1073741824` n 211 ret -8 212 end 213 n = mul n size 214 end 215 if ne get ED 3 n 216 ret -3 217 end 218 ret 0 219 end 220 221 fn emlive slot ulong gen ulong to int 222 if gt slot `4294967295` 223 ret -5 224 end 225 if or ne get ES 0 1 ne get ES 1 0 226 ret -5 227 end 228 if or eq gen 0 ne slot get ES 2 229 ret -5 230 end 231 if ne gen get ES 3 232 ret -5 233 end 234 ret 0 235 end 236 237 fn embounds to int 238 size = get ES 5 239 offset = get ED 4 240 if or eq size 0 gt size `1073741824` 241 ret -8 242 end 243 if ge offset size 244 ret -6 245 end 246 note Compare against remaining extent before multiplication, never overflow. 247 room = sub sub size 1 offset 248 for d ulong get ED 2 249 count = sub get ED add 8 d 1 250 stride = get ED add 16 d 251 if ne stride 0 252 if gt count div room stride 253 ret -6 254 end 255 room = sub room mul count stride 256 end 257 end 258 ret 0 259 end 260 261 fn emcheck to int 262 if or ne get ED 0 1 ne get ED 7 0 263 ret -1 264 end 265 if or ne get ES 6 0 ne get ES 7 0 266 ret -1 267 end 268 dtype = get ED 1 269 if or lt dtype 1 gt dtype 3 270 ret -4 271 end 272 status = emshape 273 if ne status 0 274 ret status 275 end 276 status = emlive get ED 5 get ED 6 277 if ne status 0 278 ret status 279 end 280 if ne dtype get ES 4 281 ret -4 282 end 283 ret embounds 284 end 285 286 fn emrelease slot ulong gen ulong to int 287 status = emlive slot gen 288 if ne status 0 289 ret status 290 end 291 note A maximal generation is retired, never wrapped into a valid old handle. 292 if eq gen `18446744073709551615` 293 put ES 1 1 294 else 295 put ES 3 add gen 1 296 end 297 put ES 0 0 298 ret 0 299 end 300 note SPDX-License-Identifier: AGPL-3.0-only 301 note Bounded host FP32 consumer. Uses external pinned L720 add32/mul32 and M20 emcheck. 302 note Eight independent tensors X,W,b,T,Y,dX,dW,db in 16-cell slots. 303 note Values are IEEE binary32 bits in ulong carriers, not integer fixed-point values. 304 note AD/AS are trusted local descriptor and allocator snapshots, not wire records. 305 global AD ulong 192 306 global AS ulong 64 307 global AP ulong 128 308 global AQ ulong 128 309 global AL ulong 1 310 311 fn afcount t ulong to ulong 312 if or eq t 2 eq t 7 313 ret 2 314 end 315 if or eq t 3 eq t 4 316 ret 4 317 end 318 ret 6 319 end 320 321 fn afget t ulong i ulong to ulong 322 ret get AP add mul t 16 i 323 end 324 325 fn afq t ulong i ulong to ulong 326 ret get AQ add mul t 16 i 327 end 328 329 fn afput t ulong i ulong v ulong to void 330 put AQ add mul t 16 i v 331 end 332 333 fn affinite x ulong to bool 334 if gt x `4294967295` 335 ret false 336 end 337 ret lt and x `2147483647` `2139095040` 338 end 339 340 fn afvalidate to int 341 for t ulong 8 342 for i ulong 24 343 put ED i get AD add mul t 24 i 344 end 345 for i ulong 8 346 put ES i get AS add mul t 8 i 347 end 348 status = emcheck 349 if ne status 0 350 ret status 351 end 352 note Contiguous owned local carriers only. This does not claim strided numeric kernels. 353 if or ne get ED 1 1 ne get ED 4 0 354 ret -20 355 end 356 if or ne get ED 5 add t 1 ne get ES 5 afcount t 357 ret -20 358 end 359 rank = ulong 2 360 rows = ulong 2 361 cols = ulong 3 362 if or eq t 1 eq t 6 363 rows = 3 364 cols = 2 365 end 366 if or eq t 3 eq t 4 367 cols = 2 368 end 369 if or eq t 2 eq t 7 370 rank = 1 371 cols = 1 372 end 373 if or ne get ED 2 rank ne get ED 8 rows 374 ret -21 375 end 376 if ne get ED 16 cols 377 ret -21 378 end 379 if eq rank 2 380 if or ne get ED 9 cols ne get ED 17 1 381 ret -21 382 end 383 end 384 end 385 ret 0 386 end 387 388 fn afstep lr ulong to int 389 status = afvalidate 390 if ne status 0 391 ret status 392 end 393 if not affinite lr 394 ret -22 395 end 396 if ne and lr `2147483648` 0 397 ret -22 398 end 399 for t ulong 4 400 for i ulong afcount t 401 if not affinite afget t i 402 ret -22 403 end 404 end 405 end 406 for i ulong 128 407 put AQ i 0 408 end 409 loss = ulong 0 410 for row ulong 2 411 for col ulong 2 412 v = afget 2 col 413 for k ulong 3 414 x = afget 0 add mul row 3 k 415 w = afget 1 add mul k 2 col 416 v = add32 v mul32 x w 417 end 418 pos = add mul row 2 col 419 afput 4 pos v 420 r = add32 v xor afget 3 pos `2147483648` 421 loss = add32 loss mul32 r r 422 g = mul32 `1073741824` r 423 afput 7 col add32 afq 7 col g 424 for k ulong 3 425 xp = add mul row 3 k 426 wp = add mul k 2 col 427 gx = mul32 g afget 1 wp 428 gw = mul32 g afget 0 xp 429 afput 5 xp add32 afq 5 xp gx 430 afput 6 wp add32 afq 6 wp gw 431 end 432 end 433 end 434 note Commit only after all finite-result checks; rejected steps preserve AP and AL. 435 for i ulong 6 436 delta = mul32 lr afq 6 i 437 afput 1 i add32 afget 1 i xor delta `2147483648` 438 end 439 for i ulong 2 440 delta = mul32 lr afq 7 i 441 afput 2 i add32 afget 2 i xor delta `2147483648` 442 end 443 if not affinite loss 444 ret -23 445 end 446 for t ulong 8 447 if and ne t 0 ne t 3 448 for i ulong afcount t 449 if not affinite afq t i 450 ret -23 451 end 452 end 453 end 454 end 455 for t ulong 8 456 if and ne t 0 ne t 3 457 for i ulong afcount t 458 put AP add mul t 16 i afq t i 459 end 460 end 461 end 462 put AL 0 loss 463 ret 0 464 end 465 note SPDX-License-Identifier: AGPL-3.0-only 466 note Independent exact rational oracle: X/8,W/16,b/128,T/128,learning rate1/32. 467 note Only the test oracle uses integer rationals. Production calls IEEE add32/mul32. 468 global C ulong 1 469 global D uchar 24 470 global RI long 18 471 global RR long 4 472 global SAV ulong 129 473 global RNG ulong 1 474 text PASS "NATIVE_AFFINE_FP32_PASS checks=" 475 text FAIL "NATIVE_AFFINE_FP32_FAIL check=" 476 text NL "\n" 477 478 fn number n ulong to void 479 p = ulong 24 480 while true bound 24 481 p = sub p 1 482 put D p uchar add 48 rem n 10 483 n = div n 10 484 if eq n 0 485 break 486 end 487 end 488 w = write 1 D p sub 24 p 489 if ne w long sub 24 p 490 exit 90 491 end 492 end 493 494 fn check ok bool to void 495 put C 0 add get C 0 1 496 if not ok 497 w = write 1 FAIL 0 len FAIL 498 number get C 0 499 w = write 1 NL 0 1 500 exit 1 501 end 502 end 503 504 fn bits value long scale ulong to ulong 505 note Exact binary32 encoding of small dyadic test numbers; no production primitive. 506 if eq value 0 507 ret 0 508 end 509 sign = ulong 0 510 if lt value 0 511 sign = `2147483648` 512 value = neg value 513 end 514 n = ulong value 515 power = ulong 0 516 q = n 517 while gt q 1 bound 24 518 q = shr q 1 519 power = add power 1 520 end 521 check le power 23 522 mantissa = sub shl n sub 23 power `8388608` 523 exponent = sub add power 127 scale 524 ret or sign or shl exponent 23 mantissa 525 end 526 527 fn fixture to void 528 for i ulong 192 529 put AD i 0 530 end 531 for i ulong 64 532 put AS i 0 533 end 534 for i ulong 128 535 put AP i 0 536 end 537 put AL 0 0 538 for t ulong 8 539 rank = ulong 2 540 rows = ulong 2 541 cols = ulong 3 542 count = ulong 6 543 if or eq t 1 eq t 6 544 rows = 3 545 cols = 2 546 end 547 if or eq t 3 eq t 4 548 cols = 2 549 count = 4 550 end 551 if or eq t 2 eq t 7 552 rank = 1 553 cols = 1 554 count = 2 555 end 556 p = mul t 24 557 put AD p 1 558 put AD add p 1 1 559 put AD add p 2 rank 560 put AD add p 3 count 561 put AD add p 5 add t 1 562 put AD add p 6 17 563 put AD add p 8 rows 564 put AD add p 16 cols 565 if eq rank 2 566 put AD add p 9 cols 567 put AD add p 17 1 568 end 569 p = mul t 8 570 put AS p 1 571 put AS add p 2 add t 1 572 put AS add p 3 17 573 put AS add p 4 1 574 put AS add p 5 count 575 end 576 end 577 578 fn save to void 579 for i ulong 128 580 put SAV i get AP i 581 end 582 put SAV 128 get AL 0 583 end 584 585 fn unchanged to void 586 for i ulong 128 587 check eq get SAV i get AP i 588 end 589 check eq get SAV 128 get AL 0 590 end 591 592 fn loadinputs to void 593 for i ulong 6 594 put AP i bits get RI i 3 595 put AP add 16 i bits get RI add 6 i 4 596 end 597 for i ulong 2 598 put AP add 32 i bits get RI add 12 i 7 599 end 600 for i ulong 4 601 put AP add 48 i bits get RI add 14 i 7 602 end 603 end 604 605 fn oracle to void 606 loss = long 0 607 for row ulong 2 608 for col ulong 2 609 pos = add mul row 2 col 610 y = get RI add 12 col 611 for k ulong 3 612 x = get RI add mul row 3 k 613 w = get RI add 6 add mul k 2 col 614 y = add y mul x w 615 end 616 check eq afget 4 pos bits y 7 617 r = sub y get RI add 14 pos 618 put RR pos r 619 loss = add loss mul r r 620 end 621 end 622 check eq get AL 0 bits loss 14 623 for k ulong 3 624 for col ulong 2 625 g = long 0 626 for row ulong 2 627 r = get RR add mul row 2 col 628 x = get RI add mul row 3 k 629 g = add g mul r x 630 end 631 pos = add mul k 2 col 632 check eq afget 6 pos bits g 9 633 updated = sub mul get RI add 6 pos 1024 g 634 check eq afget 1 pos bits updated 14 635 end 636 end 637 for col ulong 2 638 g = add get RR col get RR add 2 col 639 check eq afget 7 col bits g 6 640 updated = sub mul get RI add 12 col 16 g 641 check eq afget 2 col bits updated 11 642 end 643 for row ulong 2 644 for k ulong 3 645 g = long 0 646 for col ulong 2 647 r = get RR add mul row 2 col 648 w = get RI add 6 add mul k 2 col 649 g = add g mul r w 650 end 651 pos = add mul row 3 k 652 check eq afget 5 pos bits g 10 653 end 654 end 655 note Inputs and targets remain byte-identical after a successful step. 656 for i ulong 6 657 check eq afget 0 i bits get RI i 3 658 end 659 for i ulong 4 660 check eq afget 3 i bits get RI add 14 i 7 661 end 662 end 663 664 fn direct to void 665 fixture 666 check eq afvalidate 0 667 note X rows(1,-2,3),(2,0,-1); W(.5,-.25),(1,.75),(-.5,2). 668 put RI 0 8 669 put RI 1 -16 670 put RI 2 24 671 put RI 3 16 672 put RI 4 0 673 put RI 5 -8 674 put RI 6 8 675 put RI 7 -4 676 put RI 8 16 677 put RI 9 12 678 put RI 10 -8 679 put RI 11 32 680 put RI 12 16 681 put RI 13 -64 682 put RI 14 32 683 put RI 15 128 684 put RI 16 -128 685 put RI 17 64 686 loadinputs 687 check eq afstep `1023410176` 0 688 oracle 689 note Independently hand-calculated loss36.46875, not merely decreasing loss. 690 check eq get AL 0 `1108467712` 691 end 692 693 fn refusals to void 694 fixture 695 put AD 32 2 696 put AD 33 3 697 put AD 40 3 698 save 699 check eq afstep `1023410176` -21 700 unchanged 701 fixture 702 put AS 11 18 703 save 704 check eq afstep `1023410176` -5 705 unchanged 706 fixture 707 put AD 29 1 708 put AS 10 1 709 save 710 check eq afstep `1023410176` -20 711 unchanged 712 fixture 713 put AP 0 `2139095040` 714 save 715 check eq afstep `1023410176` -22 716 unchanged 717 fixture 718 put AP 0 `2143289344` 719 save 720 check eq afstep `1023410176` -22 721 unchanged 722 fixture 723 put AP 0 `4294967296` 724 save 725 check eq afstep `1023410176` -22 726 unchanged 727 fixture 728 save 729 check eq afstep `3170893824` -22 730 unchanged 731 fixture 732 put AP 0 `2139095039` 733 put AP 16 `1073741824` 734 save 735 check eq afstep `1023410176` -23 736 unchanged 737 end 738 739 fn next to long 740 n = add mul get RNG 0 `1664525` `1013904223` 741 n = and n `4294967295` 742 put RNG 0 n 743 ret sub long rem shr n 12 17 8 744 end 745 746 fn corpus to void 747 put RNG 0 303660 748 for trial ulong 4096 749 fixture 750 for i ulong 18 751 put RI i next 752 end 753 loadinputs 754 check eq afstep `1023410176` 0 755 oracle 756 end 757 end 758 759 fn main to int 760 direct 761 refusals 762 corpus 763 w = write 1 PASS 0 len PASS 764 number get C 0 765 w = write 1 NL 0 1 766 if ne w 1 767 ret 90 768 end 769 ret 0 770 end