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
aien-train / tests / adtrain / replay / ckforge.om
| 1 | note SPDX-License-Identifier: AGPL-3.0-only |
| 2 | note ckforge: forge one adtrain.ck variant with a VALID FNV-1a 64 checksum, so |
| 3 | note each structural check of native/adtrain/mlp.om ckcheck is reached on its own |
| 4 | note (a plain byte flip only ever reaches the checksum check). |
| 5 | note stdin: one ASCII mode byte, then the 536-byte image. stdout: 536 bytes. |
| 6 | note Image (docs/adtrain/CONTRACT.md): u64 LE words 0 magic, 1 version, 2 step, |
| 7 | note 3 count, 4 lr bits, 5 loss bits, 6 data hash, 7 zero, 8..65 params, 66 FNV. |
| 8 | note Modes, each changing one field and then re-checksumming bytes 0..527: |
| 9 | note 0 nothing (positive control: must reproduce the input byte for byte) |
| 10 | note m magic byte 0 xor 1 v version 2 s step 201 S step 200 |
| 11 | note c count 57 l lr bits + 1 p word 7 = 1 |
| 12 | note u param 0 bit 32 set n param 0 = NaN i param 0 = +Inf |
| 13 | note h data hash xor 1 |
| 14 | note x checksum byte 528 xor 1, NOT re-checksummed (checksum-only image) |
| 15 | note Exits: 0 done, 74 I/O, 75 bad input or mode. |
| 16 | note Independent of mlp.om: its own FNV-1a 64 (offset 14695981039346656037, |
| 17 | note prime 1099511628211) and its own word codec. |
| 18 | global CB uchar 1024 |
| 19 | global CN ulong 1 |
| 20 | |
| 21 | fn slurp to void |
| 22 | p = ulong 0 |
| 23 | reading = true |
| 24 | while reading bound 1025 |
| 25 | if eq p 1024 |
| 26 | exit 75 |
| 27 | end |
| 28 | n = read 0 CB p sub 1024 p |
| 29 | if eq n 0 |
| 30 | reading = false |
| 31 | else |
| 32 | if lt n 0 |
| 33 | exit 74 |
| 34 | end |
| 35 | p = add p ulong n |
| 36 | end |
| 37 | end |
| 38 | put CN 0 p |
| 39 | end |
| 40 | |
| 41 | note word w of the image (the image starts at CB 1, after the mode byte) |
| 42 | fn wget w ulong to ulong |
| 43 | v = ulong 0 |
| 44 | b = add 1 mul w 8 |
| 45 | for i ulong 8 |
| 46 | v = or v shl ulong get CB add b i mul i 8 |
| 47 | end |
| 48 | ret v |
| 49 | end |
| 50 | |
| 51 | fn wput w ulong v ulong to void |
| 52 | b = add 1 mul w 8 |
| 53 | for i ulong 8 |
| 54 | put CB add b i uchar and shr v mul i 8 255 |
| 55 | end |
| 56 | end |
| 57 | |
| 58 | fn fnv to ulong |
| 59 | h = ulong 14695981039346656037 |
| 60 | for i ulong 528 |
| 61 | h = mul xor h ulong get CB add 1 i 1099511628211 |
| 62 | end |
| 63 | ret h |
| 64 | end |
| 65 | |
| 66 | note apply mode m; returns false for an unknown mode |
| 67 | fn apply m uchar to bool |
| 68 | if eq m 48 |
| 69 | ret true |
| 70 | end |
| 71 | if eq m 109 |
| 72 | put CB 1 xor get CB 1 1 |
| 73 | ret true |
| 74 | end |
| 75 | if eq m 118 |
| 76 | wput 1 2 |
| 77 | ret true |
| 78 | end |
| 79 | if eq m 115 |
| 80 | wput 2 201 |
| 81 | ret true |
| 82 | end |
| 83 | if eq m 83 |
| 84 | wput 2 200 |
| 85 | ret true |
| 86 | end |
| 87 | if eq m 99 |
| 88 | wput 3 57 |
| 89 | ret true |
| 90 | end |
| 91 | if eq m 108 |
| 92 | wput 4 add wget 4 1 |
| 93 | ret true |
| 94 | end |
| 95 | if eq m 112 |
| 96 | wput 7 1 |
| 97 | ret true |
| 98 | end |
| 99 | if eq m 117 |
| 100 | wput 8 or wget 8 4294967296 |
| 101 | ret true |
| 102 | end |
| 103 | if eq m 110 |
| 104 | wput 8 2143289344 |
| 105 | ret true |
| 106 | end |
| 107 | if eq m 105 |
| 108 | wput 8 2139095040 |
| 109 | ret true |
| 110 | end |
| 111 | if eq m 104 |
| 112 | wput 6 xor wget 6 1 |
| 113 | ret true |
| 114 | end |
| 115 | ret false |
| 116 | end |
| 117 | |
| 118 | fn main to int |
| 119 | slurp |
| 120 | if ne get CN 0 537 |
| 121 | ret 75 |
| 122 | end |
| 123 | m = get CB 0 |
| 124 | if eq m 120 |
| 125 | put CB 529 xor get CB 529 1 |
| 126 | else |
| 127 | if not apply m |
| 128 | ret 75 |
| 129 | end |
| 130 | wput 66 fnv |
| 131 | end |
| 132 | o = ulong 0 |
| 133 | while lt o 536 bound 537 |
| 134 | w = write 1 CB add 1 o sub 536 o |
| 135 | if le w 0 |
| 136 | ret 74 |
| 137 | end |
| 138 | o = add o ulong w |
| 139 | end |
| 140 | ret 0 |
| 141 | end |