interplane.Get Omega
Read in your language

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

branch main Branches Tags History

aien-train / native / omegese45 / translate / rep2en.om

625 lines · 11536 bytes Raw Blame History
1note SPDX-License-Identifier: AGPL-3.0-only
2note rep2en: goal G + model report P + runtime facts.tsv -> fixed-template
3note English built only from the runtime facts. Success is printed only when
4note every job of G has, as its last facts row, class ok and exit 0, and P
5note agrees with G and with the facts. A P that contradicts the facts gives
6note `G2E_CONTRADICT <what>` and 30; an invalid input `G2E_INVALID <what>`
7note and 31. Facts follow interface v1.2 section 5: exact header line, exit
8note to class/code map, ok rows with mjr1_outcome 1 and a P-256 compressed
9note verifier key, and a legal job/attempt history (otfrows, othist).
10note Needs otio.om, vocab.om, msg.om, otmsg.om before it and otfrag.om
11note after it. Templates are documented in TRANSLATOR.md.
12text otfr "Completed and verified: one matmul_u32 job multiplying a | by | matrix by a | matrix with seed |; job | dag_id | mjr1_sha256 |.\n|Completed and verified: two matmul_u32 jobs, each multiplying a | matrix, with seeds | and |Not completed: refused before dispatch (code bound): the goal asks for a | matmul and a dimension is outside the admitted range 1 to 256; nothing was dispatched.\n|Not completed: job | was refused (code | failed (code |): |G2E_CONTRADICT |G2E_INVALID |usage: rep2en FACTS_TSV < goal-and-report\n|the worker refused a replay of an already executed job|the job was refused for budget or fuel|the worker refused the job|the connection to the worker failed|the verifier refused the worker receipt|the verifier recompute failed|the recomputed result did not match the worker result|a local input or output error occurred|goal |report |facts\n|input\n|operands\n|jobs\n|class\n|code\n|dispatch\n|bound\n"
13text othdt "job\tattempt\tm\tk\tn\tseed\texit\tclass\tcode\tdag_id\tmjr1_sha256\tmjr1_outcome\tverifier\n"
14
15const OTFMAX ulong 65536
16const OTRMAX ulong 64
17note facts.tsv bytes, row field offsets/lengths (13 per row), row values
18note (job attempt m k n seed exit class code; class 1 ok 2 refused 3 fail;
19note code = vocabulary id 14..21 or 0 for `-`).
20global otfb uchar 65536
21global otfo ulong 832
22global otfl ulong 832
23global otrv ulong 576
24global otnr ulong 1
25global otpath uchar 4096
26note Goal: kind (6 mm, 7 pair), m, k, n, s, t. Report: outcome id (10 ok,
27note 11 refused, 12 fail), kind, m, k, n, s, t, code id.
28global otg ulong 6
29global otp ulong 8
30
31note Field f of facts row r equals the vocabulary word id.
32fn otfeqw r ulong f ulong id ulong to bool
33ocvinit
34x = add mul r 13 f
35o = get otfo x
36l = get otfl x
37if ne l get ocwl id
38ret false
39end
40w = get ocwo id
41for i ulong l
42if ne get otfb add o i get ocvtsv add w i
43ret false
44end
45end
46ret true
47end
48
49note Field is exactly `-`.
50fn otfdash r ulong f ulong to bool
51x = add mul r 13 f
52if ne get otfl x 1
53ret false
54end
55ret eq get otfb get otfo x 45
56end
57
58note Field is n lowercase hex digits.
59fn otfhex r ulong f ulong n ulong to bool
60x = add mul r 13 f
61if ne get otfl x n
62ret false
63end
64o = get otfo x
65for i ulong n
66c = get otfb add o i
67ok = or and ge c 48 le c 57 and ge c 97 le c 102
68if not ok
69ret false
70end
71end
72ret true
73end
74
75note Field is 64 lowercase hex digits or exactly `-`.
76fn otfhod r ulong f ulong to bool
77if otfdash r f
78ret true
79end
80ret otfhex r f 64
81end
82
83note Field is exactly `1` (MJR1 outcome byte 1, completed).
84fn otfone r ulong f ulong to bool
85x = add mul r 13 f
86if ne get otfl x 1
87ret false
88end
89ret eq get otfb get otfo x 49
90end
91
92note Field is a P-256 compressed public key: 66 lowercase hex digits
93note starting `02` or `03`.
94fn otfkey r ulong f ulong to bool
95if not otfhex r f 66
96ret false
97end
98o = get otfo add mul r 13 f
99if ne get otfb o 48
100ret false
101end
102c = get otfb add o 1
103ret or eq c 50 eq c 51
104end
105
106note Decimal value of field f of row r; OTBAD2 when not 1..9 digits.
107const OTBAD2 ulong 1099511627776
108fn otfnum r ulong f ulong to ulong
109x = add mul r 13 f
110o = get otfo x
111l = get otfl x
112if or eq l 0 gt l 9
113ret OTBAD2
114end
115v = ulong 0
116for i ulong l
117c = get otfb add o i
118if or lt c 48 gt c 57
119ret OTBAD2
120end
121v = add mul v 10 ulong sub c 48
122end
123ret v
124end
125
126note Append field f of row r.
127fn otpfld r ulong f ulong to void
128x = add mul r 13 f
129o = get otfo x
130for i ulong get otfl x
131otpb get otfb add o i
132end
133end
134
135note otfb[0, n) starts with the exact header line othdt.
136fn othdrok n ulong to bool
137h = len othdt
138if lt n h
139ret false
140end
141for i ulong h
142if ne get otfb i get othdt i
143ret false
144end
145end
146ret true
147end
148
149note Split otfb[h, n), h = the header length, into rows of 13
150note TAB-separated fields. False when a row is malformed, a line is empty
151note (other than the final newline), or there are more than OTRMAX rows.
152fn otfsplit n ulong to bool
153put otnr 0 0
154r = ulong 0
155f = ulong 0
156p = len othdt
157b = p
158while le p n bound 65537
159c = uchar 10
160if lt p n
161c = get otfb p
162end
163if or eq c 9 eq c 10
164if eq c 10
165if and eq p b eq f 0
166if lt p n
167ret false
168end
169p = add p 1
170continue
171end
172end
173if ge r OTRMAX
174ret false
175end
176if ge f 13
177ret false
178end
179x = add mul r 13 f
180put otfo x b
181put otfl x sub p b
182f = add f 1
183b = add p 1
184if eq c 10
185if ne f 13
186ret false
187end
188r = add r 1
189f = 0
190end
191end
192p = add p 1
193end
194if ne f 0
195ret false
196end
197put otnr 0 r
198ret true
199end
200
201note Decode and check each row's values into otrv (9 per row). False on a
202note row that is not a well-formed facts row (see TRANSLATOR.md).
203fn otfrows to bool
204for r ulong get otnr 0
205v = mul r 9
206for f ulong 7
207x = otfnum r f
208if eq x OTBAD2
209ret false
210end
211put otrv add v f x
212end
213cl = ulong 0
214if otfeqw r 7 10
215cl = 1
216end
217if otfeqw r 7 11
218cl = 2
219end
220if otfeqw r 7 12
221cl = 3
222end
223if eq cl 0
224ret false
225end
226put otrv add v 7 cl
227cd = ulong 0
228if not otfdash r 8
229for id ulong 8
230if otfeqw r 8 add id 14
231cd = add id 14
232end
233end
234if eq cd 0
235ret false
236end
237end
238put otrv add v 8 cd
239ex = get otrv add v 6
240if eq cl 1
241if or ne ex 0 ne cd 0
242ret false
243end
244if not and otfhex r 9 64 otfhex r 10 64
245ret false
246end
247if not otfone r 11
248ret false
249end
250if not otfkey r 12
251ret false
252end
253else
254if eq cd 0
255ret false
256end
257if not and otfdash r 11 otfdash r 12
258ret false
259end
260note A non-ok row may carry a real dag_id or a receipt digest: each is
261note 64 lowercase hex or `-` (interface v1.2 section 5).
262if not and otfhod r 9 otfhod r 10
263ret false
264end
265note Code -> class and exit (interface v1.2 section 5): replay, budget,
266note worker (ids 14..16) are refused with exit 11; transport (17) fails
267note with exit 10; receipt, recomp, verdict, io (18..21) fail with 12..15.
268wc = ulong 3
269wx = sub cd 6
270if le cd 16
271wc = 2
272wx = 11
273end
274if eq cd 17
275wx = 10
276end
277if ne cl wc
278ret false
279end
280if ne ex wx
281ret false
282end
283end
284end
285ret true
286end
287
288fn otrval r ulong f ulong to ulong
289ret get otrv add mul r 9 f
290end
291
292note Job/attempt history (interface v1.2 section 5). Jobs appear in order
293note starting at 1, each with attempt 1 first. A second row for the same
294note job is legal only as attempt 2 right after an attempt-1 `fail
295note transport`. A row for the next job is legal only after the previous
296note job's last row was ok. So nothing follows a job's ok row, every
297note non-ok row other than one retried transport failure is the last row,
298note and every attempt is 1 or 2, increasing within a job.
299note pt: the previous row was an attempt-1 `fail transport`; pk: it was ok.
300fn othist to bool
301pj = ulong 0
302pt = false
303pk = false
304for r ulong get otnr 0
305j = otrval r 0
306a = otrval r 1
307if eq j pj
308if not and eq a 2 pt
309ret false
310end
311else
312if not and eq j add pj 1 eq a 1
313ret false
314end
315if and gt pj 0 not pk
316ret false
317end
318end
319c7 = otrval r 7
320c8 = otrval r 8
321pj = j
322pt = and eq a 1 and eq c7 3 eq c8 17
323pk = eq c7 1
324end
325ret true
326end
327
328note Row r states the goal dims and seed sd.
329fn otrowok r ulong sd ulong to bool
330if ne otrval r 2 get otg 1
331ret false
332end
333if ne otrval r 3 get otg 2
334ret false
335end
336if ne otrval r 4 get otg 3
337ret false
338end
339ret eq otrval r 5 sd
340end
341
342note Emit `G2E_CONTRADICT <what>` (fragment fw) and return 30.
343fn otcontra fw ulong to int
344put otol 0 0
345otpfr 17
346otpfr fw
347ret 30
348end
349
350note Emit `G2E_INVALID <what>` and return 31.
351fn otinval fw ulong to int
352put otol 0 0
353otpfr 18
354otpfr fw
355ret 31
356end
357
358fn otrdims to void
359otpdec get otg 1
360otpfr 1
361otpdec get otg 2
362otpfr 2
363otpdec get otg 2
364otpfr 1
365otpdec get otg 3
366end
367
368note Index of the last facts row of job j, or OTRMAX when there is none.
369fn otlast j ulong to ulong
370x = OTRMAX
371for r ulong get otnr 0
372if eq otrval r 0 j
373x = r
374end
375end
376ret x
377end
378
379note "; job {j} dag_id {dag} mjr1_sha256 {sha}"
380fn otpjob j ulong r ulong to void
381otpfr 4
382otpdec j
383otpfr 5
384otpfld r 9
385otpfr 6
386otpfld r 10
387end
388
389note Read the facts file named by argument 1 into otfb. Returns the byte
390note count or -1.
391fn otrdfacts to long
392an = argread 1 otpath 0 4096
393if le an 0
394ret neg long 1
395end
396fd = fopen otpath 0 ulong an 0 0
397if lt fd 0
398ret neg long 1
399end
400n = ulong 0
401while true bound 65537
402if ge n OTFMAX
403ret neg long 1
404end
405k = read int fd otfb n sub OTFMAX n
406if lt k 0
407ret neg long 1
408end
409if eq k 0
410break
411end
412n = add n ulong k
413end
414c = fclose int fd
415ret long n
416end
417
418note rep2en on otin[0, n): first line G, second line P. Returns the exit
419note code with otob holding the English sentence or the typed line.
420fn otrepen n ulong to int
421note Split stdin into two lines.
422e1 = n
423for i ulong n
424if eq get otin i 10
425e1 = i
426break
427end
428end
429if ge e1 n
430ret otinval 31
431end
432s2 = add e1 1
433e2 = n
434if gt e2 s2
435if eq get otin sub e2 1 10
436e2 = sub e2 1
437end
438end
439if le e2 s2
440ret otinval 31
441end
442note Goal.
443if not otcopy 0 e1
444ret otinval 31
445end
446v = ocsetgl e1
447if lt v 0
448put otol 0 0
449otpfr 18
450otpfr 28
451otprs v
452otpb 10
453ret 31
454end
455for i ulong 6
456put otg i get ocgv i
457end
458note Report.
459if not otcopy s2 sub e2 s2
460ret otinval 31
461end
462v = ocvline sub e2 s2 4
463if lt v 0
464put otol 0 0
465otpfr 18
466otpfr 29
467otprs v
468otpb 10
469ret 31
470end
471oc = get ocids 1
472put otp 0 oc
473if eq oc 10
474put otp 1 get ocids 2
475put otp 2 ochexv 3 3
476put otp 3 ochexv 8 3
477put otp 4 ochexv 13 3
478put otp 5 ochexv 18 4
479put otp 6 0
480if eq get ocids 2 7
481put otp 6 ochexv 24 4
482end
483else
484put otp 7 get ocids 2
485end
486note Facts.
487fl = otrdfacts
488if lt fl 0
489ret otinval 30
490end
491if not othdrok ulong fl
492ret otinval 30
493end
494if not otfsplit ulong fl
495ret otinval 30
496end
497if not otfrows
498ret otinval 30
499end
500if not othist
501ret otinval 30
502end
503nj = ulong 1
504if eq get otg 0 7
505nj = 2
506end
507note P operands against G.
508if eq oc 10
509same = true
510for i ulong 5
511if ne get otp add i 1 get otg i
512same = false
513end
514end
515if eq nj 2
516if ne get otp 6 get otg 5
517same = false
518end
519end
520if not same
521ret otcontra 32
522end
523end
524note Every facts row against G.
525nr = get otnr 0
526for r ulong nr
527j = otrval r 0
528if or lt j 1 gt j nj
529ret otcontra 33
530end
531sd = get otg 4
532if eq j 2
533sd = get otg 5
534end
535same = otrowok r sd
536if not same
537ret otcontra 32
538end
539end
540if eq oc 10
541note Success needs the last row of every job to be class ok, exit 0.
542for jj ulong nj
543r = otlast add jj 1
544if eq r OTRMAX
545ret otcontra 33
546end
547if ne otrval r 7 1
548ret otcontra 34
549end
550end
551r1 = otlast 1
552if eq nj 1
553otpfr 0
554otrdims
555otpfr 3
556otpdec get otg 4
557otpjob 1 r1
558otpfr 7
559ret 0
560end
561r2 = otlast 2
562otpfr 8
563otrdims
564otpfr 9
565otpdec get otg 4
566otpfr 10
567otpdec get otg 5
568otpjob 1 r1
569otpjob 2 r2
570otpfr 7
571ret 0
572end
573cd = get otp 7
574if eq cd 13
575note Bound: decided before dispatch, so no facts rows and a G dim
576note outside 1..256.
577if gt nr 0
578ret otcontra 37
579end
580adm = true
581for i ulong 3
582d = get otg add i 1
583if or lt d 1 gt d 256
584adm = false
585end
586end
587if adm
588ret otcontra 37
589end
590otpfr 11
591otpdec get otg 1
592otpfr 1
593otpdec get otg 2
594otpfr 1
595otpdec get otg 3
596otpfr 12
597ret 0
598end
599if eq nr 0
600ret otcontra 36
601end
602rl = sub nr 1
603wantc = ulong 2
604if eq oc 12
605wantc = 3
606end
607if ne otrval rl 7 wantc
608ret otcontra 34
609end
610if ne otrval rl 8 cd
611ret otcontra 35
612end
613otpfr 13
614otpdec otrval rl 0
615if eq oc 11
616otpfr 14
617else
618otpfr 15
619end
620otpword cd
621otpfr 16
622otpfr add 6 cd
623otpfr 7
624ret 0
625end