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 / om / gpu / engine / config.om

581 lines · 12635 bytes Raw Blame History
1note SPDX-License-Identifier: AGPL-3.0-only
2note om/gpu/engine/config.om: Universal Pure Seeded-OM-2 HuggingFace config.json Parser & ModelSpec.
3note Automatically detects architecture, dimensions, layer types (Full-Attention vs Gated DeltaNet),
4note MoE vs Dense, RoPE parameters, RMSNorm convention ((1+w) vs w), QK-Norm, and quantization
5note from any standard HuggingFace config.json (Llama 3, Qwen 2.5/3/3.5/3.6/3.8/4, Gemma 2/3,
6note Mistral, DeepSeek, Phi, or custom checkpoints).
7
8note ModelSpec field indices (global engSpec ulong 64)
9const MS_ARCH ulong 0
10const MS_H ulong 1
11const MS_I ulong 2
12const MS_MOE_I ulong 3
13const MS_LAYERS ulong 4
14const MS_NQ ulong 5
15const MS_NKV ulong 6
16const MS_HD ulong 7
17const MS_VOCAB ulong 8
18const MS_NEXP ulong 9
19const MS_TOPK ulong 10
20const MS_FA_INT ulong 11
21const MS_GDN_NK ulong 12
22const MS_GDN_NV ulong 13
23const MS_GDN_HD ulong 14
24const MS_ROPE_DIMS ulong 15
25const MS_ROPE_THETA ulong 16
26const MS_NORM_ADD1 ulong 17
27const MS_QK_NORM ulong 18
28const MS_ATTN_GATE ulong 19
29const MS_TIE_EMB ulong 20
30const MS_QUANT ulong 21
31const MS_MAX_CTX ulong 22
32const MS_N_FA ulong 23
33const MS_N_GDN ulong 24
34const MS_SH_EXP ulong 25
35const MS_SH_I ulong 26
36const MS_HAS_TEXT_PREFIX ulong 27
37const MS_CONV_K ulong 28
38const MS_EPS_E6 ulong 29
39const MS_HC_COUNT ulong 30
40const MS_HC_LOWRANK ulong 31
41const MS_GDN_SIGMOID ulong 32
42const MS_PLE_LAYER ulong 33
43const MS_PLE_DIM ulong 34
44const MS_PLE_NGRAM ulong 35
45const MS_PLE_HPN ulong 36
46const MS_PLE_CONV_K ulong 37
47const MS_PLE_SPLITS ulong 38
48const MS_IDX_BUDGET ulong 39
49const MS_IDX_COMP ulong 40
50const MS_IDX_NH ulong 41
51const MS_IDX_NKV ulong 42
52const MS_IDX_HD ulong 43
53const MS_EOS_ID ulong 44
54
55global engSpec ulong 64
56global engLayerKind uchar 256
57global engCfgBuf uchar 262144
58global engCfgLen ulong 1
59global engModelType uchar 64
60global engModelTypeLen ulong 1
61global engModelDir uchar 512
62global engModelDirLen ulong 1
63global engPathTmp uchar 1024
64
65text engCfgSuf "/config.json"
66text engKTextCfg "\"text_config\""
67text engKModelType "\"model_type\""
68text engKHid "\"hidden_size\""
69text engKInter "\"intermediate_size\""
70text engKMoeInter "\"moe_intermediate_size\""
71text engKShInter "\"shared_expert_intermediate_size\""
72text engKLayers "\"num_hidden_layers\""
73text engKNq "\"num_attention_heads\""
74text engKNkv "\"num_key_value_heads\""
75text engKHd "\"head_dim\""
76text engKVocab "\"vocab_size\""
77text engKNexp "\"num_experts\""
78text engKNRouted "\"n_routed_experts\""
79text engKTopk "\"num_experts_per_tok\""
80text engKFaInt "\"full_attention_interval\""
81text engKGdnNk "\"linear_num_key_heads\""
82text engKGdnNv "\"linear_num_value_heads\""
83text engKGdnHd "\"linear_key_head_dim\""
84text engKConvK "\"linear_conv_kernel_dim\""
85text engKPartRot "\"partial_rotary_factor\""
86text engKRopeTheta "\"rope_theta\""
87text engKTieEmb "\"tie_word_embeddings\""
88text engKAttnGate "\"attn_output_gate\""
89text engKQuantMeth "\"quant_method\""
90text engKEps "\"rms_norm_eps\""
91text engKHcCount "\"hc_count\""
92text engKHcLowrank "\"hc_lowrank\""
93text engKOutGate "\"output_gate_type\""
94text engKPleLayers "\"ple_layer_ids\""
95text engKPleDim "\"ple_embed_dim\""
96text engKNgramSz "\"ngram_size\""
97text engKHpn "\"heads_per_ngram\""
98text engKPleConvK "\"ple_conv_kernel_size\""
99text engKPleSplits "\"split_ngram_parts\""
100text engKIdxBudget "\"indexer_budget\""
101text engKIdxComp "\"indexer_compress_ratio\""
102text engKIdxNh "\"indexer_n_heads\""
103text engKIdxNkv "\"indexer_kv_heads\""
104text engKIdxHd "\"indexer_head_dim\""
105text engKEosId "\"eos_token_id\""
106text engSubSigmoid "sigmoid"
107
108fn engJoinPath suf view uchar * to ulong
109dlen = get engModelDirLen 0
110for i ulong dlen bound 512
111put engPathTmp i get engModelDir i
112end
113p = dlen
114for i ulong len suf bound 256
115put engPathTmp p get suf i
116p = add p 1
117end
118put engPathTmp p 0
119ret p
120end
121
122fn engMatchCfg pos ulong pat view uchar * to bool
123clen = get engCfgLen 0
124plen = len pat
125if gt add pos plen clen
126ret false
127end
128for i ulong plen bound 64
129if ne get engCfgBuf add pos i get pat i
130ret false
131end
132end
133ret true
134end
135
136fn engFindKey start ulong endPos ulong key view uchar * to ulong
137p = start
138klen = len key
139while lt add p klen endPos bound 262144
140if engMatchCfg p key
141j = add p klen
142while and lt j endPos ne get engCfgBuf j 58 bound 64
143j = add j 1
144end
145if lt add j 1 endPos
146j = add j 1
147while lt j endPos bound 64
148c = get engCfgBuf j
149if eq c 32
150j = add j 1
151else
152if eq c 9
153j = add j 1
154else
155if eq c 10
156j = add j 1
157else
158if eq c 13
159j = add j 1
160else
161break
162end
163end
164end
165end
166end
167ret j
168end
169end
170p = add p 1
171end
172ret 0
173end
174
175fn engParseU64At pos ulong to ulong
176clen = get engCfgLen 0
177v = ulong 0
178p = pos
179while lt p clen bound 32
180c = get engCfgBuf p
181if and ge c 48 le c 57
182v = add mul v 10 ulong sub c 48
183p = add p 1
184else
185break
186end
187end
188ret v
189end
190
191fn engParseBoolAt pos ulong to ulong
192clen = get engCfgLen 0
193if lt pos clen
194if eq get engCfgBuf pos 116
195ret 1
196end
197end
198ret 0
199end
200
201fn engParseFrac100At pos ulong to ulong
202note Parses a decimal like 0.25 -> 25, 1.0 -> 100, 0.5 -> 50
203clen = get engCfgLen 0
204if ge pos clen
205ret 100
206end
207whole = engParseU64At pos
208p = pos
209while and lt p clen and ge get engCfgBuf p 48 le get engCfgBuf p 57 bound 16
210p = add p 1
211end
212frac = ulong 0
213if and lt p clen eq get engCfgBuf p 46
214p = add p 1
215if and lt p clen and ge get engCfgBuf p 48 le get engCfgBuf p 57
216frac = mul ulong sub get engCfgBuf p 48 10
217p = add p 1
218if and lt p clen and ge get engCfgBuf p 48 le get engCfgBuf p 57
219frac = add frac ulong sub get engCfgBuf p 48
220end
221end
222end
223ret add mul whole 100 frac
224end
225
226fn engReadStrAt pos ulong dst edit uchar 64 to ulong
227clen = get engCfgLen 0
228if or ge pos clen ne get engCfgBuf pos 34
229ret 0
230end
231p = add pos 1
232n = ulong 0
233while and lt p clen lt n 62 bound 64
234c = get engCfgBuf p
235if eq c 34
236break
237end
238put dst n c
239n = add n 1
240p = add p 1
241end
242put dst n 0
243ret n
244end
245
246fn engStrHas buf view uchar 64 blen ulong pat view uchar * to bool
247slen = len pat
248if gt slen blen
249ret false
250end
251for i ulong add sub blen slen 1 bound 64
252ok = true
253for j ulong slen bound 32
254if ne get buf add i j get pat j
255ok = false
256break
257end
258end
259if ok
260ret true
261end
262end
263ret false
264end
265
266text engSubQwen35 "qwen3_5"
267text engSubQwen4 "qwen4"
268text engSubMoe "moe"
269text engSubDeepseek "deepseek"
270text engSubGemma "gemma"
271text engSubQwen3 "qwen3"
272text engSubFp8 "fp8"
273text engSubModelopt "modelopt"
274
275fn engSkipColonWs j0 ulong endPos ulong to ulong
276j = j0
277while lt j endPos bound 64
278if eq get engCfgBuf j 58
279break
280end
281j = add j 1
282end
283if ge add j 1 endPos
284ret 0
285end
286j = add j 1
287while lt j endPos bound 64
288ch = get engCfgBuf j
289if eq ch 32
290j = add j 1
291else
292if eq ch 9
293j = add j 1
294else
295if eq ch 10
296j = add j 1
297else
298if eq ch 13
299j = add j 1
300else
301break
302end
303end
304end
305end
306end
307ret j
308end
309
310fn engFindKeyTop start ulong endPos ulong key view uchar * to ulong
311note Finds key at top level of the JSON object starting at start (depth == 1), skipping nested {...} like "mtp"!
312p = start
313klen = len key
314depth = ulong 0
315inStr = false
316while lt add p klen endPos bound 262144
317c = get engCfgBuf p
318if eq c 34
319if not inStr
320if eq depth 1
321if engMatchCfg p key
322ret engSkipColonWs add p klen endPos
323end
324end
325end
326inStr = not inStr
327else
328if not inStr
329if eq c 123
330depth = add depth 1
331else
332if eq c 125
333if gt depth 0
334depth = sub depth 1
335end
336if eq depth 0
337ret 0
338end
339end
340end
341end
342end
343p = add p 1
344end
345ret 0
346end
347
348fn engSetIfKey start ulong tot ulong key view uchar * slot ulong to void
349p = engFindKeyTop start tot key
350if eq p 0
351p = engFindKey start tot key
352end
353if gt p 0
354put engSpec slot engParseU64At p
355end
356end
357
358fn engDetectArch tot ulong tStart ulong to void
359mtPos = engFindKey tStart tot engKModelType
360if eq mtPos 0
361mtPos = engFindKey 0 tot engKModelType
362end
363mtLocal = new uchar 64 0
364mtLen = ulong 0
365if gt mtPos 0
366mtLen = engReadStrAt mtPos mtLocal
367for i ulong mtLen bound 64
368put engModelType i get mtLocal i
369end
370end
371put engModelTypeLen 0 mtLen
372if engStrHas mtLocal mtLen engSubQwen35
373put engSpec MS_NORM_ADD1 1
374put engSpec MS_QK_NORM 1
375put engSpec MS_ATTN_GATE 1
376if or gt get engSpec MS_NEXP 0 engStrHas mtLocal mtLen engSubMoe
377put engSpec MS_ARCH 2
378put engSpec MS_SH_EXP 1
379if eq get engSpec MS_SH_I 0
380put engSpec MS_SH_I get engSpec MS_MOE_I
381end
382else
383put engSpec MS_ARCH 1
384end
385else
386if engStrHas mtLocal mtLen engSubQwen4
387put engSpec MS_ARCH 3
388put engSpec MS_NORM_ADD1 1
389put engSpec MS_QK_NORM 1
390put engSpec MS_ATTN_GATE 1
391put engSpec MS_SH_EXP 1
392else
393if engStrHas mtLocal mtLen engSubDeepseek
394put engSpec MS_ARCH 4
395else
396if engStrHas mtLocal mtLen engSubGemma
397put engSpec MS_ARCH 5
398put engSpec MS_NORM_ADD1 1
399put engSpec MS_QK_NORM 1
400else
401put engSpec MS_ARCH 0
402if engStrHas mtLocal mtLen engSubQwen3
403put engSpec MS_QK_NORM 1
404end
405end
406end
407end
408end
409qTmp = new uchar 64 0
410qp = engFindKey 0 tot engKQuantMeth
411if gt qp 0
412ql = engReadStrAt qp qTmp
413if engStrHas qTmp ql engSubFp8
414put engSpec MS_QUANT 1
415else
416if engStrHas qTmp ql engSubModelopt
417put engSpec MS_QUANT 2
418end
419end
420end
421end
422
423fn engComputeLayerKinds to void
424nL = get engSpec MS_LAYERS
425faInt = get engSpec MS_FA_INT
426nFa = ulong 0
427nGdn = ulong 0
428for L ulong nL bound 256
429if eq faInt 1
430put engLayerKind L 0
431nFa = add nFa 1
432else
433if eq rem add L 1 faInt 0
434put engLayerKind L 0
435nFa = add nFa 1
436else
437put engLayerKind L 1
438nGdn = add nGdn 1
439end
440end
441end
442put engSpec MS_N_FA nFa
443put engSpec MS_N_GDN nGdn
444end
445
446fn engParseFirstArrU64At pos ulong to ulong
447clen = get engCfgLen 0
448p = pos
449while lt p clen bound 64
450c = get engCfgBuf p
451if and ge c 48 le c 57
452ret engParseU64At p
453end
454if eq c 93
455ret 0
456end
457p = add p 1
458end
459ret 0
460end
461
462fn engLoadConfig to bool
463ogTmp = new uchar 64 0
464plen = engJoinPath engCfgSuf
465fd = int fopen engPathTmp 0 plen 0 0
466if lt fd 0
467ret false
468end
469tot = ulong 0
470while lt tot 262100 bound 64
471got = pread fd engCfgBuf tot sub 262100 tot long tot
472if le got 0
473break
474end
475tot = add tot ulong got
476end
477c0 = fclose fd
478if eq tot 0
479ret false
480end
481put engCfgLen 0 tot
482for i ulong 64
483put engSpec i 0
484end
485put engSpec MS_FA_INT 1
486put engSpec MS_ROPE_THETA 1000000
487put engSpec MS_CONV_K 4
488put engSpec MS_EPS_E6 1
489put engSpec MS_MAX_CTX 131072
490put engSpec MS_HC_COUNT 1
491put engSpec MS_EOS_ID 248044
492tStart = ulong 0
493tcPos = engFindKey 0 tot engKTextCfg
494if gt tcPos 0
495tStart = tcPos
496put engSpec MS_HAS_TEXT_PREFIX 1
497end
498engSetIfKey tStart tot engKHid MS_H
499engSetIfKey tStart tot engKInter MS_I
500engSetIfKey tStart tot engKMoeInter MS_MOE_I
501engSetIfKey tStart tot engKShInter MS_SH_I
502if gt get engSpec MS_SH_I 0
503put engSpec MS_SH_EXP 1
504end
505engSetIfKey tStart tot engKLayers MS_LAYERS
506engSetIfKey tStart tot engKNq MS_NQ
507engSetIfKey tStart tot engKNkv MS_NKV
508engSetIfKey tStart tot engKHd MS_HD
509if and eq get engSpec MS_HD 0 gt get engSpec MS_NQ 0
510put engSpec MS_HD div get engSpec MS_H get engSpec MS_NQ
511end
512if eq get engSpec MS_NKV 0
513put engSpec MS_NKV get engSpec MS_NQ
514end
515engSetIfKey tStart tot engKVocab MS_VOCAB
516engSetIfKey tStart tot engKNexp MS_NEXP
517if eq get engSpec MS_NEXP 0
518engSetIfKey tStart tot engKNRouted MS_NEXP
519end
520engSetIfKey tStart tot engKTopk MS_TOPK
521engSetIfKey tStart tot engKFaInt MS_FA_INT
522if eq get engSpec MS_FA_INT 0
523put engSpec MS_FA_INT 1
524end
525engSetIfKey tStart tot engKGdnNk MS_GDN_NK
526engSetIfKey tStart tot engKGdnNv MS_GDN_NV
527engSetIfKey tStart tot engKGdnHd MS_GDN_HD
528engSetIfKey tStart tot engKConvK MS_CONV_K
529engSetIfKey tStart tot engKRopeTheta MS_ROPE_THETA
530engSetIfKey tStart tot engKHcCount MS_HC_COUNT
531if eq get engSpec MS_HC_COUNT 0
532put engSpec MS_HC_COUNT 1
533end
534engSetIfKey tStart tot engKHcLowrank MS_HC_LOWRANK
535engSetIfKey tStart tot engKPleDim MS_PLE_DIM
536engSetIfKey tStart tot engKNgramSz MS_PLE_NGRAM
537engSetIfKey tStart tot engKHpn MS_PLE_HPN
538engSetIfKey tStart tot engKPleConvK MS_PLE_CONV_K
539engSetIfKey tStart tot engKPleSplits MS_PLE_SPLITS
540engSetIfKey tStart tot engKIdxBudget MS_IDX_BUDGET
541engSetIfKey tStart tot engKIdxComp MS_IDX_COMP
542engSetIfKey tStart tot engKIdxNh MS_IDX_NH
543engSetIfKey tStart tot engKIdxNkv MS_IDX_NKV
544engSetIfKey tStart tot engKIdxHd MS_IDX_HD
545p = engFindKey tStart tot engKEosId
546if gt p 0
547if eq get engCfgBuf p 91
548put engSpec MS_EOS_ID engParseFirstArrU64At p
549else
550put engSpec MS_EOS_ID engParseU64At p
551end
552end
553p = engFindKey tStart tot engKPleLayers
554if gt p 0
555put engSpec MS_PLE_LAYER engParseFirstArrU64At p
556end
557p = engFindKey tStart tot engKOutGate
558if gt p 0
559ogl = engReadStrAt p ogTmp
560if engStrHas ogTmp ogl engSubSigmoid
561put engSpec MS_GDN_SIGMOID 1
562end
563end
564p = engFindKey tStart tot engKTieEmb
565if gt p 0
566put engSpec MS_TIE_EMB engParseBoolAt p
567end
568p = engFindKey tStart tot engKAttnGate
569if gt p 0
570put engSpec MS_ATTN_GATE engParseBoolAt p
571end
572rotPct = ulong 100
573p = engFindKey tStart tot engKPartRot
574if gt p 0
575rotPct = engParseFrac100At p
576end
577put engSpec MS_ROPE_DIMS div mul get engSpec MS_HD rotPct 100
578engDetectArch tot tStart
579engComputeLayerKinds
580ret gt get engSpec MS_H 0
581end