interplane.Get Omega
Read in your language

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

branch main Branches Tags History

omega-mv / core / sovereign-core / om / golden / ollm / gdec.om

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