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/native/omegese45/core/run.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 / native / omegese45 / core / run.om` 311 lines ยท 5715 bytes Raw Blame History 1 note SPDX-License-Identifier: AGPL-3.0-only 2 note omegese45 core: data files, training schedule, dev metrics and decoding (aien-train #45, 3 note pipeline lane). Needs vocab.om, msg.om, model.om, ckpt.om (and the SHA unit) before it. 4 note Data file (.ids, written by native/omegese45/data/gen.om): records of one byte L (1 .. 176) 5 note then L ids (< 41). Text files are OE45 v1 (docs/omegese45/CONTRACT.md). 6 const OPDBN ulong `4194304` 7 const OPMAXE ulong 40000 8 const OPBUD ulong 31 9 global opdb uchar `4194305` 10 global opdn ulong 1 11 global opeo ulong 40000 12 global opne ulong 1 13 global opperm ulong 40000 14 global opfp uchar 4200 15 global opst ulong 16 16 global opln ulong 1 17 global opsv uchar 256 18 19 note opst: run statistics. 0 unused, 1 positions, 2 correct (teacher-forced argmax), 20 note 3 messages, 4 exact U, 5 exact G, 6 epoch of opperm + 1. 21 22 note argv[i] into opfp; returns its length. 23 fn oppath i ulong to ulong 24 r = argread i opfp 0 4096 25 if or le r 0 gt r 4096 26 exit 2 27 end 28 ret ulong r 29 end 30 31 fn opdecu i ulong to ulong 32 n = oppath i 33 v = ulong 0 34 if or eq n 0 gt n 18 35 exit 2 36 end 37 for k ulong n 38 c = ulong get opfp k 39 if or lt c 48 gt c 57 40 exit 2 41 end 42 v = add mul v 10 sub c 48 43 end 44 ret v 45 end 46 47 note Read the file argv[i] whole into opdb (at most OPDBN bytes, else exit 2). 48 fn opread i ulong to void 49 n = oppath i 50 fd = int fopen opfp 0 n 0 0 51 if lt fd 0 52 exit 70 53 end 54 p = ulong 0 55 dn = false 56 while not dn bound 5000 57 r = read fd opdb p sub add OPDBN 1 p 58 if lt r 0 59 exit 70 60 end 61 if eq r 0 62 dn = true 63 else 64 p = add p ulong r 65 if gt p OPDBN 66 exit 2 67 end 68 end 69 end 70 c = fclose fd 71 put opdn 0 p 72 end 73 74 note Index the id records of opdb (exit 2 on a malformed file). 75 fn opindex to void 76 n = get opdn 0 77 p = ulong 0 78 e = ulong 0 79 while lt p n bound 40001 80 l = ulong get opdb p 81 if or or eq l 0 gt l OPMAXL ge e OPMAXE 82 exit 2 83 end 84 if gt add add p 1 l n 85 exit 2 86 end 87 for k ulong l 88 if ge ulong get opdb add add p 1 k OPV 89 exit 2 90 end 91 end 92 put opeo e p 93 e = add e 1 94 p = add add p 1 l 95 end 96 if eq e 0 97 exit 2 98 end 99 put opne 0 e 100 end 101 102 note sha256 of opdb[0, opdn) into optds. 103 fn ophdat to void 104 c = new uchar 104 0 105 b = new uchar 4096 0 106 d = new uchar 32 0 107 sha256_init c 108 n = get opdn 0 109 p = ulong 0 110 while lt p n bound 1100 111 k = sub n p 112 if gt k 4096 113 k = 4096 114 end 115 for i ulong k 116 put b i get opdb add p i 117 end 118 sha256_update c part b 0 k 119 p = add p k 120 end 121 sha256_final c d 122 for i ulong 32 123 put optds i get d i 124 end 125 end 126 127 note Load the .ids file argv[i]: read, index, hash into optds. 128 fn opldat i ulong to void 129 opread i 130 opindex 131 ophdat 132 end 133 134 note Episode e into opseq / opsl. 135 fn opepi e ulong to void 136 o = get opeo e 137 l = ulong get opdb o 138 for k ulong l 139 put opseq k get opdb add add o 1 k 140 end 141 put opsl 0 l 142 end 143 144 note Epoch order: a Fisher-Yates permutation of 0 .. N-1 from splitmix64 seeded with 145 note orderseed + `1000003` * epoch, rebuilt from the step alone at resume. 146 fn opperms ep ulong to void 147 n = get opne 0 148 put oprs 0 add get opmeta 5 mul ep `1000003` 149 for i ulong n 150 put opperm i i 151 end 152 i = n 153 while gt i 1 bound 40001 154 j = rem opnext i 155 i = sub i 1 156 x = get opperm i 157 put opperm i get opperm j 158 put opperm j x 159 end 160 put opst 6 add ep 1 161 end 162 163 note Train from opmeta[1] to min(until, total), saving every `every` steps and at the end. 164 note Prints `T step phase sum-loss-bits positions` at each save. 165 fn optrain until ulong every ulong to void 166 lr = bitcast f32 uint get opmeta 6 167 s = get opmeta 1 168 if gt until get opmeta 4 169 until = get opmeta 4 170 end 171 n = get opne 0 172 ls = 0.0f32 173 np = ulong 0 174 while lt s until bound 999999 175 ep = div s n 176 if ne get opst 6 add ep 1 177 opperms ep 178 end 179 opepi get opperm rem s n 180 ph = ulong 2 181 if lt s get opmeta 3 182 ph = 1 183 end 184 ls = add ls optrep ph lr 185 np = add np opnpos ph 186 s = add s 1 187 put opmeta 1 s 188 if or eq rem s every 0 eq s until 189 opsave 190 oprt s ph ls np 191 ls = 0.0f32 192 np = 0 193 end 194 end 195 end 196 197 note Trained positions of the current episode under phase ph. 198 fn opnpos ph ulong to ulong 199 if eq ph 1 200 ret get opsl 0 201 end 202 c = ulong 0 203 for t ulong get opsl 0 204 c = add c ulong get opmk t 205 end 206 ret c 207 end 208 209 fn oprt s ulong ph ulong ls f32 np ulong to void 210 ocputc 84 211 ocputc 32 212 ocputn s 213 ocputc 32 214 ocputn ph 215 ocputc 32 216 ocputn ulong bitcast uint ls 217 ocputc 32 218 ocputn np 219 ocputc 10 220 end 221 222 note Decode after the prefix opseq[0, n) (mode 85 U, 71 G). Generated ids follow the prefix 223 note in opseq. Returns 0 ok (count in opln), 50 invalid (U), 53 budget. 224 fn opdecode n ulong md ulong to ulong 225 st = ocstart 5 226 put opln 0 0 227 for i ulong OPBUD 228 t = add n i 229 opfeat t 230 opfwd 231 id = ulong 0 232 if eq md 71 233 if eq ocmask st 0 234 ret 50 235 end 236 id = opargmx false 237 else 238 id = opargmx true 239 end 240 put opseq t uchar id 241 put opln 0 add i 1 242 st = ocstep st id 243 if eq md 71 244 if ocfinal st 245 ret 0 246 end 247 else 248 if eq id 5 249 if ocfinal st 250 ret 0 251 end 252 ret 50 253 end 254 end 255 end 256 ret 53 257 end 258 259 note Dev metrics for one episode: at every A/P message, teacher-forced argmax accuracy and 260 note free decoding (U and G) from the true prefix; exact means the reference message. 261 fn opdevep to void 262 opmask 263 n = get opsl 0 264 for t ulong n 265 if eq get opmk t 1 266 opfeat t 267 opfwd 268 put opst 1 add get opst 1 1 269 if eq opargmx true optgt t 270 put opst 2 add get opst 2 1 271 end 272 end 273 end 274 s = ulong 0 275 for t ulong n 276 if eq get opseq t 5 277 if eq get opmk s 1 278 opdevmsg s add sub t s 1 279 end 280 s = add t 1 281 end 282 end 283 end 284 285 note Message at [s, s + l) of the current episode: decode U and G from its prefix. The 286 note episode is kept in opsv; decoding may write up to OPBUD ids from s, restored after each. 287 fn opdevmsg s ulong l ulong to void 288 for k ulong get opsl 0 289 put opsv k get opseq k 290 end 291 put opst 3 add get opst 3 1 292 put opst 4 add get opst 4 opdevx s l 85 293 put opst 5 add get opst 5 opdevx s l 71 294 end 295 296 fn opdevx s ulong l ulong md ulong to ulong 297 rc = opdecode s md 298 ok = and eq rc 0 eq get opln 0 l 299 for k ulong l 300 if ne get opseq add s k get opsv add s k 301 ok = false 302 end 303 end 304 for k ulong OPBUD 305 put opseq add s k get opsv add s k 306 end 307 if ok 308 ret 1 309 end 310 ret 0 311 end