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 / evidence / OMEGALLM / gpu / src-diff-4b83ad45-7bd36d87.txt
| 1 | 6278c6278 |
| 2 | < note gr.om: row and elementwise SM121 kernels for the ollm GPU step (slots 9..22), emitted after |
| 3 | --- |
| 4 | > note gr.om: row and elementwise SM121 kernels for the ollm GPU step (slots 9..24), emitted after |
| 5 | 6696a6697,6758 |
| 6 | > note 23 SQN: out[c] = sum over i in [512 c, 512 c + 512) of g[i]^2 (f32); args nchunk g out. The |
| 7 | > note gradient buffer is padded with zeros to a multiple of 512 (ggplan, ggbwd), so no tail guard. |
| 8 | > fn grsqn to void |
| 9 | > grpro |
| 10 | > grptr 10 1 4 2048 |
| 11 | > gkmovz 64 |
| 12 | > top = grtop 30 64 |
| 13 | > grld8 32 10 true |
| 14 | > for u uint 8 |
| 15 | > gkffmaf 64 add 32 u add 32 u 64 |
| 16 | > end |
| 17 | > gradv 10 32 |
| 18 | > grbot 30 top |
| 19 | > grptr 12 3 4 4 |
| 20 | > gkstg 12 64 0 false |
| 21 | > gkexit |
| 22 | > end |
| 23 | > note OMUTH: 1 in the product; 0 in mutant h (beta1 0.8 on chip), which gacmp must catch. |
| 24 | > const OMUTH ulong 1 |
| 25 | > note 24 ADAM (f32, on chip): g = g c; m = b1 m + (1 - b1) g; v = b2 v + (1 - b2) g^2; |
| 26 | > note w -= lrb m / (sqrt(v ibc2) + 1e-8), the f32 image of og.om oadam1/oadam2 with lrb = lr/bc1 and |
| 27 | > note ibc2 = 1/bc2 from the host. Args P w m v g c lrb ibc2 (slots 0, 2-9, 10, 11, 12). |
| 28 | > fn gradam to void |
| 29 | > grpro |
| 30 | > b1 = 0.9f64 |
| 31 | > if eq OMUTH 0 |
| 32 | > b1 = 0.8f64 |
| 33 | > end |
| 34 | > gkmovi 24 grf b1 |
| 35 | > gkmovi 25 grf sub 1.0f64 0.9 |
| 36 | > gkmovi 27 grf 0.99f64 |
| 37 | > gkmovi 28 grf sub 1.0f64 0.99 |
| 38 | > gkmovi 29 grf 0.00000001f64 |
| 39 | > grptr 10 1 4 4 |
| 40 | > grptr 12 3 4 4 |
| 41 | > grptr 14 5 4 4 |
| 42 | > grptr 16 7 4 4 |
| 43 | > gkldc 64 grarg 10 false |
| 44 | > gkldc 65 grarg 11 true |
| 45 | > gkldc 66 grarg 12 true |
| 46 | > gkldg 32 16 0 true |
| 47 | > gkldg 33 12 0 true |
| 48 | > gkldg 34 14 0 true |
| 49 | > gkldg 35 10 0 true |
| 50 | > gkfmulf 32 32 64 |
| 51 | > gkfmulf 33 33 24 |
| 52 | > gkffmaf 33 32 25 33 |
| 53 | > gkfmulf 36 32 32 |
| 54 | > gkfmulf 34 34 27 |
| 55 | > gkffmaf 34 36 28 34 |
| 56 | > gkfmulf 37 34 66 |
| 57 | > grmufu 38 37 8192 |
| 58 | > grfadd 38 38 29 |
| 59 | > grmufu 39 38 4096 |
| 60 | > gkfmulf 40 33 65 |
| 61 | > gkfmulf 40 40 39 |
| 62 | > grfsub 35 35 40 |
| 63 | > gkstg 10 35 0 false |
| 64 | > gkstg 12 33 0 true |
| 65 | > gkstg 14 34 0 true |
| 66 | > gkexit |
| 67 | > end |
| 68 | 6707c6769 |
| 69 | < for k uint 14 |
| 70 | --- |
| 71 | > for k uint 16 |
| 72 | 6739a6802,6807 |
| 73 | > if eq id 23 |
| 74 | > grsqn |
| 75 | > end |
| 76 | > if eq id 24 |
| 77 | > gradam |
| 78 | > end |
| 79 | 6803a6872,6876 |
| 80 | > note P rounded up to the SQN chunk of 512; the gradient buffer is that long and zeroed to it |
| 81 | > fn ggp5 to ulong |
| 82 | > ret mul ggcd get og 8 512 512 |
| 83 | > end |
| 84 | > |
| 85 | 6833c6906 |
| 86 | < ggput 1 get og 8 |
| 87 | --- |
| 88 | > ggput 1 ggp5 |
| 89 | 6853a6927,6929 |
| 90 | > ggput 21 get og 8 |
| 91 | > ggput 22 get og 8 |
| 92 | > ggput 23 div ggp5 512 |
| 93 | 7320c7396 |
| 94 | < ggew 20 get og 8 gga1 1 gga1 1 |
| 95 | --- |
| 96 | > ggew 20 ggp5 gga1 1 gga1 1 |
| 97 | 7360,7361c7436,7437 |
| 98 | < note upload the f32 parameters, the batch tokens and the CSR of x (rows sorted by token) |
| 99 | < fn ggup to void |
| 100 | --- |
| 101 | > note upload the f32 parameters |
| 102 | > fn ggupw to void |
| 103 | 7365a7442,7446 |
| 104 | > put gkinv 0 1 |
| 105 | > end |
| 106 | > |
| 107 | > note upload the batch tokens and the CSR of x (rows sorted by token) |
| 108 | > fn ggupb to void |
| 109 | 7370a7452,7504 |
| 110 | > note n values omv[s + j] as f32 to arena byte offset o + 4 j, and back (one chunk of an Adam moment) |
| 111 | > fn ggupmc s ulong o ulong n ulong to void |
| 112 | > h = get gbmem 5 |
| 113 | > for j ulong n |
| 114 | > x = bitcast uint f32 get omv add s j |
| 115 | > m = mapset h add o mul j 4 4 ulong x |
| 116 | > end |
| 117 | > end |
| 118 | > |
| 119 | > fn ggdnmc s ulong o ulong n ulong to void |
| 120 | > h = get gbmem 5 |
| 121 | > for j ulong n |
| 122 | > x = uint mapget h add o mul j 4 4 |
| 123 | > put omv add s j f64 bitcast f32 x |
| 124 | > end |
| 125 | > end |
| 126 | > |
| 127 | > note chip parameters of chunk q back into ow as f64 |
| 128 | > fn ggdnwc q ulong p ulong to void |
| 129 | > h = get gbmem 5 |
| 130 | > o = get gga 0 |
| 131 | > i0 = mul q OCH |
| 132 | > for j ulong sub oce q p i0 |
| 133 | > i = add i0 j |
| 134 | > x = uint mapget h add o mul i 4 4 |
| 135 | > put ow i f64 bitcast f32 x |
| 136 | > end |
| 137 | > end |
| 138 | > |
| 139 | > note optimizer state (ow, omv) to the chip as f32 (m in gga 21, v in gga 22), and back |
| 140 | > fn ggupst to void |
| 141 | > ggupw |
| 142 | > p = get og 8 |
| 143 | > for q ulong ocn p |
| 144 | > i0 = mul q OCH |
| 145 | > n = sub oce q p i0 |
| 146 | > ggupmc add get og 11 i0 add get gga 21 mul i0 4 n |
| 147 | > ggupmc add get og 12 i0 add get gga 22 mul i0 4 n |
| 148 | > end |
| 149 | > put gkinv 0 1 |
| 150 | > end |
| 151 | > |
| 152 | > fn ggdnst to void |
| 153 | > p = get og 8 |
| 154 | > for q ulong ocn p |
| 155 | > ggdnwc q p |
| 156 | > i0 = mul q OCH |
| 157 | > n = sub oce q p i0 |
| 158 | > ggdnmc add get og 11 i0 add get gga 21 mul i0 4 n |
| 159 | > ggdnmc add get og 12 i0 add get gga 22 mul i0 4 n |
| 160 | > end |
| 161 | > end |
| 162 | > |
| 163 | 7460,7461c7594,7596 |
| 164 | < note the step loss and gradient (into ogr[0..P)) for the batch in obx/oby; ggopen first |
| 165 | < note phase wall times of the last gggrad (ns): 0 upload, 1 forward, 2 backward, 3 download, 4 loss |
| 166 | --- |
| 167 | > note the step loss and gradient for the batch in obx/oby; ggopen first. full: upload the f32 |
| 168 | > note parameters first and download the gradient into ogr[0..P) after; otherwise both stay on chip. |
| 169 | > note phase wall times (ns): 0 upload, 1 forward, 2 backward, 3 download, 4 loss, 5 on-chip Adam |
| 170 | 7463c7598 |
| 171 | < fn gggrad to f64 |
| 172 | --- |
| 173 | > fn ggpass full bool to f64 |
| 174 | 7465c7600,7603 |
| 175 | < ggup |
| 176 | --- |
| 177 | > if full |
| 178 | > ggupw |
| 179 | > end |
| 180 | > ggupb |
| 181 | 7473a7612 |
| 182 | > if full |
| 183 | 7474a7614 |
| 184 | > end |
| 185 | 7482a7623,7666 |
| 186 | > fn gggrad to f64 |
| 187 | > ret ggpass true |
| 188 | > end |
| 189 | > |
| 190 | > note clip and Adam on chip at step og[41], the f32 image of oadam: SQN partial sums of g^2, the |
| 191 | > note norm, clip factor, schedule and bias corrections on the host in f64, then ADAM over P |
| 192 | > fn ggadam to void |
| 193 | > p = get og 8 |
| 194 | > nc = div ggp5 512 |
| 195 | > ggu 0 nc |
| 196 | > ggpt 1 gga1 1 |
| 197 | > ggpt 2 gga1 23 |
| 198 | > ggrun 23 6 ggcd nc 64 1 1 |
| 199 | > h = get gbmem 5 |
| 200 | > so = get gga 23 |
| 201 | > ss = 0.0f64 |
| 202 | > for c ulong nc |
| 203 | > x = uint mapget h add so mul c 4 4 |
| 204 | > ss = add ss f64 bitcast f32 x |
| 205 | > end |
| 206 | > nr = fsqrt ss |
| 207 | > cl = 1.0f64 |
| 208 | > if gt nr 1.0 |
| 209 | > cl = div 1.0 nr |
| 210 | > end |
| 211 | > s = get og 41 |
| 212 | > lrs = olrs s bitcast f64 get og 43 |
| 213 | > bc1 = sub 1.0 opowb 0.9 s |
| 214 | > bc2 = sub 1.0 opowb 0.99 s |
| 215 | > if eq OMUTC 0 |
| 216 | > bc1 = 1.0f64 |
| 217 | > bc2 = 1.0f64 |
| 218 | > end |
| 219 | > ggu 0 p |
| 220 | > ggpt 1 gga1 0 |
| 221 | > ggpt 2 gga1 21 |
| 222 | > ggpt 3 gga1 22 |
| 223 | > ggpt 4 gga1 1 |
| 224 | > ggu 10 ulong grf cl |
| 225 | > ggu 11 ulong grf div lrs bc1 |
| 226 | > ggu 12 ulong grf div 1.0f64 bc2 |
| 227 | > ggrun 24 13 ggcd p 64 1 1 |
| 228 | > end |
| 229 | > |
| 230 | 7486c7670 |
| 231 | < for i ulong 5 |
| 232 | --- |
| 233 | > for i ulong 6 |
| 234 | 7651c7835,8014 |
| 235 | < note gb10 platform main: gcmp and gtrain here, every other command through the CPU main (lio.om) |
| 236 | --- |
| 237 | > note ogr[P + i] = ow[i], the f64 parameter before the step |
| 238 | > fn ggkw q ulong p ulong to void |
| 239 | > i0 = mul q OCH |
| 240 | > for j ulong sub oce q p i0 |
| 241 | > i = add i0 j |
| 242 | > put ogr add p i get ow i |
| 243 | > end |
| 244 | > end |
| 245 | > |
| 246 | > note ogr[i] = chip parameter i as f64 |
| 247 | > fn ggdw q ulong p ulong to void |
| 248 | > h = get gbmem 5 |
| 249 | > wo = get gga 0 |
| 250 | > i0 = mul q OCH |
| 251 | > for j ulong sub oce q p i0 |
| 252 | > i = add i0 j |
| 253 | > x = uint mapget h add wo mul i 4 4 |
| 254 | > put ogr i f64 bitcast f32 x |
| 255 | > end |
| 256 | > end |
| 257 | > |
| 258 | > note over i < P with w0 = ogr[P + i], c = ow[i] (CPU f64 result), g = ogr[i] (chip f32 result): |
| 259 | > note u = c - w0, d = (g - f32(w0)) - u; ggam 0 max |d|, 1 max |u|, 2 max (|d| - 2^-24 |c|), the part |
| 260 | > note of d above the half-ulp rounding of the f32 master weight |
| 261 | > global ggam f64 3 |
| 262 | > fn ggad1 i ulong p ulong to void |
| 263 | > w0 = get ogr add p i |
| 264 | > c = get ow i |
| 265 | > u = sub c w0 |
| 266 | > g = sub get ogr i f64 f32 w0 |
| 267 | > d = fabs sub g u |
| 268 | > u = fabs u |
| 269 | > e = sub d mul fabs c 0.000000059604644775390625f64 |
| 270 | > if gt d get ggam 0 |
| 271 | > put ggam 0 d |
| 272 | > end |
| 273 | > if gt u get ggam 1 |
| 274 | > put ggam 1 u |
| 275 | > end |
| 276 | > if gt e get ggam 2 |
| 277 | > put ggam 2 e |
| 278 | > end |
| 279 | > end |
| 280 | > |
| 281 | > fn ggadc q ulong p ulong to void |
| 282 | > i0 = mul q OCH |
| 283 | > for j ulong sub oce q p i0 |
| 284 | > ggad1 add i0 j p |
| 285 | > end |
| 286 | > end |
| 287 | > |
| 288 | > note gacmp CK DATA S: one step from CK on batch S with the chip gradient, Adam on the CPU (oadam, f64) |
| 289 | > note and on the chip (ggadam, f32); prints `GA P maxd_e12 maxu_e12 rel_e9 resid_e9 tol_e9 adam_ns |
| 290 | > note loss_micro` and GACMP PASS (resid = max(|d| - 2^-24 |c|) / max |u| < tol = 2^-16) or GACMP FAIL |
| 291 | > note (exit 46) |
| 292 | > fn ggacmp to void |
| 293 | > if ne oargc 5 |
| 294 | > exit 2 |
| 295 | > end |
| 296 | > ockload 2 |
| 297 | > odopen 3 |
| 298 | > obatch oargu 4 |
| 299 | > put og 10 0 |
| 300 | > p = get og 8 |
| 301 | > ggopen |
| 302 | > ggupst |
| 303 | > lg = ggpass true |
| 304 | > for q ulong ocn p |
| 305 | > ggkw q p |
| 306 | > end |
| 307 | > oadam |
| 308 | > t0 = monons |
| 309 | > ggadam |
| 310 | > t1 = monons |
| 311 | > for q2 ulong ocn p |
| 312 | > ggdw q2 p |
| 313 | > end |
| 314 | > for k ulong 3 |
| 315 | > put ggam k 0.0f64 |
| 316 | > end |
| 317 | > for q3 ulong ocn p |
| 318 | > ggadc q3 p |
| 319 | > end |
| 320 | > mu = get ggam 1 |
| 321 | > rel = div get ggam 0 mu |
| 322 | > res = div get ggam 2 mu |
| 323 | > tol = div 1.0f64 65536.0f64 |
| 324 | > oputc 71 |
| 325 | > oputc 65 |
| 326 | > oputc 32 |
| 327 | > oputu p |
| 328 | > oputc 32 |
| 329 | > oputl rmic mul get ggam 0 1000000.0f64 |
| 330 | > oputc 32 |
| 331 | > oputl rmic mul mu 1000000.0f64 |
| 332 | > oputc 32 |
| 333 | > oputl rmic mul rel 1000.0f64 |
| 334 | > oputc 32 |
| 335 | > oputl rmic mul res 1000.0f64 |
| 336 | > oputc 32 |
| 337 | > oputl rmic mul tol 1000.0f64 |
| 338 | > oputc 32 |
| 339 | > oputl sub t1 t0 |
| 340 | > oputc 32 |
| 341 | > oputl rmic lg |
| 342 | > oputc 10 |
| 343 | > r = nvstop |
| 344 | > oputc 71 |
| 345 | > oputc 65 |
| 346 | > oputc 67 |
| 347 | > oputc 77 |
| 348 | > oputc 80 |
| 349 | > oputc 32 |
| 350 | > if lt res tol |
| 351 | > oputc 80 |
| 352 | > oputc 65 |
| 353 | > oputc 83 |
| 354 | > oputc 83 |
| 355 | > oputc 10 |
| 356 | > oflush |
| 357 | > ret |
| 358 | > end |
| 359 | > oputc 70 |
| 360 | > oputc 65 |
| 361 | > oputc 73 |
| 362 | > oputc 76 |
| 363 | > oputc 10 |
| 364 | > oflush |
| 365 | > exit 46 |
| 366 | > end |
| 367 | > |
| 368 | > note gtrainf CK TRAIN UNTIL EVERY: gtrain with the parameters and Adam state resident on the chip in |
| 369 | > note f32 (ggadam); only the batch goes up each step. At save points the state comes back to f64 for |
| 370 | > note ocksave and `T s+1 loss_micro` is printed; GT at the end has the last step's phase times. |
| 371 | > fn ggtrainf to void |
| 372 | > if ne oargc 6 |
| 373 | > exit 2 |
| 374 | > end |
| 375 | > ockload 2 |
| 376 | > odopen 3 |
| 377 | > un = oargu 4 |
| 378 | > ev = oargu 5 |
| 379 | > if eq ev 0 |
| 380 | > exit 2 |
| 381 | > end |
| 382 | > en = get og 42 |
| 383 | > if lt un en |
| 384 | > en = un |
| 385 | > end |
| 386 | > ggopen |
| 387 | > ggupst |
| 388 | > while lt get og 41 en bound 999999 |
| 389 | > s = get og 41 |
| 390 | > obatch s |
| 391 | > put og 10 0 |
| 392 | > ls = ggpass false |
| 393 | > t = monons |
| 394 | > ggadam |
| 395 | > put ggtm 5 sub monons t |
| 396 | > s1 = add s 1 |
| 397 | > put og 41 s1 |
| 398 | > if or eq rem s1 ev 0 eq s1 en |
| 399 | > ggdnst |
| 400 | > ocksave 2 |
| 401 | > oputc 84 |
| 402 | > oputc 32 |
| 403 | > oputu s1 |
| 404 | > oputc 32 |
| 405 | > oputl rmic ls |
| 406 | > oputc 10 |
| 407 | > oflush |
| 408 | > end |
| 409 | > end |
| 410 | > ggtms |
| 411 | > oflush |
| 412 | > r = nvstop |
| 413 | > end |
| 414 | > |
| 415 | > note gb10 platform main: gcmp, gtrain, gtrainf and gacmp here, every other command through the CPU |
| 416 | > note main (lio.om) |
| 417 | 7664a8028,8035 |
| 418 | > if eq w 28831846509999207 |
| 419 | > ggtrainf |
| 420 | > ret 0 |
| 421 | > end |
| 422 | > if eq w 482871566695 |
| 423 | > ggacmp |
| 424 | > ret 0 |
| 425 | > end |