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
omega-mv / core / sovereign-core / om / golden / ollm / gdec.om
| 1 | note SPDX-License-Identifier: Apache-2.0 |
| 2 | note om/golden/ollm/gdec.om: greedy decoding of the own Omega LLM for the golden-token gate (DRA-52, |
| 3 | note Core #853). This is not a stand-alone unit. gate.sh builds an aien-train tree with its own |
| 4 | note tests/omegallm/build.sh (TARGET=gb10), renames gpu/gg.om's `fn main to int` (exactly one line) |
| 5 | note to `fn oggmain to int`, and appends this unit, so both decoders call the candidate tree's own |
| 6 | note model.om (CPU, f64) and gpu/ kernels (GB10, f32) unchanged. Every other command still reaches |
| 7 | note the aien-train mains through oggmain. |
| 8 | note Commands (argv[1]; packing as cli.om: little-endian u64 of the bytes, Wolfram |
| 9 | note FromDigits[Reverse[ToCharacterCode[w]],256]): gtcpu 504396739687, gtgpu 504397001831. |
| 10 | note gtcpu CK MERGES N P0 [P1 ..] greedy on the CPU forward (model.om ofwd, f64) |
| 11 | note gtgpu CK MERGES N P0 [P1 ..] greedy on the GB10 forward (gpu/gg.om ggfwd, f32), all prompts |
| 12 | note in one batch, one ggfwd per step |
| 13 | note Context of prompt k: token 0, then Pk (its BPE encoding when V > 256, its bytes otherwise), |
| 14 | note exactly as cli.om cmdsamp builds it; a generated token 0 ends prompt k after it is printed. |
| 15 | note The step reads the logits of the last context position. 1 + |Pk| + N must not exceed T, so the |
| 16 | note window never slides (positions are 0 .. in both decoders). MERGES is read only when V > 256. |
| 17 | note Output, one line per generated token, then a summary line: |
| 18 | note T k s id top1_e9 margin_e9 (id = argmax, lowest index on ties, as cli.om oargmax) |
| 19 | note GTE cpu|gpu prompts steps ns |
| 20 | note top1 is the largest logit; margin is its distance to the second largest, both times 10^9, |
| 21 | note truncated toward zero. gtcpu reads them from the f64 logits. gtgpu reads the CE kernel's row |
| 22 | note output (gpu/gr.om id 21, L <- (e/sum - [c = y]) sc with y = 0 here and sc = 1/(T B)): p_c = |
| 23 | note L_c / sc, p_0 = L_0 / sc + 1, the argmax over p, top1 = the kernel's row max m (stats word 0) |
| 24 | note and margin = log(p_best / p_second). No judgment is made here: om/golden/ollm/gate.om |
| 25 | note compares a gtgpu run with the committed gtcpu reference. |
| 26 | note Exit: 2 usage (argument count, N outside 1 .. 4096, more prompts than 64 or than the batch B, |
| 27 | note context past T); the aien-train refusals of ockload (10-15), obload (27) and the GPU (ggdie, |
| 28 | note 84) are unchanged. |
| 29 | |
| 30 | global zgct ulong 32768 |
| 31 | global zgcn ulong 64 |
| 32 | global zgdn ulong 64 |
| 33 | global zgst ulong 2 |
| 34 | global zgv f64 2 |
| 35 | |
| 36 | text zgtcp "cpu" |
| 37 | text zgtgp "gpu" |
| 38 | |
| 39 | note argument checks and loads; returns N |
| 40 | fn zgargs to ulong |
| 41 | na = oargc |
| 42 | if lt na 6 |
| 43 | exit 2 |
| 44 | end |
| 45 | if gt sub na 5 64 |
| 46 | exit 2 |
| 47 | end |
| 48 | ockload 2 |
| 49 | v = get og 0 |
| 50 | if gt v 256 |
| 51 | obload 3 v |
| 52 | end |
| 53 | nn = oargu 4 |
| 54 | if or eq nn 0 gt nn 4096 |
| 55 | exit 2 |
| 56 | end |
| 57 | if gt get og 1 512 |
| 58 | exit 2 |
| 59 | end |
| 60 | ret nn |
| 61 | end |
| 62 | |
| 63 | fn zgput b ulong i ulong v ulong to void |
| 64 | put zgct add b add 1 i v |
| 65 | end |
| 66 | |
| 67 | note prompt tokens of argument ai after token 0 at zgct[b + 1 ..); returns the context length |
| 68 | fn zgldp ai ulong b ulong to ulong |
| 69 | if gt get og 0 256 |
| 70 | np = obprompt ai |
| 71 | for i ulong np |
| 72 | zgput b i get obtk i |
| 73 | end |
| 74 | ret add 1 np |
| 75 | end |
| 76 | r = oargr ai |
| 77 | if or lt r 1 gt r 4000 |
| 78 | exit 2 |
| 79 | end |
| 80 | for i ulong ulong r |
| 81 | zgput b i ulong get oarg i |
| 82 | end |
| 83 | ret add 1 ulong r |
| 84 | end |
| 85 | |
| 86 | note context of prompt k into zgct[k 512 ..): token 0, then the prompt (argument 5 + k) |
| 87 | fn zgload k ulong nn ulong to void |
| 88 | b = mul k 512 |
| 89 | put zgct b 0 |
| 90 | n = zgldp add 5 k b |
| 91 | if gt add n nn get og 1 |
| 92 | exit 2 |
| 93 | end |
| 94 | put zgcn k n |
| 95 | put zgdn k 0 |
| 96 | end |
| 97 | |
| 98 | fn zgpush k ulong c ulong to void |
| 99 | n = get zgcn k |
| 100 | put zgct add mul k 512 n c |
| 101 | put zgcn k add n 1 |
| 102 | end |
| 103 | |
| 104 | fn zge9 x f64 to long |
| 105 | ret long mul x 1000000000.0f64 |
| 106 | end |
| 107 | |
| 108 | fn zgline k ulong s ulong c ulong a f64 m f64 to void |
| 109 | oputc 84 |
| 110 | oputc 32 |
| 111 | oputu k |
| 112 | oputc 32 |
| 113 | oputu s |
| 114 | oputc 32 |
| 115 | oputu c |
| 116 | oputc 32 |
| 117 | oputl zge9 a |
| 118 | oputc 32 |
| 119 | oputl zge9 m |
| 120 | oputc 10 |
| 121 | end |
| 122 | |
| 123 | fn zgsum which ulong np ulong ns ulong to void |
| 124 | oputc 71 |
| 125 | oputc 84 |
| 126 | oputc 69 |
| 127 | oputc 32 |
| 128 | if eq which 0 |
| 129 | for i ulong 3 |
| 130 | oputc ulong get zgtcp i |
| 131 | end |
| 132 | else |
| 133 | for i ulong 3 |
| 134 | oputc ulong get zgtgp i |
| 135 | end |
| 136 | end |
| 137 | oputc 32 |
| 138 | oputu np |
| 139 | oputc 32 |
| 140 | oputu get zgst 0 |
| 141 | oputc 32 |
| 142 | oputu ns |
| 143 | oputc 10 |
| 144 | oflush |
| 145 | end |
| 146 | |
| 147 | fn zgcset k ulong to void |
| 148 | n = get zgcn k |
| 149 | b = mul k 512 |
| 150 | for i ulong n |
| 151 | put obx i get zgct add b i |
| 152 | end |
| 153 | put og 9 n |
| 154 | end |
| 155 | |
| 156 | note the largest of oa[TMP + c] over c != best |
| 157 | fn zgcsec best ulong to f64 |
| 158 | tm = get og 27 |
| 159 | sv = bitcast f64 ulong 18442240474082181120 |
| 160 | for c ulong get og 0 |
| 161 | if ne c best |
| 162 | sv = fmax sv get oa add tm c |
| 163 | end |
| 164 | end |
| 165 | ret sv |
| 166 | end |
| 167 | |
| 168 | note CPU step of prompt k: the f64 logits of its last position in oa[TMP ..), the argmax (cli.om |
| 169 | note oargmax: lowest index on ties) and the largest logit over the other indices; prints the T |
| 170 | note line, returns the id |
| 171 | fn zgcstep k ulong s ulong to ulong |
| 172 | zgcset k |
| 173 | lf = ofwd 0 |
| 174 | olast |
| 175 | best = oargmax |
| 176 | bv = get oa add get og 27 best |
| 177 | sv = zgcsec best |
| 178 | zgline k s best bv sub bv sv |
| 179 | ret best |
| 180 | end |
| 181 | |
| 182 | fn zgcpu to void |
| 183 | t0 = monons |
| 184 | nn = zgargs |
| 185 | np = sub oargc 5 |
| 186 | put zgst 0 0 |
| 187 | for k ulong np |
| 188 | zgload k nn |
| 189 | for s ulong nn |
| 190 | c = zgcstep k s |
| 191 | put zgst 0 add get zgst 0 1 |
| 192 | zgpush k c |
| 193 | if eq c 0 |
| 194 | break |
| 195 | end |
| 196 | end |
| 197 | end |
| 198 | zgsum 0 np ulong sub monons t0 |
| 199 | end |
| 200 | |
| 201 | note GPU batch rows: row b < np holds prompt b's context, then zeros; every other row and every |
| 202 | note target is 0 |
| 203 | fn zgfill np ulong to void |
| 204 | tt = get og 1 |
| 205 | for b ulong get og 6 |
| 206 | n = ulong 0 |
| 207 | if lt b np |
| 208 | n = get zgcn b |
| 209 | end |
| 210 | for t ulong tt |
| 211 | x = ulong 0 |
| 212 | if lt t n |
| 213 | x = get zgct add mul b 512 t |
| 214 | end |
| 215 | put obx add mul b tt t x |
| 216 | put oby add mul b tt t 0 |
| 217 | end |
| 218 | end |
| 219 | end |
| 220 | |
| 221 | note p_c of row r from the CE kernel output (see the header) |
| 222 | fn zgp r ulong c ulong sc f64 to f64 |
| 223 | v = get og 0 |
| 224 | o = add get gga 11 mul 4 add mul r v c |
| 225 | p = div ggf o sc |
| 226 | if eq c 0 |
| 227 | p = add p 1.0f64 |
| 228 | end |
| 229 | ret p |
| 230 | end |
| 231 | |
| 232 | note argmax of p over row r (lowest index on ties); its p in zgv[0] |
| 233 | fn zgpbest r ulong sc f64 to ulong |
| 234 | best = ulong 0 |
| 235 | bp = zgp r 0 sc |
| 236 | for c ulong get og 0 |
| 237 | p = zgp r c sc |
| 238 | if gt p bp |
| 239 | bp = p |
| 240 | best = c |
| 241 | end |
| 242 | end |
| 243 | put zgv 0 bp |
| 244 | ret best |
| 245 | end |
| 246 | |
| 247 | fn zgpsec r ulong best ulong sc f64 to f64 |
| 248 | sp = bitcast f64 ulong 18442240474082181120 |
| 249 | for c ulong get og 0 |
| 250 | if ne c best |
| 251 | sp = fmax sp zgp r c sc |
| 252 | end |
| 253 | end |
| 254 | ret sp |
| 255 | end |
| 256 | |
| 257 | note GPU step of prompt k after one ggfwd: argmax of p over the row of its last position, second p, |
| 258 | note the kernel's row max; prints the T line, returns the id |
| 259 | fn zggstep k ulong s ulong sc f64 to ulong |
| 260 | r = add mul k get og 1 sub get zgcn k 1 |
| 261 | best = zgpbest r sc |
| 262 | sp = zgpsec r best sc |
| 263 | m = ggf add get gga 12 mul r 12 |
| 264 | mg = 1000.0f64 |
| 265 | if gt sp 0.0f64 |
| 266 | mg = flog div get zgv 0 sp |
| 267 | end |
| 268 | zgline k s best m mg |
| 269 | ret best |
| 270 | end |
| 271 | |
| 272 | fn zgglive np ulong to bool |
| 273 | for k ulong np |
| 274 | if eq get zgdn k 0 |
| 275 | ret true |
| 276 | end |
| 277 | end |
| 278 | ret false |
| 279 | end |
| 280 | |
| 281 | fn zggpu to void |
| 282 | t0 = monons |
| 283 | nn = zgargs |
| 284 | np = sub oargc 5 |
| 285 | if gt np get og 6 |
| 286 | exit 2 |
| 287 | end |
| 288 | put zgst 0 0 |
| 289 | for k ulong np |
| 290 | zgload k nn |
| 291 | end |
| 292 | ggopen |
| 293 | ggupw |
| 294 | sc = div 1.0f64 f64 mul get og 1 get og 6 |
| 295 | for s ulong nn |
| 296 | if not zgglive np |
| 297 | break |
| 298 | end |
| 299 | zgfill np |
| 300 | ggupb |
| 301 | ggfwd |
| 302 | for k ulong np |
| 303 | if eq get zgdn k 0 |
| 304 | c = zggstep k s sc |
| 305 | put zgst 0 add get zgst 0 1 |
| 306 | zgpush k c |
| 307 | if eq c 0 |
| 308 | put zgdn k 1 |
| 309 | end |
| 310 | end |
| 311 | end |
| 312 | end |
| 313 | zgsum 1 np ulong sub monons t0 |
| 314 | end |
| 315 | |
| 316 | fn main to int |
| 317 | if lt oargc 2 |
| 318 | exit 2 |
| 319 | end |
| 320 | w = ocmdw |
| 321 | if eq w 504396739687 |
| 322 | zgcpu |
| 323 | ret 0 |
| 324 | end |
| 325 | if eq w 504397001831 |
| 326 | zggpu |
| 327 | ret 0 |
| 328 | end |
| 329 | ret oggmain |
| 330 | end |