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/omegallm/ckpt.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 / omegallm / ckpt.om` 274 lines ยท 6104 bytes Raw Blame History 1 note SPDX-License-Identifier: AGPL-3.0-only 2 note omegallm ckpt.om (aien-train#52): checkpoint OLLMCK01 / OLLMCK02 and gradient OLLMGR01 files 3 note (CONTRACT section 6, CONTRACT-V1 section 6). Needs math.om, data.om, model.om, adam.om before it. 4 note Files are streamed: a save encodes the f64 payload little-endian in chunks of OCKC values into 5 note ock, hashes each chunk (FNV-1a 64) and writes it at its file position through the platform 6 note unit (ocwopen, ocwput, ocwend; lio.om writes PATH.tmp, fsync, rename; eio.om the file in 7 note place), then writes the header at position 0. A load reads the header and then the payload in 8 note chunks through oprd into opw, hashing and decoding into the pools in one pass. 9 note CK01 header 112 bytes (FNV at 104); CK02 120 bytes (G at 104, FNV at 112); GR01 112 bytes, step 10 note field = B, one payload. Largest file at the v3 maxima: 120 + 24 P with P = `29995392` (Wolfram: 11 note 120+24*`29995392` -> `719889528`); a file over OCKCAP = `719889529` bytes is refused with 15 before its 12 note header is read, as v0 refused a file over its image (exactly OCKCAP bytes goes to the header 13 note checks, then 15). 14 note Magic as a little-endian u64 (Wolfram FromDigits[Reverse[ToCharacterCode["OLLMCK01"]],256] 15 note -> `3544415659172318287`; "OLLMGR01" -> `3544423372933581903`; "OLLMCK02" -> `3616473253210246223`). 16 note Load refusals (exit codes): 10 file shorter than its header or than header + 24 P, 11 bad magic, 17 note 12 a shape zero or over the maximum, V < 256, D mod H != 0, TOTAL > 999999, or (CK02) G = 0, 18 note G > B or B mod G != 0, 13 P disagrees with the shapes, 14 FNV-1a mismatch, 15 file longer than 19 note header + 24 P; 70 I/O. 20 const OCKCAP ulong `719889529` 21 const OCKC ulong 65536 22 global ock uchar 524288 23 24 fn ocput8 o ulong v ulong to void 25 for k ulong 8 26 put ock add o k uchar and shr v mul k 8 255 27 end 28 end 29 30 31 note little-endian u64 at ock[o .. o + 8) 32 fn ocget8 o ulong to ulong 33 v = ulong 0 34 for k ulong 8 35 v = or v shl ulong get ock add o k mul k 8 36 end 37 ret v 38 end 39 40 note decode m values from ock into gradient pool [o .. o + m) (a worker's gradient block, lio.om) 41 fn ocdecb o ulong m ulong to void 42 for j ulong m 43 ogrp add o j bitcast f64 ocget8 mul j 8 44 end 45 end 46 note little-endian u64 at opw[o .. o + 8) 47 fn opw8 o ulong to ulong 48 v = ulong 0 49 for k ulong 8 50 v = or v shl ulong get opw add o k mul k 8 51 end 52 ret v 53 end 54 55 note FNV-1a 64 step over ock[0 .. n) from state h (basis `cbf29ce484222325`, prime `100000001b3`) 56 fn ocfnvk h ulong n ulong to ulong 57 x = h 58 for i ulong n 59 x = mul xor x ulong get ock i `1099511628211` 60 end 61 ret x 62 end 63 64 fn ocfnvw h ulong n ulong to ulong 65 x = h 66 for i ulong n 67 x = mul xor x ulong get opw i `1099511628211` 68 end 69 ret x 70 end 71 72 note header fields from og into ock[0 .. 104); magic mg, step field st 73 fn ochead mg ulong st ulong to void 74 ocput8 0 mg 75 for i ulong 7 76 ocput8 add 8 mul i 8 get og i 77 end 78 ocput8 64 get og 40 79 ocput8 72 st 80 ocput8 80 get og 42 81 ocput8 88 get og 43 82 ocput8 96 get og 8 83 end 84 85 note encode m values of pool k (0 params, 1 m, 2 v, 3 GRD, 4 BLK) from value index i into ock 86 fn ocenc k ulong i ulong m ulong to void 87 if eq k 0 88 for j ulong m 89 ocput8 mul j 8 bitcast ulong owg add i j 90 end 91 ret 92 end 93 if ge k 3 94 o = add get og 10 i 95 if eq k 4 96 o = add get og 8 i 97 end 98 for j ulong m 99 ocput8 mul j 8 bitcast ulong ogrg add o j 100 end 101 ret 102 end 103 o = add get og add 10 k i 104 for j ulong m 105 ocput8 mul j 8 bitcast ulong omvg add o j 106 end 107 end 108 109 note decode m values from opw into pool k (0 params, 1 m, 2 v) from value index i 110 fn ocdec k ulong i ulong m ulong to void 111 if eq k 0 112 for j ulong m 113 owp add i j bitcast f64 opw8 mul j 8 114 end 115 ret 116 end 117 o = add get og add 10 k i 118 for j ulong m 119 omvp add o j bitcast f64 opw8 mul j 8 120 end 121 end 122 123 note stream pools ks .. ke-1 (ocenc numbering) after a header of hl bytes; returns the FNV-1a 124 fn ocbody ks ulong ke ulong hl ulong to ulong 125 p = get og 8 126 h = ulong `14695981039346656037` 127 pos = hl 128 nc = div add p sub OCKC 1 OCKC 129 for k ulong sub ke ks 130 for c ulong nc 131 i = mul c OCKC 132 m = sub p i 133 if gt m OCKC 134 m = OCKC 135 end 136 ocenc add ks k i m 137 nb = mul m 8 138 h = ocfnvk h nb 139 ocwput pos nb 140 pos = add pos nb 141 end 142 end 143 ret h 144 end 145 146 note write checkpoint (params, m, v) to argv[ai] with the loaded or initialised magic (og 46) 147 fn ocksave ai ulong to void 148 ocwopen ai 149 hl = ulong 112 150 if eq get og 46 2 151 hl = 120 152 end 153 h = ocbody 0 3 hl 154 if eq hl 120 155 ochead `3616473253210246223` get og 41 156 ocput8 104 get og 44 157 ocput8 112 h 158 else 159 ochead `3544415659172318287` get og 41 160 ocput8 104 h 161 end 162 ocwput 0 hl 163 ocwend ai 164 end 165 166 note write gradient file GR01: header with step = B, payload GRD (for either checkpoint magic) 167 fn ogrsave ai ulong to void 168 ocwopen ai 169 h = ocbody 3 4 112 170 ochead `3544423372933581903` get og 6 171 ocput8 104 h 172 ocwput 0 112 173 ocwend ai 174 end 175 176 note load the checkpoint named by argv[ai] into og, ow (params) and omv (m, v) 177 fn ockload ai ulong to void 178 n = ofsz ai 179 if gt n OCKCAP 180 exit 15 181 end 182 hn = oprd ai 0 0 120 183 if lt n 112 184 exit 10 185 end 186 mg = opw8 0 187 hl = ulong 112 188 if eq mg `3616473253210246223` 189 hl = 120 190 put og 46 2 191 else 192 if ne mg `3544415659172318287` 193 exit 11 194 end 195 put og 46 1 196 end 197 if lt n hl 198 exit 10 199 end 200 for i ulong 7 201 put og i opw8 add 8 mul i 8 202 end 203 if not ogeom 204 exit 12 205 end 206 put og 40 opw8 64 207 put og 41 opw8 72 208 put og 42 opw8 80 209 put og 43 opw8 88 210 if gt get og 42 999999 211 exit 12 212 end 213 g = ulong 1 214 if eq hl 120 215 g = opw8 104 216 end 217 if not ogok2 g 218 exit 12 219 end 220 put og 44 g 221 put og 45 1 222 p = get og 8 223 if ne opw8 96 p 224 exit 13 225 end 226 hs = opw8 sub hl 8 227 pb = mul 24 p 228 if lt n add hl pb 229 exit 10 230 end 231 if gt n add hl pb 232 exit 15 233 end 234 if ne ocklp ai hl p hs 1 235 exit 14 236 end 237 end 238 239 note one pass over the payload at hl: read, hash and decode each chunk; exit 70 on a short read. 240 note Returns 1 when the payload FNV equals hs, else 0. 241 fn ocklp ai ulong hl ulong p ulong hs ulong to ulong 242 h = ulong `14695981039346656037` 243 nc = div add p sub OCKC 1 OCKC 244 pos = hl 245 for k ulong 3 246 for c ulong nc 247 i = mul c OCKC 248 m = sub p i 249 if gt m OCKC 250 m = OCKC 251 end 252 nb = mul m 8 253 if ne oprd ai pos 0 nb nb 254 exit 70 255 end 256 h = ocfnvw h nb 257 ocdec k i m 258 pos = add pos nb 259 end 260 end 261 if eq h hs 262 ret 1 263 end 264 ret 0 265 end 266 267 note G against the loaded shapes: 1 <= G <= B and B mod G = 0 268 fn ogok2 g ulong to bool 269 b = get og 6 270 if or eq g 0 gt g b 271 ret false 272 end 273 ret eq rem b g 0 274 end