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/omega-mv/blob/main/train/aien-train/tests/adtrain/main.om # omega-mv Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance. Brought by drakestapleton Sign in to star 1 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-mv / train / aien-train / tests / adtrain / main.om` 269 lines ยท 4024 bytes Raw Blame History 1 note SPDX-License-Identifier: AGPL-3.0-only 2 note adtrain driver. Reads one mode byte from fd 0: 3 note T train 200 steps (L rows, P rows, loss gate 88), S train 120 and save, 4 note R load and continue to 200, Z as S with data seed 29, G tape gradients 5 note against central differences, D write the C-oracle fixture and K rows. 6 note Exits: 90 bad mode, 65 corrupt checkpoint, 66 data-binding mismatch, 7 note 88 loss not reduced, 1 gradient check failed; mlp.om adds 74/86/87. 8 global AD uchar 24 9 global AB uchar 4 10 global AC ulong 2 11 global AL f32 1 12 text ATP "ADTRAIN_T_PASS\n" 13 text ASP "ADTRAIN_S_PASS\n" 14 text ARP "ADTRAIN_R_PASS\n" 15 text AGP "ADTRAIN_G_PASS checked=" 16 text AGF "ADTRAIN_G_FAIL checked=" 17 text ADP "ADTRAIN_D_PASS\n" 18 text ASK "skip" 19 text AFL " failed=" 20 21 fn dout t uchar to void 22 put AB 0 t 23 w = write 1 AB 0 1 24 if ne w 1 25 exit 74 26 end 27 end 28 29 fn dnum n ulong to void 30 if eq n 0 31 dout 48 32 ret 33 end 34 p = ulong 24 35 while gt n 0 bound 24 36 p = sub p 1 37 put AD p uchar add 48 rem n 10 38 n = div n 10 39 end 40 w = write 1 AD p sub 24 p 41 if ne w long sub 24 p 42 exit 74 43 end 44 end 45 46 fn dtext n ulong to void 47 note n selects one of the fixed texts. 48 if eq n 0 49 w = write 1 ATP 0 len ATP 50 end 51 if eq n 1 52 w = write 1 ASP 0 len ASP 53 end 54 if eq n 2 55 w = write 1 ARP 0 len ARP 56 end 57 if eq n 3 58 w = write 1 ADP 0 len ADP 59 end 60 end 61 62 note " \n" 63 fn dline tag uchar a ulong b ulong to void 64 dout tag 65 dout 32 66 dnum a 67 dout 32 68 dnum b 69 dout 10 70 end 71 72 fn dloss s ulong l f32 to void 73 dline 76 s mlbits l 74 end 75 76 fn dparams to void 77 for i ulong 58 78 dline 80 i mlbits get MP i 79 end 80 end 81 82 note Train from the current step up to `upto`, printing L rows, then L upto. 83 note The loss at step 100 is kept in AL for the T loss gate. 84 fn dtrain upto ulong to f32 85 start = get MS 1 86 for i ulong sub upto start 87 s = add start i 88 l = mlstep 89 dloss s l 90 if eq s 100 91 put AL 0 l 92 end 93 end 94 l = mlfwd 95 dloss upto l 96 ret l 97 end 98 99 fn mode_t to void 100 mlinit 17 101 l0 = mlfwd 102 l200 = dtrain 200 103 if not and lt l200 l0 lt l200 get AL 0 104 exit 88 105 end 106 dparams 107 dtext 0 108 end 109 110 fn mode_s seed ulong to void 111 mlinit seed 112 l = dtrain 120 113 cksave l 114 dtext 1 115 end 116 117 fn mode_r to void 118 mlinit 17 119 st = ckload 120 if eq st -1 121 exit 65 122 end 123 if eq st -2 124 exit 66 125 end 126 if ne st 0 127 exit 65 128 end 129 l = dtrain 200 130 dparams 131 dtext 2 132 end 133 134 note Gradient-check step h = 1/64 (exact in binary32, bits 0x3C800000). It is 135 note its own constant, not the learning rate mllr, so a changed lr is caught 136 note by the golden gate and not hidden in the finite-difference step. dgc 137 note scales by 32.0 = 1/(2h); change both together. 138 fn dgeps to f32 139 ret div 1.0f32 64.0f32 140 end 141 142 note One central difference; returns 0 skipped, 1 agreed, 2 disagreed. 143 fn dgc i ulong to ulong 144 p = get MP i 145 eps = dgeps 146 put MP i add p eps 147 fp = mlfwd 148 okp = mlsame 149 put MP i sub p eps 150 fm = mlfwd 151 okm = mlsame 152 put MP i p 153 dout 71 154 dout 67 155 dout 32 156 dnum i 157 dout 32 158 if not and okp okm 159 w = write 1 ASK 0 len ASK 160 dout 10 161 ret 0 162 end 163 d = mul sub fp fm 32.0f32 164 g = get MG i 165 e = fabs sub d g 166 ok = le e eps 167 if ge fabs g eps 168 ok = le mul e 16.0f32 fabs g 169 end 170 dnum mlbits d 171 dout 32 172 if ok 173 dout 49 174 dout 10 175 ret 1 176 end 177 dout 48 178 dout 10 179 ret 2 180 end 181 182 fn mode_g to void 183 mlinit 17 184 l = mlgrad 185 mlmask 186 for i ulong 58 187 dline 71 i mlbits get MG i 188 end 189 put AC 0 0 190 put AC 1 0 191 for i ulong 58 192 r = dgc i 193 if eq r 1 194 put AC 0 add get AC 0 1 195 end 196 if eq r 2 197 put AC 1 add get AC 1 1 198 end 199 end 200 ok = and ge get AC 0 50 eq get AC 1 0 201 if ok 202 w = write 1 AGP 0 len AGP 203 else 204 w = write 1 AGF 0 len AGF 205 end 206 dnum add get AC 0 get AC 1 207 w = write 1 AFL 0 len AFL 208 dnum get AC 1 209 dout 10 210 if not ok 211 exit 1 212 end 213 end 214 215 note K rows: the first ten generator values k (-8..8) of seed 17, for an 216 note external re-implementation of the data generator. 217 fn mode_d to void 218 mlinit 17 219 l = mlgrad 220 mlfix 221 put MS 0 17 222 for i ulong 10 223 k = mlk 224 dout 75 225 dout 32 226 dnum i 227 dout 32 228 if lt k 0 229 dout 45 230 k = neg k 231 end 232 dnum ulong k 233 dout 10 234 end 235 dtext 3 236 end 237 238 fn main to int 239 n = read 0 AB 0 1 240 if ne n 1 241 exit 90 242 end 243 m = get AB 0 244 if eq m 84 245 mode_t 246 ret 0 247 end 248 if eq m 83 249 mode_s 17 250 ret 0 251 end 252 if eq m 90 253 mode_s 29 254 ret 0 255 end 256 if eq m 82 257 mode_r 258 ret 0 259 end 260 if eq m 71 261 mode_g 262 ret 0 263 end 264 if eq m 68 265 mode_d 266 ret 0 267 end 268 exit 90 269 end