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 / si19 / selmain.om
| 1 | note SPDX-License-Identifier: AGPL-3.0-only |
| 2 | note aien-train#25 ORIG-2 driver. First stdin byte selects the mode. |
| 3 | note T train: config (64 bytes = 8 LE words: kind, seed, lr code 0|8|10|12, max epochs, |
| 4 | note patience, control, stop-at epoch, eval partition flags bit0 TRAIN bit1 DEV bit2 TEST, |
| 5 | note bit3 = v2 admission: ORIG1-CONTRACT-v2.md, oxadm2, workload-family splits 0 TRAIN, |
| 6 | note 1 VALIDATION, 2 HELD-OUT; the image records it in SS[20]), then the allow-list block |
| 7 | note (4096 bytes, zero padded), then omexp-v1 records to EOF. |
| 8 | note Admission: config -> allow-list status -> oxload|oxadm2 -> train -> image on fd 3 -> |
| 9 | note key=value report on stdout (-> evaluation of the flagged partitions with SB). |
| 10 | note R resume: config, allow-list, one image (length fixed by the config kind), records. |
| 11 | note E evaluate: like R without training and without an image; sleval per flagged partition |
| 12 | note per core class (0, 1, 2, 3 = all) on stdout, per-record lines on fd 4: |
| 13 | note seq fam core M N model rule ref static near oracle cost_model cost_oracle |
| 14 | note cost_rule cost_ref cost_static cost_near; v2 appends press calls split cell. |
| 15 | note R and E refuse (68) an image whose SS[20] differs from the config's v2 bit. |
| 16 | note C compare two images of one kind byte for byte: exit 0 identical, 1 different. |
| 17 | note G fixture: 16 bytes (seed, count), SYNTHETIC records to fd 3, identity on stdout. |
| 18 | note Exit: 64 bad mode, 65 image refused, 66 dataset refused, 67 unauthorized, 68 config |
| 19 | note invalid, 74 I/O, 86 non-finite update (from slstep). |
| 20 | global SM uchar 1 |
| 21 | global SK uchar 64 |
| 22 | global SD uchar 24 |
| 23 | text MREF "SELECT checkpoint refused status=-" |
| 24 | text MDAT "SELECT dataset refused status=-" |
| 25 | text MUNA "SELECT dataset unauthorized status=-" |
| 26 | text MIDN "SELECT_IDENTICAL bytes=" |
| 27 | text MDIF "SELECT_DIFFERENT first_byte=" |
| 28 | text MKIN "kind=" |
| 29 | text MNPA "nparams=" |
| 30 | text MSEE "seed=" |
| 31 | text MIFN "init_fnv=" |
| 32 | text MLR "lr=" |
| 33 | text MLRB "lr_bits=" |
| 34 | text MCTL "control=" |
| 35 | text MEPO "epochs=" |
| 36 | text MUPD "updates=" |
| 37 | text MCUR "cursor=" |
| 38 | text MMU "mu16=" |
| 39 | text MSH "sh=" |
| 40 | text MNTR "ntrain=" |
| 41 | text MTLS "train_loss_sum=" |
| 42 | text MTLD "train_loss_dec=" |
| 43 | text MDLS "dev_loss_sum=" |
| 44 | text MDLD "dev_loss_dec=" |
| 45 | text MBEP "best_epoch=" |
| 46 | text MSTL "stale_epochs=" |
| 47 | text MFFN "final_params_fnv=" |
| 48 | text MBFN "best_params_fnv=" |
| 49 | text MDFN "data_fnv=" |
| 50 | text MREC "records=" |
| 51 | text MIMB "image_bytes=" |
| 52 | text MIMF "image_fnv=" |
| 53 | text MALW "allow=" |
| 54 | text MSTA "status=ok" |
| 55 | text MBND "data_bound=yes" |
| 56 | text MUNB "data_bound=no" |
| 57 | text MEVL "eval part=" |
| 58 | text MCOR " core=" |
| 59 | text MCOL "eval_columns=n model oracle rule ref static near affine top1 win_rule loss_rule win_near loss_near win_static loss_static win_ref loss_ref" |
| 60 | text MGB "bytes=" |
| 61 | text MGL "load_status=" |
| 62 | text MFNV "fnv=" |
| 63 | text MBIG "big" |
| 64 | text MNEG "-" |
| 65 | text MSP " " |
| 66 | text MNL "\n" |
| 67 | text MV2 "v2_admitted=" |
| 68 | text MV2T " train=" |
| 69 | text MV2V " validation=" |
| 70 | text MV2H " heldout=" |
| 71 | text MV2R " refused=" |
| 72 | |
| 73 | fn snl to void |
| 74 | w = write 1 MNL 0 1 |
| 75 | end |
| 76 | |
| 77 | fn ssp to void |
| 78 | w = write 1 MSP 0 1 |
| 79 | end |
| 80 | |
| 81 | fn skw i ulong to ulong |
| 82 | note Config word i (little-endian) from SK. |
| 83 | v = ulong 0 |
| 84 | for k ulong 8 |
| 85 | v = or v shl ulong get SK add mul i 8 k mul k 8 |
| 86 | end |
| 87 | ret v |
| 88 | end |
| 89 | |
| 90 | fn snum fd int n ulong to void |
| 91 | note Decimal ulong to any fd through the driver's own digit buffer. |
| 92 | p = ulong 24 |
| 93 | if eq n 0 |
| 94 | p = 23 |
| 95 | put SD 23 48 |
| 96 | end |
| 97 | while gt n 0 bound 24 |
| 98 | p = sub p 1 |
| 99 | put SD p uchar add 48 rem n 10 |
| 100 | n = div n 10 |
| 101 | end |
| 102 | w = write fd SD p sub 24 p |
| 103 | if ne w long sub 24 p |
| 104 | exit 74 |
| 105 | end |
| 106 | end |
| 107 | |
| 108 | fn ssnum x long to void |
| 109 | if lt x 0 |
| 110 | w = write 1 MNEG 0 1 |
| 111 | x = neg x |
| 112 | end |
| 113 | wnum ulong x |
| 114 | end |
| 115 | |
| 116 | fn sdec x ulong to void |
| 117 | note Binary32 bits as a signed decimal; magnitudes of 2^33 and above print as big. |
| 118 | if ne and x 2147483648 0 |
| 119 | w = write 1 MNEG 0 1 |
| 120 | x = and x 2147483647 |
| 121 | end |
| 122 | if ge and shr x 23 255 160 |
| 123 | w = write 1 MBIG 0 len MBIG |
| 124 | ret |
| 125 | end |
| 126 | wdec x |
| 127 | end |
| 128 | |
| 129 | fn srdcfg n ulong to ulong |
| 130 | o = ulong 0 |
| 131 | while lt o n bound 64 |
| 132 | r = read 0 SK o sub n o |
| 133 | if lt r 0 |
| 134 | exit 74 |
| 135 | end |
| 136 | if eq r 0 |
| 137 | ret o |
| 138 | end |
| 139 | o = add o ulong r |
| 140 | end |
| 141 | ret o |
| 142 | end |
| 143 | |
| 144 | fn srdlb to ulong |
| 145 | note The allow-list block: 4096 bytes, zero padded; returns the used length. |
| 146 | o = ulong 0 |
| 147 | while lt o 4096 bound 4096 |
| 148 | r = read 0 LB o sub 4096 o |
| 149 | if lt r 0 |
| 150 | exit 74 |
| 151 | end |
| 152 | if eq r 0 |
| 153 | ret o |
| 154 | end |
| 155 | o = add o ulong r |
| 156 | end |
| 157 | n = ulong 0 |
| 158 | for i ulong 4096 |
| 159 | if ne get LB i 0 |
| 160 | n = add i 1 |
| 161 | end |
| 162 | end |
| 163 | ret n |
| 164 | end |
| 165 | |
| 166 | fn srdimg n ulong to ulong |
| 167 | note Exactly up to n image bytes into SI[0..n); never reads past them. |
| 168 | o = ulong 0 |
| 169 | while lt o n bound 999999 |
| 170 | r = read 0 SI o sub n o |
| 171 | if lt r 0 |
| 172 | exit 74 |
| 173 | end |
| 174 | if eq r 0 |
| 175 | ret o |
| 176 | end |
| 177 | o = add o ulong r |
| 178 | end |
| 179 | ret o |
| 180 | end |
| 181 | |
| 182 | fn srdrb to ulong |
| 183 | note Records to end of input into RB; 524289 means more than the capacity arrived. |
| 184 | o = ulong 0 |
| 185 | while lt o 524288 bound 999999 |
| 186 | r = read 0 RB o sub 524288 o |
| 187 | if lt r 0 |
| 188 | exit 74 |
| 189 | end |
| 190 | if eq r 0 |
| 191 | ret o |
| 192 | end |
| 193 | o = add o ulong r |
| 194 | end |
| 195 | r = read 0 SM 0 1 |
| 196 | if ne r 0 |
| 197 | ret 524289 |
| 198 | end |
| 199 | ret o |
| 200 | end |
| 201 | |
| 202 | fn swimg n ulong to void |
| 203 | o = ulong 0 |
| 204 | while lt o n bound 999999 |
| 205 | w = write 3 SI o sub n o |
| 206 | if le w 0 |
| 207 | exit 74 |
| 208 | end |
| 209 | o = add o ulong w |
| 210 | end |
| 211 | end |
| 212 | |
| 213 | fn slrcode lr ulong to ulong |
| 214 | if eq lr wmbits 1 8 |
| 215 | ret 8 |
| 216 | end |
| 217 | if eq lr wmbits 1 10 |
| 218 | ret 10 |
| 219 | end |
| 220 | if eq lr wmbits 1 12 |
| 221 | ret 12 |
| 222 | end |
| 223 | ret 0 |
| 224 | end |
| 225 | |
| 226 | fn scfgok to bool |
| 227 | note kind 1|2, lr code 0|8|10|12, epochs and stop <= 64, control <= 2, flags < 8. |
| 228 | k = skw 0 |
| 229 | if or lt k 1 gt k 2 |
| 230 | ret false |
| 231 | end |
| 232 | k = skw 2 |
| 233 | if and ne k 0 and ne k 8 and ne k 10 ne k 12 |
| 234 | ret false |
| 235 | end |
| 236 | if or gt skw 3 64 gt skw 6 64 |
| 237 | ret false |
| 238 | end |
| 239 | if or gt skw 5 2 gt skw 7 15 |
| 240 | ret false |
| 241 | end |
| 242 | ret true |
| 243 | end |
| 244 | |
| 245 | fn slrbits code ulong to ulong |
| 246 | if eq code 0 |
| 247 | ret 0 |
| 248 | end |
| 249 | ret wmbits 1 code |
| 250 | end |
| 251 | |
| 252 | fn skv1 to void |
| 253 | w = write 1 MKIN 0 len MKIN |
| 254 | wnum get SS 0 |
| 255 | snl |
| 256 | w = write 1 MNPA 0 len MNPA |
| 257 | wnum get SS 15 |
| 258 | snl |
| 259 | w = write 1 MSEE 0 len MSEE |
| 260 | wnum get SS 2 |
| 261 | snl |
| 262 | w = write 1 MIFN 0 len MIFN |
| 263 | wnum get SS 19 |
| 264 | snl |
| 265 | w = write 1 MLR 0 len MLR |
| 266 | wnum slrcode get SS 3 |
| 267 | snl |
| 268 | w = write 1 MLRB 0 len MLRB |
| 269 | wnum get SS 3 |
| 270 | snl |
| 271 | w = write 1 MCTL 0 len MCTL |
| 272 | wnum get SS 16 |
| 273 | snl |
| 274 | w = write 1 MEPO 0 len MEPO |
| 275 | wnum get SS 4 |
| 276 | snl |
| 277 | w = write 1 MUPD 0 len MUPD |
| 278 | wnum get SS 6 |
| 279 | snl |
| 280 | w = write 1 MCUR 0 len MCUR |
| 281 | wnum get SS 5 |
| 282 | snl |
| 283 | end |
| 284 | |
| 285 | fn skv2 to void |
| 286 | w = write 1 MMU 0 len MMU |
| 287 | ssnum wsdec get SS 8 |
| 288 | snl |
| 289 | w = write 1 MSH 0 len MSH |
| 290 | wnum get SS 9 |
| 291 | snl |
| 292 | w = write 1 MNTR 0 len MNTR |
| 293 | wnum get SS 10 |
| 294 | snl |
| 295 | w = write 1 MTLS 0 len MTLS |
| 296 | wnum get SS 17 |
| 297 | snl |
| 298 | w = write 1 MTLD 0 len MTLD |
| 299 | sdec get SS 17 |
| 300 | snl |
| 301 | w = write 1 MDLS 0 len MDLS |
| 302 | wnum get SS 13 |
| 303 | snl |
| 304 | w = write 1 MDLD 0 len MDLD |
| 305 | sdec get SS 13 |
| 306 | snl |
| 307 | w = write 1 MBEP 0 len MBEP |
| 308 | wnum get SS 18 |
| 309 | snl |
| 310 | w = write 1 MSTL 0 len MSTL |
| 311 | wnum get SS 14 |
| 312 | snl |
| 313 | end |
| 314 | |
| 315 | fn skv3 n ulong to void |
| 316 | w = write 1 MFFN 0 len MFFN |
| 317 | wnum slfnvp get SS 15 |
| 318 | snl |
| 319 | w = write 1 MBFN 0 len MBFN |
| 320 | wnum slfnvb get SS 15 |
| 321 | snl |
| 322 | w = write 1 MDFN 0 len MDFN |
| 323 | wnum get SS 11 |
| 324 | snl |
| 325 | w = write 1 MREC 0 len MREC |
| 326 | wnum get RC 0 |
| 327 | snl |
| 328 | w = write 1 MIMB 0 len MIMB |
| 329 | wnum n |
| 330 | snl |
| 331 | w = write 1 MIMF 0 len MIMF |
| 332 | wnum sifnv 0 sub n 8 |
| 333 | snl |
| 334 | end |
| 335 | |
| 336 | fn sreport n ulong to void |
| 337 | skv1 |
| 338 | skv2 |
| 339 | skv3 n |
| 340 | w = write 1 MSTA 0 len MSTA |
| 341 | snl |
| 342 | end |
| 343 | |
| 344 | fn scostcol r ulong a ulong to void |
| 345 | w = write 4 MSP 0 1 |
| 346 | snum 4 oxcost r a |
| 347 | end |
| 348 | |
| 349 | fn v2cols r ulong to void |
| 350 | note The v2 columns of a per-record line: pressure, calls, split, workload family. |
| 351 | w = write 4 MSP 0 1 |
| 352 | snum 4 oxpress r |
| 353 | w = write 4 MSP 0 1 |
| 354 | snum 4 oxword r 7 |
| 355 | w = write 4 MSP 0 1 |
| 356 | snum 4 oxpart r |
| 357 | w = write 4 MSP 0 1 |
| 358 | snum 4 oxcell r |
| 359 | end |
| 360 | |
| 361 | fn srecline r ulong to void |
| 362 | note One per-record line on fd 4 (the model uses the current SP). |
| 363 | m = slpick r |
| 364 | snum 4 oxseq r |
| 365 | w = write 4 MSP 0 1 |
| 366 | snum 4 oxfam r |
| 367 | w = write 4 MSP 0 1 |
| 368 | snum 4 oxcore r |
| 369 | w = write 4 MSP 0 1 |
| 370 | snum 4 oxm r |
| 371 | w = write 4 MSP 0 1 |
| 372 | snum 4 oxn r |
| 373 | w = write 4 MSP 0 1 |
| 374 | snum 4 m |
| 375 | w = write 4 MSP 0 1 |
| 376 | snum 4 oxrule r |
| 377 | w = write 4 MSP 0 1 |
| 378 | snum 4 0 |
| 379 | w = write 4 MSP 0 1 |
| 380 | snum 4 slstat r |
| 381 | w = write 4 MSP 0 1 |
| 382 | snum 4 slnear r |
| 383 | w = write 4 MSP 0 1 |
| 384 | snum 4 oxbest r |
| 385 | w = write 4 MSP 0 1 |
| 386 | snum 4 oxcost r m |
| 387 | w = write 4 MSP 0 1 |
| 388 | snum 4 oxcost r oxbest r |
| 389 | scostcol r oxrule r |
| 390 | scostcol r 0 |
| 391 | scostcol r slstat r |
| 392 | scostcol r slnear r |
| 393 | if ne and skw 7 8 0 |
| 394 | v2cols r |
| 395 | end |
| 396 | w = write 4 MNL 0 1 |
| 397 | end |
| 398 | |
| 399 | fn sv2line to void |
| 400 | w = write 1 MV2 0 len MV2 |
| 401 | wnum get RC 10 |
| 402 | w = write 1 MV2T 0 len MV2T |
| 403 | wnum get RC 4 |
| 404 | w = write 1 MV2V 0 len MV2V |
| 405 | wnum get RC 5 |
| 406 | w = write 1 MV2H 0 len MV2H |
| 407 | wnum get RC 6 |
| 408 | w = write 1 MV2R 0 len MV2R |
| 409 | wnum sub get RC 0 get RC 10 |
| 410 | snl |
| 411 | end |
| 412 | |
| 413 | fn sevline part ulong core ulong to void |
| 414 | slevalc part core |
| 415 | w = write 1 MEVL 0 len MEVL |
| 416 | wnum part |
| 417 | w = write 1 MCOR 0 len MCOR |
| 418 | wnum core |
| 419 | for k ulong 17 |
| 420 | ssp |
| 421 | wnum get SE k |
| 422 | end |
| 423 | snl |
| 424 | end |
| 425 | |
| 426 | fn sevals flags ulong to void |
| 427 | w = write 1 MCOL 0 len MCOL |
| 428 | snl |
| 429 | for p ulong 3 |
| 430 | if ne and shr flags p 1 0 |
| 431 | for c ulong 4 |
| 432 | sevline p c |
| 433 | end |
| 434 | for r ulong get RC 0 |
| 435 | if eq oxpart r p |
| 436 | srecline r |
| 437 | end |
| 438 | end |
| 439 | end |
| 440 | end |
| 441 | end |
| 442 | |
| 443 | fn sadmit n ulong lbn ulong to int |
| 444 | note Allow-list status (67) then record admission (66); 0 when admitted. |
| 445 | st = oxallow lbn oxfnv n |
| 446 | if lt st 0 |
| 447 | w = write 1 MUNA 0 len MUNA |
| 448 | wnum ulong neg long st |
| 449 | snl |
| 450 | ret 67 |
| 451 | end |
| 452 | w = write 1 MALW 0 len MALW |
| 453 | wnum ulong st |
| 454 | snl |
| 455 | if eq and skw 7 8 0 |
| 456 | st = oxload n |
| 457 | else |
| 458 | st = oxadm2 n |
| 459 | end |
| 460 | if ne st 0 |
| 461 | w = write 1 MDAT 0 len MDAT |
| 462 | wnum ulong neg long st |
| 463 | snl |
| 464 | ret 66 |
| 465 | end |
| 466 | if ne and skw 7 8 0 |
| 467 | sv2line |
| 468 | end |
| 469 | ret 0 |
| 470 | end |
| 471 | |
| 472 | fn srun m ulong to int |
| 473 | note T (84), R (82) and E (69): read the stream in admission order, then act. |
| 474 | if ne srdcfg 64 64 |
| 475 | ret 68 |
| 476 | end |
| 477 | if not scfgok |
| 478 | ret 68 |
| 479 | end |
| 480 | lbn = srdlb |
| 481 | img = ulong 0 |
| 482 | if ne m 84 |
| 483 | img = sllen skw 0 |
| 484 | if ne srdimg img img |
| 485 | ret 65 |
| 486 | end |
| 487 | end |
| 488 | n = srdrb |
| 489 | if gt n 524288 |
| 490 | ret 66 |
| 491 | end |
| 492 | st = sadmit n lbn |
| 493 | if ne st 0 |
| 494 | ret st |
| 495 | end |
| 496 | if eq m 84 |
| 497 | slinit skw 0 skw 1 slrbits skw 2 skw 5 |
| 498 | if ne and skw 7 8 0 |
| 499 | put SS 20 1 |
| 500 | end |
| 501 | slnorm |
| 502 | else |
| 503 | if eq m 69 |
| 504 | st = sladmit 0 img |
| 505 | else |
| 506 | st = slload 0 img |
| 507 | end |
| 508 | if ne st 0 |
| 509 | w = write 1 MREF 0 len MREF |
| 510 | wnum ulong neg long st |
| 511 | snl |
| 512 | ret 65 |
| 513 | end |
| 514 | if ne get SS 0 skw 0 |
| 515 | ret 68 |
| 516 | end |
| 517 | if ne get SS 20 shr and skw 7 8 3 |
| 518 | ret 68 |
| 519 | end |
| 520 | if eq m 69 |
| 521 | if slbound 0 |
| 522 | w = write 1 MBND 0 len MBND |
| 523 | else |
| 524 | w = write 1 MUNB 0 len MUNB |
| 525 | end |
| 526 | snl |
| 527 | end |
| 528 | end |
| 529 | if ne m 69 |
| 530 | sltrain skw 3 skw 4 skw 6 |
| 531 | img = slsave 0 |
| 532 | swimg img |
| 533 | end |
| 534 | sreport img |
| 535 | if ne skw 7 0 |
| 536 | slbest |
| 537 | sevals skw 7 |
| 538 | end |
| 539 | ret 0 |
| 540 | end |
| 541 | |
| 542 | fn scompare to int |
| 543 | n = srdimg 32768 |
| 544 | if eq n 32768 |
| 545 | r = read 0 SM 0 1 |
| 546 | if ne r 0 |
| 547 | ret 1 |
| 548 | end |
| 549 | end |
| 550 | k = siget 16 |
| 551 | if or lt k 1 gt k 2 |
| 552 | ret 1 |
| 553 | end |
| 554 | k = sllen k |
| 555 | if ne n mul 2 k |
| 556 | w = write 1 MDIF 0 len MDIF |
| 557 | wnum n |
| 558 | snl |
| 559 | ret 1 |
| 560 | end |
| 561 | for i ulong k |
| 562 | if ne get SI i get SI add k i |
| 563 | w = write 1 MDIF 0 len MDIF |
| 564 | wnum i |
| 565 | snl |
| 566 | ret 1 |
| 567 | end |
| 568 | end |
| 569 | w = write 1 MIDN 0 len MIDN |
| 570 | wnum k |
| 571 | ssp |
| 572 | w = write 1 MFNV 0 len MFNV |
| 573 | wnum siget sub k 8 |
| 574 | snl |
| 575 | ret 0 |
| 576 | end |
| 577 | |
| 578 | fn sgen to int |
| 579 | if ne srdcfg 16 16 |
| 580 | ret 68 |
| 581 | end |
| 582 | n = sxgen skw 0 skw 1 |
| 583 | o = ulong 0 |
| 584 | while lt o n bound 999999 |
| 585 | w = write 3 RB o sub n o |
| 586 | if le w 0 |
| 587 | exit 74 |
| 588 | end |
| 589 | o = add o ulong w |
| 590 | end |
| 591 | w = write 1 MREC 0 len MREC |
| 592 | wnum skw 1 |
| 593 | snl |
| 594 | w = write 1 MGB 0 len MGB |
| 595 | wnum n |
| 596 | snl |
| 597 | w = write 1 MFNV 0 len MFNV |
| 598 | wnum oxfnv n |
| 599 | snl |
| 600 | w = write 1 MGL 0 len MGL |
| 601 | ssnum long oxload n |
| 602 | snl |
| 603 | ret 0 |
| 604 | end |
| 605 | |
| 606 | fn main to int |
| 607 | r = read 0 SM 0 1 |
| 608 | if ne r 1 |
| 609 | ret 64 |
| 610 | end |
| 611 | m = get SM 0 |
| 612 | if eq m 71 |
| 613 | ret sgen |
| 614 | end |
| 615 | if eq m 67 |
| 616 | ret scompare |
| 617 | end |
| 618 | if or eq m 84 or eq m 82 eq m 69 |
| 619 | ret srun ulong m |
| 620 | end |
| 621 | ret 64 |
| 622 | end |