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 / gate.om

954 lines · 14618 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0
2note om/golden/ollm/gate.om: golden-token record and comparator for the own Omega LLM (DRA-52,
3note Core #853). Every judgment of the gate is made here; gate.sh and record.sh only sequence.
4note Build (om/golden/build.sh does this):
5note { printf 'om2\n'; cat om/vendor/json.om om/vendor/sha256.om om/golden/ollm/gate.om; } | omc
6note Modes:
7note gate rec CPUOUT CK MERGES PROMPTS MAXTOK FLOOR_E9 DRIFT_E9 ENGINE SOURCE HOST UTC LABEL
8note turns a gdec.om gtcpu run (CPUOUT) into one aien-golden-ollm/1 record on stdout. The
9note checkpoint, merges and prompt file are hashed here. Prompt k keeps its leading steps whose
10note top-1 margin is at least FLOOR_E9 (10^-9 logit units); the first step below the floor and
11note everything after it are dropped, and a generated id 0 is kept and ends the prompt. Each prompt
12note must keep at least RMIN steps (exit 5 ambiguous otherwise).
13note gate cmp REF CANDOUT CK MERGES PROMPTS
14note compares a gdec.om gtgpu run with the record: the three files must hash to the record's
15note identities (exit 3 NOTCOMPARABLE otherwise). For every kept step the candidate id must
16note equal the reference id (DIVERGE) and its top-1 logit must be within DRIFT_E9 of the
17note reference's (DRIFT). Prints MATCH, DIVERGE or DRIFT per prompt and a summary line.
18note Exit: 0 written or every prompt matches, 1 a DIVERGE or DRIFT, 2 usage or bad argument,
19note 3 not comparable, 4 file or format refusal, 5 ambiguous prompt (rec). Formats: README.md.
20
21const KMAX ulong 64
22const SMAX ulong 4096
23const RMIN ulong 4
24const BUFCAP ulong 4194304
25
26global gb uchar 4194304
27global gbn ulong 1
28global gcur ulong 1
29global gw ulong 2
30global gpa uchar 4352
31global gh uchar 65536
32global gsha uchar 192
33global go uchar 65536
34global gon ulong 1
35global gid ulong 262144
36global gtop long 262144
37global gmar long 262144
38global gcnt ulong 64
39global gend ulong 64
40global grid ulong 262144
41global grtop long 262144
42global grn ulong 64
43global ghd ulong 16
44global gstr uchar 1024
45global gstl ulong 8
46global gsum ulong 8
47global gmd long 2
48
49text tmrec "rec"
50text tmcmp "cmp"
51text tpre "golden-ollm: refused "
52text tuse "usage: gate rec CPUOUT CK MERGES PROMPTS MAXTOK FLOOR_E9 DRIFT_E9 ENGINE SOURCE HOST UTC LABEL | gate cmp REF CANDOUT CK MERGES PROMPTS"
53text tio "io"
54text tbig "too-large"
55text tfmt "format"
56text tamb "ambiguous-prompt"
57text tbarg "bad-argument"
58text tschema "aien-golden-ollm/1"
59text tk0 "label"
60text tk1 "ckpt_sha256"
61text tk2 "merges_sha256"
62text tk3 "prompts_sha256"
63text tk4 "prompts"
64text tk5 "max_tokens"
65text tk6 "margin_floor_e9"
66text tk7 "drift_bound_e9"
67text tk8 "ref_decoder"
68text tk9 "ref_engine_sha256"
69text tk10 "ref_source"
70text tk11 "host_id"
71text tk12 "utc"
72text tgtcpu "gtcpu"
73text tend "end"
74text tgte "GTE"
75text tcpu "cpu"
76text tgpu "gpu"
77text treal "REAL"
78text tfake "FAKE"
79text tsyn "SYNTHETIC"
80text tnc "NOTCOMPARABLE "
81text tmatch "MATCH "
82text tdiv "DIVERGE "
83text tdrift "DRIFT "
84text tsumm "golden-ollm cmp prompts="
85text tn " n="
86text tmd " maxdrift_e9="
87text tix " index="
88text tref " ref="
89text tcand " cand="
90text tcend "end"
91text ts1 " compared="
92text ts2 " match="
93text ts3 " diverge="
94text ts4 " drift="
95
96note ---- output
97
98fn oflsh to void
99n = get gon 0
100p = ulong 0
101while lt p n bound 65537
102w = write 1 go p sub n p
103if le w 0
104exit 4
105end
106p = add p ulong w
107end
108put gon 0 0
109end
110
111fn oc c ulong to void
112n = get gon 0
113if ge n 65536
114oflsh
115n = ulong 0
116end
117put go n uchar and c 255
118put gon 0 add n 1
119end
120
121fn ot t view uchar * to void
122for i ulong len t
123oc ulong get t i
124end
125end
126
127fn ou v ulong to void
128d = new uchar 24 0
129n = ulong 0
130x = v
131while true bound 21
132put d n uchar add rem x 10 48
133n = add n 1
134x = div x 10
135if eq x 0
136break
137end
138end
139for i ulong n
140oc ulong get d sub sub n 1 i
141end
142end
143
144fn ol v long to void
145if lt v 0
146oc 45
147if eq v -9223372036854775808
148ou 9223372036854775808
149else
150ou ulong neg v
151end
152else
153ou ulong v
154end
155end
156
157fn osp to void
158oc 32
159end
160
161fn onl to void
162oc 10
163end
164
165note refusal: message on stderr, exit code
166fn die code int why view uchar * to void
167oflsh
168w = write 2 tpre 0 len tpre
169w = write 2 why 0 len why
170m = new uchar 1 10
171w = write 2 m 0 1
172exit code
173end
174
175fn usage to void
176oflsh
177w = write 2 tuse 0 len tuse
178m = new uchar 1 10
179w = write 2 m 0 1
180exit 2
181end
182
183note ---- arguments and files
184
185note argv[i] into gpa; returns its length or exits 2
186fn arg i ulong to ulong
187r = argread i gpa 0 4096
188if or le r 0 gt r 4096
189usage
190end
191ret ulong r
192end
193
194note the whole file named by argv[i] into gb[0 .. gbn); exits 4 on I/O or when it exceeds BUFCAP
195fn fload i ulong to void
196n = arg i
197fd = fopen gpa 0 n 0 0
198if lt fd 0
199die 4 tio
200end
201t = ulong 0
202while true bound 999999
203if ge t BUFCAP
204die 4 tbig
205end
206k = read int fd gb t sub BUFCAP t
207if lt k 0
208die 4 tio
209end
210if eq k 0
211break
212end
213t = add t ulong k
214end
215c = fclose int fd
216put gbn 0 t
217put gcur 0 0
218end
219
220note sha256 of the file named by argv[i] into gsha[slot 64 ..)
221fn fhash i ulong slot ulong to void
222n = arg i
223fd = fopen gpa 0 n 0 0
224if lt fd 0
225die 4 tio
226end
227hreset
228while true bound 999999
229k = read int fd gh 0 65536
230if lt k 0
231die 4 tio
232end
233if eq k 0
234break
235end
236for j ulong ulong k
237b = hpush get gh j
238end
239end
240c = fclose int fd
241if not hfinal
242die 4 tio
243end
244for j ulong 64
245put gsha add mul slot 64 j get hd j
246end
247end
248
249note ---- line and word scanning over gb[gcur ..)
250
251note next word: gw = (start, length); words end at a space or a line end; returns false at a line end
252note or the end of the buffer (no word)
253fn word to bool
254c = get gcur 0
255n = get gbn 0
256if ge c n
257ret false
258end
259if eq get gb c 10
260ret false
261end
262s = c
263while lt c n bound 999999
264x = get gb c
265if or eq x 32 eq x 10
266break
267end
268c = add c 1
269end
270put gw 0 s
271put gw 1 sub c s
272if eq get gw 1 0
273die 4 tfmt
274end
275if lt c n
276if eq get gb c 32
277c = add c 1
278end
279end
280put gcur 0 c
281ret true
282end
283
284note the line must end here: consumes the newline, exits 4 otherwise
285fn eol to void
286c = get gcur 0
287if ge c get gbn 0
288die 4 tfmt
289end
290if ne get gb c 10
291die 4 tfmt
292end
293put gcur 0 add c 1
294end
295
296fn wneed to void
297if not word
298die 4 tfmt
299end
300end
301
302note the current word equals t
303fn wis t view uchar * to bool
304if ne get gw 1 len t
305ret false
306end
307s = get gw 0
308for i ulong len t
309if ne get gb add s i get t i
310ret false
311end
312end
313ret true
314end
315
316fn wexp t view uchar * to void
317wneed
318if not wis t
319die 4 tfmt
320end
321end
322
323note the current word as an unsigned decimal of 1 .. 19 digits
324fn wu to ulong
325n = get gw 1
326if gt n 19
327die 4 tfmt
328end
329s = get gw 0
330v = ulong 0
331for i ulong n
332x = get gb add s i
333if or lt x 48 gt x 57
334die 4 tfmt
335end
336v = add mul v 10 ulong sub x 48
337end
338ret v
339end
340
341fn wl to long
342s = get gw 0
343if eq get gb s 45
344put gw 0 add s 1
345put gw 1 sub get gw 1 1
346if eq get gw 1 0
347die 4 tfmt
348end
349v = wu
350if gt v 9223372036854775807
351die 4 tfmt
352end
353ret neg long v
354end
355v = wu
356if gt v 9223372036854775807
357die 4 tfmt
358end
359ret long v
360end
361
362fn nu to ulong
363wneed
364ret wu
365end
366
367fn nl to long
368wneed
369ret wl
370end
371
372note the current word is 64 lowercase hex and equals gsha[slot 64 ..) when chk; copies it there
373note otherwise
374fn whex slot ulong chk bool to bool
375if ne get gw 1 64
376die 4 tfmt
377end
378s = get gw 0
379ok = true
380for i ulong 64
381x = get gb add s i
382if not or and ge x 48 le x 57 and ge x 97 le x 102
383die 4 tfmt
384end
385o = add mul slot 64 i
386if chk
387if ne get gsha o x
388ok = false
389end
390else
391put gsha o x
392end
393end
394ret ok
395end
396
397note the argument i as a decimal: 1 .. 19 digits
398fn argu i ulong to ulong
399n = arg i
400if gt n 19
401die 2 tbarg
402end
403v = ulong 0
404for j ulong n
405x = get gpa j
406if or lt x 48 gt x 57
407die 2 tbarg
408end
409v = add mul v 10 ulong sub x 48
410end
411ret v
412end
413
414fn idch x uchar to bool
415if and ge x 48 le x 57
416ret true
417end
418if and ge x 65 le x 90
419ret true
420end
421if and ge x 97 le x 122
422ret true
423end
424if or or eq x 46 eq x 95 or eq x 47 eq x 64
425ret true
426end
427ret or or eq x 58 eq x 43 eq x 45
428end
429
430note the argument i must be 1 .. 128 of [A-Za-z0-9._/@:+-]; copied into gstr[slot 128 ..), length
431note gstl[slot]
432fn argid i ulong slot ulong to void
433n = arg i
434if gt n 128
435die 2 tbarg
436end
437for j ulong n
438x = get gpa j
439if not idch x
440die 2 tbarg
441end
442put gstr add mul slot 128 j x
443end
444put gstl slot n
445end
446
447fn ostr slot ulong to void
448for j ulong get gstl slot
449oc ulong get gstr add mul slot 128 j
450end
451end
452
453fn osha slot ulong to void
454for j ulong 64
455oc ulong get gsha add mul slot 64 j
456end
457end
458
459note ---- gdec.om output: T k s id top1 margin lines, then GTE cpu|gpu K steps ns
460
461note parse gb as a gdec run of the decoder named t; fills gid/gtop/gmar, gcnt, gend; returns K
462fn dparse t view uchar * to ulong
463for k ulong KMAX
464put gcnt k 0
465put gend k 0
466end
467steps = ulong 0
468while true bound 262146
469wneed
470if wis tgte
471break
472end
473if or ne get gw 1 1 ne get gb get gw 0 84
474die 4 tfmt
475end
476dline
477steps = add steps 1
478end
479wexp t
480kk = nu
481st = nu
482ns = nu
483eol
484if lt get gcur 0 get gbn 0
485die 4 tfmt
486end
487if or or eq kk 0 gt kk KMAX ne st steps
488die 4 tfmt
489end
490for k ulong KMAX
491if and ge k kk ne get gcnt k 0
492die 4 tfmt
493end
494end
495ret kk
496end
497
498note one T line after its T word: steps of prompt k must arrive in order 0, 1, ..; nothing after an
499note id 0
500fn dline to void
501k = nu
502s = nu
503if or ge k KMAX ge s SMAX
504die 4 tfmt
505end
506if or ne s get gcnt k ne get gend k 0
507die 4 tfmt
508end
509o = add mul k SMAX s
510c = nu
511put gid o c
512put gtop o nl
513put gmar o nl
514eol
515put gcnt k add s 1
516if eq c 0
517put gend k 1
518end
519end
520
521note ---- rec
522
523fn reckey t view uchar * to void
524ot t
525osp
526end
527
528fn reclab to void
529n = arg 13
530for j ulong n
531oc ulong get gpa j
532end
533end
534
535note kept steps of prompt k under floor f: leading steps with margin >= f; an id 0 ends it
536fn keep k ulong f long to ulong
537n = ulong 0
538for s ulong get gcnt k
539o = add mul k SMAX s
540if lt get gmar o f
541break
542end
543n = add n 1
544if eq get gid o 0
545break
546end
547end
548ret n
549end
550
551fn recrow tag ulong k ulong n ulong which ulong to void
552oc tag
553osp
554ou k
555osp
556ou n
557for s ulong n
558o = add mul k SMAX s
559osp
560if eq which 0
561ou get gid o
562end
563if eq which 1
564ol get gtop o
565end
566if eq which 2
567ol get gmar o
568end
569end
570onl
571end
572
573fn rec to void
574if ne ulong argcnt 14
575usage
576end
577mx = argu 6
578fl = argu 7
579dr = argu 8
580if or or eq mx 0 gt mx SMAX or eq fl 0 eq dr 0
581die 2 tbarg
582end
583if or gt fl 1000000000000 gt dr 1000000000000
584die 2 tbarg
585end
586argid 9 0
587argid 10 1
588argid 11 2
589argid 12 3
590ok = or or argis 13 treal argis 13 tfake argis 13 tsyn
591if not ok
592die 2 tbarg
593end
594fload 2
595kk = dparse tcpu
596for k ulong kk
597if lt get gcnt k mx
598if eq get gend k 0
599die 4 tfmt
600end
601end
602if gt get gcnt k mx
603die 4 tfmt
604end
605end
606fhash 3 0
607fhash 4 1
608fhash 5 2
609for k ulong kk
610if lt keep k long fl RMIN
611die 5 tamb
612end
613end
614recout kk mx fl dr
615end
616
617fn recout kk ulong mx ulong fl ulong dr ulong to void
618ot tschema
619onl
620reckey tk0
621reclab
622onl
623reckey tk1
624osha 0
625onl
626reckey tk2
627osha 1
628onl
629reckey tk3
630osha 2
631onl
632reckey tk4
633ou kk
634onl
635reckey tk5
636ou mx
637onl
638reckey tk6
639ou fl
640onl
641reckey tk7
642ou dr
643onl
644reckey tk8
645ot tgtcpu
646onl
647recid tk9 0
648recid tk10 1
649recid tk11 2
650recid tk12 3
651for k ulong kk
652n = keep k long fl
653recrow 80 k n 0
654recrow 76 k n 1
655recrow 77 k n 2
656end
657ot tend
658onl
659oflsh
660end
661
662fn recid t view uchar * slot ulong to void
663reckey t
664ostr slot
665onl
666end
667
668note ---- cmp
669
670note one header line KEY VALUE; hex slots are compared with the hashed files
671fn hkey t view uchar * to void
672wexp t
673wneed
674end
675
676fn hsha t view uchar * slot ulong to bool
677hkey t
678ok = whex slot true
679eol
680ret ok
681end
682
683note record line TAG k n v0 .. v(n-1); which 0 ids into grid, 1 top1 into grtop, 2 margins (each
684note must meet the record's floor). As rec writes it: RMIN <= n <= max_tokens (<= SMAX).
685fn rrow tag ulong k ulong which ulong to void
686wneed
687if or ne get gw 1 1 ne ulong get gb get gw 0 tag
688die 4 tfmt
689end
690if ne nu k
691die 4 tfmt
692end
693n = nu
694if or lt n RMIN gt n get ghd 1
695die 4 tfmt
696end
697if eq which 0
698put grn k n
699end
700if ne n get grn k
701die 4 tfmt
702end
703for s ulong n
704o = add mul k SMAX s
705if eq which 0
706put grid o nu
707end
708if eq which 1
709put grtop o nl
710end
711if eq which 2
712if lt nl long get ghd 2
713die 4 tfmt
714end
715end
716end
717eol
718end
719
720fn hshas t view uchar * slot ulong to void
721put ghd add 4 slot 0
722if hsha t slot
723put ghd add 4 slot 1
724end
725end
726
727note parse the record in gb against the file hashes in gsha slots 0..2: ghd[4 + slot] = 1 when the
728note record's checkpoint, merges or prompts hash equals the file's; ghd 1 max_tokens, 2 floor,
729note 3 drift bound; returns K
730fn rparse to ulong
731wexp tschema
732eol
733hkey tk0
734if not or or wis treal wis tfake wis tsyn
735die 4 tfmt
736end
737eol
738hshas tk1 0
739hshas tk2 1
740hshas tk3 2
741hkey tk4
742kk = wu
743eol
744hkey tk5
745put ghd 1 wu
746eol
747hkey tk6
748put ghd 2 wu
749eol
750hkey tk7
751put ghd 3 wu
752eol
753mtk = get ghd 1
754if or or eq mtk 0 gt mtk SMAX or eq get ghd 2 0 eq get ghd 3 0
755die 4 tfmt
756end
757if or gt get ghd 2 1000000000000 gt get ghd 3 1000000000000
758die 4 tfmt
759end
760hkey tk8
761if not wis tgtcpu
762die 4 tfmt
763end
764eol
765rskip tk9
766rskip tk10
767rskip tk11
768rskip tk12
769if or eq kk 0 gt kk KMAX
770die 4 tfmt
771end
772for k ulong kk
773rrow 80 k 0
774rrow 76 k 1
775rrow 77 k 2
776end
777wexp tend
778eol
779if lt get gcur 0 get gbn 0
780die 4 tfmt
781end
782ret kk
783end
784
785fn rskip t view uchar * to void
786hkey t
787eol
788end
789
790fn onc t view uchar * to void
791ot tnc
792ot t
793onl
794oflsh
795exit 3
796end
797
798fn absd a long b long to ulong
799if gt a b
800ret ulong sub a b
801end
802ret ulong sub b a
803end
804
805note compare prompt k; prints its verdict; returns 0 match, 1 diverge, 2 drift
806fn cmpk k ulong dr ulong to ulong
807n = get grn k
808mxd = ulong 0
809for s ulong n
810o = add mul k SMAX s
811if ge s get gcnt k
812cdiv k s get grid o false 0
813ret 1
814end
815if ne get gid o get grid o
816cdiv k s get grid o true get gid o
817ret 1
818end
819d = absd get gtop o get grtop o
820if gt d dr
821cdrift k s get grtop o get gtop o
822ret 2
823end
824if gt d mxd
825mxd = d
826end
827end
828ot tmatch
829ou k
830ot tn
831ou n
832ot tmd
833ou mxd
834onl
835if gt mxd get gsum 4
836put gsum 4 mxd
837end
838ret 0
839end
840
841
842fn cdiv k ulong s ulong r ulong has bool c ulong to void
843ot tdiv
844ou k
845ot tix
846ou s
847ot tref
848ou r
849ot tcand
850if has
851ou c
852else
853ot tcend
854end
855onl
856end
857
858fn cdrift k ulong s ulong r long c long to void
859ot tdrift
860ou k
861ot tix
862ou s
863ot tref
864ol r
865ot tcand
866ol c
867onl
868end
869
870
871fn cmp to void
872if ne ulong argcnt 7
873usage
874end
875fhash 4 0
876fhash 5 1
877fhash 6 2
878fload 2
879kk = rparse
880dr = get ghd 3
881if eq get ghd 4 0
882onc tk1
883end
884if eq get ghd 5 0
885onc tk2
886end
887if eq get ghd 6 0
888onc tk3
889end
890fload 3
891ck = dparse tgpu
892if ne ck kk
893onc tk4
894end
895for i ulong 8
896put gsum i 0
897end
898for k ulong kk
899v = cmpk k dr
900put gsum v add get gsum v 1
901put gsum 3 add get gsum 3 get grn k
902end
903csum kk
904end
905
906fn csum kk ulong to void
907ot tsumm
908ou kk
909ot ts1
910ou get gsum 3
911ot ts2
912ou get gsum 0
913ot ts3
914ou get gsum 1
915ot ts4
916ou get gsum 2
917ot tmd
918ou get gsum 4
919onl
920oflsh
921if ne get gsum 0 kk
922exit 1
923end
924exit 0
925end
926
927fn argis i ulong t view uchar * to bool
928r = argread i gpa 0 4096
929if ne r long len t
930ret false
931end
932for j ulong len t
933if ne get gpa j get t j
934ret false
935end
936end
937ret true
938end
939
940fn main to int
941if lt ulong argcnt 2
942usage
943end
944if argis 1 tmrec
945rec
946ret 0
947end
948if argis 1 tmcmp
949cmp
950ret 0
951end
952usage
953ret 2
954end