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 / native / omegese45 / core / ckpt.om
| 1 | note SPDX-License-Identifier: AGPL-3.0-only |
| 2 | note omegese45 core checkpoint OE45CK01 (aien-train #45, pipeline lane; interface section 6). |
| 3 | note Needs, before it: the omega-mv SHA-256 unit om/sha256/sha256-om2.om (bf54b19f, export |
| 4 | note words removed), vocab.om (ocvtsv), model.om. All integers little-endian. Layout: |
| 5 | note 0 magic "OE45CK01" 8 vocab pin = sha256(ocvtsv), 32 bytes |
| 6 | note 40 u32 x 8: format 1, V 41, head 30, tail 64, inputs 3854, hidden 256, outputs 41, MAXLEN 176 |
| 7 | note 72 u64 init seed 80 u32 init algorithm (1) 84 u32 0 |
| 8 | note 88 u64 step 96 u64 generation 104 u64 payload length 3989668 |
| 9 | note 112 payload sha256 144 training-data sha256 (the .ids file the run was bound to) |
| 10 | note 176 u32 learning-rate binary32 bits 180 u32 0 184 u64 phase-1 steps |
| 11 | note 192 u64 total steps 200 u64 epoch-order seed 208 sha256 of bytes 0 .. 207 |
| 12 | note 240 payload: the 997417 parameters as binary32 in model.om payload order. |
| 13 | note Two slots DIR/ck.a and DIR/ck.b. Save writes generation g = loaded + 1 to ck.a when g is |
| 14 | note odd, ck.b when even, then fsync: the newest valid slot is never the one being written. |
| 15 | note Load takes the structurally valid slot (size, magic, arch, payload length, header and |
| 16 | note payload digests) with the highest generation; none valid exits 51 (CKPT_REFUSED); a |
| 17 | note valid newest slot whose vocab pin differs from sha256(ocvtsv) exits 52 (CKPT_VOCAB). |
| 18 | const OPCKN ulong 3989908 |
| 19 | const OPPL ulong 3989668 |
| 20 | const OPHB ulong 240 |
| 21 | global opck uchar 3989924 |
| 22 | global opvp uchar 32 |
| 23 | global optds uchar 32 |
| 24 | global opmeta ulong 8 |
| 25 | global opckp uchar 4200 |
| 26 | global opcdl ulong 1 |
| 27 | global opslt ulong 1 |
| 28 | text opmag "OE45CK01" |
| 29 | |
| 30 | note opmeta: 0 init seed, 1 step, 2 generation, 3 phase-1 steps, 4 total steps, |
| 31 | note 5 epoch-order seed, 6 learning-rate bits, 7 init algorithm. |
| 32 | |
| 33 | fn opp32 o ulong v ulong to void |
| 34 | for i ulong 4 |
| 35 | put opck add o i uchar and shr v mul i 8 255 |
| 36 | end |
| 37 | end |
| 38 | |
| 39 | fn opp64 o ulong v ulong to void |
| 40 | for i ulong 8 |
| 41 | put opck add o i uchar and shr v mul i 8 255 |
| 42 | end |
| 43 | end |
| 44 | |
| 45 | fn opg32 o ulong to ulong |
| 46 | v = ulong 0 |
| 47 | for i ulong 4 |
| 48 | v = or v shl ulong get opck add o i mul i 8 |
| 49 | end |
| 50 | ret v |
| 51 | end |
| 52 | |
| 53 | fn opg64 o ulong to ulong |
| 54 | v = ulong 0 |
| 55 | for i ulong 8 |
| 56 | v = or v shl ulong get opck add o i mul i 8 |
| 57 | end |
| 58 | ret v |
| 59 | end |
| 60 | |
| 61 | note sha256 of opck[o, o + n) streamed through a 4096-byte local chunk (a global cannot be |
| 62 | note a call argument). |
| 63 | fn ophck o ulong n ulong d edit uchar 32 to void |
| 64 | c = new uchar 104 0 |
| 65 | b = new uchar 4096 0 |
| 66 | sha256_init c |
| 67 | p = ulong 0 |
| 68 | while lt p n bound 1100 |
| 69 | k = sub n p |
| 70 | if gt k 4096 |
| 71 | k = 4096 |
| 72 | end |
| 73 | for i ulong k |
| 74 | put b i get opck add o add p i |
| 75 | end |
| 76 | sha256_update c part b 0 k |
| 77 | p = add p k |
| 78 | end |
| 79 | sha256_final c d |
| 80 | end |
| 81 | |
| 82 | fn opvpin to void |
| 83 | d = new uchar 32 0 |
| 84 | sha256_hash ocvtsv d |
| 85 | for i ulong 32 |
| 86 | put opvp i get d i |
| 87 | end |
| 88 | end |
| 89 | |
| 90 | note Arch word i of the header (offset 40 + 4 i). |
| 91 | fn oparch i ulong to ulong |
| 92 | if eq i 0 |
| 93 | ret 1 |
| 94 | end |
| 95 | if eq i 1 |
| 96 | ret OPV |
| 97 | end |
| 98 | if eq i 2 |
| 99 | ret OPHS |
| 100 | end |
| 101 | if eq i 3 |
| 102 | ret OPTW |
| 103 | end |
| 104 | if eq i 4 |
| 105 | ret OPIN |
| 106 | end |
| 107 | if eq i 5 |
| 108 | ret OPH |
| 109 | end |
| 110 | if eq i 6 |
| 111 | ret OPV |
| 112 | end |
| 113 | ret OPMAXL |
| 114 | end |
| 115 | |
| 116 | fn opserp to void |
| 117 | for i ulong OPNP |
| 118 | opp32 add OPHB mul i 4 ulong bitcast uint opgetp i |
| 119 | end |
| 120 | end |
| 121 | |
| 122 | fn opdesp to void |
| 123 | for i ulong OPNP |
| 124 | opsetp i bitcast f32 uint opg32 add OPHB mul i 4 |
| 125 | end |
| 126 | end |
| 127 | |
| 128 | note Build the whole image in opck from the model and opmeta. |
| 129 | fn opimg to void |
| 130 | d = new uchar 32 0 |
| 131 | for i ulong 8 |
| 132 | put opck i get opmag i |
| 133 | end |
| 134 | for i ulong 32 |
| 135 | put opck add 8 i get opvp i |
| 136 | end |
| 137 | for i ulong 8 |
| 138 | opp32 add 40 mul i 4 oparch i |
| 139 | end |
| 140 | opp64 72 get opmeta 0 |
| 141 | opp32 80 get opmeta 7 |
| 142 | opp32 84 0 |
| 143 | opp64 88 get opmeta 1 |
| 144 | opp64 96 get opmeta 2 |
| 145 | opp64 104 OPPL |
| 146 | opserp |
| 147 | ophck OPHB OPPL d |
| 148 | for i ulong 32 |
| 149 | put opck add 112 i get d i |
| 150 | put opck add 144 i get optds i |
| 151 | end |
| 152 | opp32 176 get opmeta 6 |
| 153 | opp32 180 0 |
| 154 | opp64 184 get opmeta 3 |
| 155 | opp64 192 get opmeta 4 |
| 156 | opp64 200 get opmeta 5 |
| 157 | ophck 0 208 d |
| 158 | for i ulong 32 |
| 159 | put opck add 208 i get d i |
| 160 | end |
| 161 | end |
| 162 | |
| 163 | note Slot path DIR/ck.a (s 0) or DIR/ck.b (s 1) into opckp; returns its length. |
| 164 | fn opslp s ulong to ulong |
| 165 | n = get opcdl 0 |
| 166 | put opckp n 47 |
| 167 | put opckp add n 1 99 |
| 168 | put opckp add n 2 107 |
| 169 | put opckp add n 3 46 |
| 170 | put opckp add n 4 add uchar 97 uchar s |
| 171 | ret add n 5 |
| 172 | end |
| 173 | |
| 174 | note Read slot s into opck; returns the byte count read (capped at OPCKN + 1), 0 if absent. |
| 175 | fn oprdsl s ulong to ulong |
| 176 | n = opslp s |
| 177 | fd = int fopen opckp 0 n 0 0 |
| 178 | if lt fd 0 |
| 179 | ret 0 |
| 180 | end |
| 181 | p = ulong 0 |
| 182 | dn = false |
| 183 | while not dn bound 2000 |
| 184 | r = read fd opck p sub add OPCKN 1 p |
| 185 | if le r 0 |
| 186 | dn = true |
| 187 | else |
| 188 | p = add p ulong r |
| 189 | if gt p OPCKN |
| 190 | dn = true |
| 191 | end |
| 192 | end |
| 193 | end |
| 194 | c = fclose fd |
| 195 | ret p |
| 196 | end |
| 197 | |
| 198 | fn opeqd o ulong d edit uchar 32 to bool |
| 199 | for i ulong 32 |
| 200 | if ne get opck add o i get d i |
| 201 | ret false |
| 202 | end |
| 203 | end |
| 204 | ret true |
| 205 | end |
| 206 | |
| 207 | note Structural check of opck (everything except the vocab pin). |
| 208 | fn opvalid n ulong to bool |
| 209 | d = new uchar 32 0 |
| 210 | if ne n OPCKN |
| 211 | ret false |
| 212 | end |
| 213 | for i ulong 8 |
| 214 | if ne get opck i get opmag i |
| 215 | ret false |
| 216 | end |
| 217 | end |
| 218 | for i ulong 8 |
| 219 | if ne opg32 add 40 mul i 4 oparch i |
| 220 | ret false |
| 221 | end |
| 222 | end |
| 223 | if ne opg64 104 OPPL |
| 224 | ret false |
| 225 | end |
| 226 | ophck 0 208 d |
| 227 | if not opeqd 208 d |
| 228 | ret false |
| 229 | end |
| 230 | ophck OPHB OPPL d |
| 231 | ret opeqd 112 d |
| 232 | end |
| 233 | |
| 234 | note Generation of slot s when valid, else 0 (generations start at 1). |
| 235 | fn opslgen s ulong to ulong |
| 236 | n = oprdsl s |
| 237 | if not opvalid n |
| 238 | ret 0 |
| 239 | end |
| 240 | g = opg64 96 |
| 241 | if eq g 0 |
| 242 | ret 0 |
| 243 | end |
| 244 | ret g |
| 245 | end |
| 246 | |
| 247 | note The checkpoint directory is argv[i]. |
| 248 | fn opckdir i ulong to void |
| 249 | r = argread i opckp 0 4096 |
| 250 | if or le r 0 gt r 4090 |
| 251 | exit 2 |
| 252 | end |
| 253 | put opcdl 0 ulong r |
| 254 | end |
| 255 | |
| 256 | note Load the newest valid slot into the model and opmeta (exits 51 / 52). |
| 257 | fn opload to void |
| 258 | opvpin |
| 259 | ga = opslgen 0 |
| 260 | gb = opslgen 1 |
| 261 | if and eq ga 0 eq gb 0 |
| 262 | exit 51 |
| 263 | end |
| 264 | s = ulong 0 |
| 265 | if gt gb ga |
| 266 | s = 1 |
| 267 | end |
| 268 | put opslt 0 s |
| 269 | if eq s 0 |
| 270 | n = oprdsl 0 |
| 271 | end |
| 272 | for i ulong 32 |
| 273 | if ne get opck add 8 i get opvp i |
| 274 | exit 52 |
| 275 | end |
| 276 | end |
| 277 | put opmeta 0 opg64 72 |
| 278 | put opmeta 7 opg32 80 |
| 279 | put opmeta 1 opg64 88 |
| 280 | put opmeta 2 opg64 96 |
| 281 | for i ulong 32 |
| 282 | put optds i get opck add 144 i |
| 283 | end |
| 284 | put opmeta 6 opg32 176 |
| 285 | put opmeta 3 opg64 184 |
| 286 | put opmeta 4 opg64 192 |
| 287 | put opmeta 5 opg64 200 |
| 288 | opdesp |
| 289 | end |
| 290 | |
| 291 | note Save the model as generation opmeta[2] + 1 with step opmeta[1] and the vocab pin in |
| 292 | note opvp (set by opload or by the caller before a fresh save); exits 70 on I/O error. |
| 293 | fn opsave to void |
| 294 | g = add get opmeta 2 1 |
| 295 | put opmeta 2 g |
| 296 | opimg |
| 297 | s = sub 1 and g 1 |
| 298 | n = opslp s |
| 299 | fd = int fopen opckp 0 n 577 420 |
| 300 | if lt fd 0 |
| 301 | exit 70 |
| 302 | end |
| 303 | p = ulong 0 |
| 304 | while lt p OPCKN bound 2000 |
| 305 | w = write fd opck p sub OPCKN p |
| 306 | if le w 0 |
| 307 | exit 70 |
| 308 | end |
| 309 | p = add p ulong w |
| 310 | end |
| 311 | if ne fsync fd 0 |
| 312 | exit 70 |
| 313 | end |
| 314 | if ne fclose fd 0 |
| 315 | exit 70 |
| 316 | end |
| 317 | put opslt 0 s |
| 318 | end |