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 / qwen-native / model / graph.om
| 1 | note One text sequence on the frozen 27B dense or 35B routed model. Device projections share a resident weight mapping per layer. |
| 2 | global qrun ulong 6 |
| 3 | fn qwroleof slot ulong to ulong |
| 4 | ret ulong get qrole add mul get qrun 1 1600 slot |
| 5 | end |
| 6 | |
| 7 | fn qinvnorm x view f32 * h ulong to f64 |
| 8 | s = 0.0f64 |
| 9 | for j ulong h |
| 10 | v = f64 get x j |
| 11 | s = add s mul v v |
| 12 | end |
| 13 | ret div 1.0f64 fsqrt add div s f64 h 0.000001f64 |
| 14 | end |
| 15 | |
| 16 | fn qnorm id ulong x view f32 * y edit f32 * to void |
| 17 | h = get qcfg 1 |
| 18 | w = new f32 5120 0.0f32 |
| 19 | qreadrow id 0 w 0 h |
| 20 | inv = qinvnorm x h |
| 21 | for j ulong h |
| 22 | a = mul f64 get x j inv |
| 23 | gain = add 1.0f64 f64 get w j |
| 24 | put y j f32 mul a gain |
| 25 | end |
| 26 | end |
| 27 | |
| 28 | fn qresid x edit f32 * delta view f32 * to void |
| 29 | for j ulong get qcfg 1 |
| 30 | put x j add get x j get delta j |
| 31 | end |
| 32 | end |
| 33 | |
| 34 | fn qab x view f32 * pack edit f32 * start ulong to void |
| 35 | a = new f32 48 0.0f32 |
| 36 | b = new f32 48 0.0f32 |
| 37 | qproject qwroleof 4 x a 0 |
| 38 | qproject qwroleof 5 x b 0 |
| 39 | heads = div get qcfg 3 128 |
| 40 | for j ulong heads |
| 41 | p = add start mul j 2 |
| 42 | put pack p get a j |
| 43 | put pack add p 1 get b j |
| 44 | end |
| 45 | end |
| 46 | |
| 47 | fn qdweights w edit f32 * to void |
| 48 | qreadrow qwroleof 10 0 w 0 get qwcount qwroleof 10 |
| 49 | heads = div get qcfg 3 128 |
| 50 | qreadrow qwroleof 2 0 w 40960 heads |
| 51 | qreadrow qwroleof 3 0 w 41008 heads |
| 52 | qreadrow qwroleof 8 0 w 41056 128 |
| 53 | end |
| 54 | |
| 55 | fn qdelta x view f32 * y edit f32 * to void |
| 56 | p = new f32 16480 0.0f32 |
| 57 | w = new f32 41184 0.0f32 |
| 58 | z = new f32 6144 0.0f32 |
| 59 | n = add 4096 get qcfg 3 |
| 60 | qproject qwroleof 6 x p 0 |
| 61 | qproject qwroleof 7 x p n |
| 62 | qab x p add n get qcfg 3 |
| 63 | qdweights w |
| 64 | qwen_delta_step get qrun 0 get qrun 1 get qrun 2 p w z |
| 65 | qproject qwroleof 9 z y 0 |
| 66 | end |
| 67 | |
| 68 | fn qattention x view f32 * y edit f32 * to void |
| 69 | p = new f32 14336 0.0f32 |
| 70 | w = new f32 512 0.0f32 |
| 71 | z = new f32 6144 0.0f32 |
| 72 | n = mul get qcfg 4 2 |
| 73 | qproject qwroleof 13 x p 0 |
| 74 | qproject qwroleof 14 x p n |
| 75 | qproject qwroleof 15 x p add n get qcfg 5 |
| 76 | qreadrow qwroleof 11 0 w 0 256 |
| 77 | qreadrow qwroleof 12 0 w 256 256 |
| 78 | qwen_attention_step get qrun 0 get qrun 1 get qrun 2 p w z |
| 79 | qproject qwroleof 16 z y 0 |
| 80 | end |
| 81 | |
| 82 | fn qswiglu a edit f32 * b view f32 * n ulong to void |
| 83 | for j ulong n |
| 84 | v = get a j |
| 85 | gate = mul v f32 qb_sig f64 v |
| 86 | put a j mul gate get b j |
| 87 | end |
| 88 | end |
| 89 | |
| 90 | fn qfeed slot ulong x view f32 * y edit f32 * to void |
| 91 | g = new f32 17408 0.0f32 |
| 92 | u = new f32 17408 0.0f32 |
| 93 | qproject qwroleof slot x g 0 |
| 94 | qproject qwroleof add slot 1 x u 0 |
| 95 | qswiglu g u get qcfg 6 |
| 96 | qproject qwroleof add slot 2 g y 0 |
| 97 | end |
| 98 | |
| 99 | global qtop uint 8 |
| 100 | global qprob f32 8 |
| 101 | fn qroute scores view f32 * to void |
| 102 | den = 0.0f64 |
| 103 | top = 0.0f64 |
| 104 | for rank ulong 8 |
| 105 | best = ulong 256 |
| 106 | for e ulong 256 |
| 107 | used = false |
| 108 | for j ulong rank |
| 109 | if eq ulong get qtop j e |
| 110 | used = true |
| 111 | end |
| 112 | end |
| 113 | if not used |
| 114 | if eq best 256 |
| 115 | best = e |
| 116 | else |
| 117 | if gt get scores e get scores best |
| 118 | best = e |
| 119 | end |
| 120 | end |
| 121 | end |
| 122 | end |
| 123 | put qtop rank uint best |
| 124 | if eq rank 0 |
| 125 | top = f64 get scores best |
| 126 | end |
| 127 | p = qb_exp sub f64 get scores best top |
| 128 | den = add den p |
| 129 | put qprob rank f32 p |
| 130 | end |
| 131 | for rank ulong 8 |
| 132 | put qprob rank f32 div f64 get qprob rank den |
| 133 | end |
| 134 | end |
| 135 | |
| 136 | fn qaddexpert y edit f32 * e view f32 * alpha f32 to void |
| 137 | for j ulong get qcfg 1 |
| 138 | put y j add get y j mul alpha get e j |
| 139 | end |
| 140 | end |
| 141 | |
| 142 | fn qmoe x view f32 * y edit f32 * to void |
| 143 | router = new f32 256 0.0f32 |
| 144 | gate = new f32 1 0.0f32 |
| 145 | expert = new f32 2048 0.0f32 |
| 146 | qproject qwroleof 20 x router 0 |
| 147 | qroute router |
| 148 | qproject qwroleof 21 x gate 0 |
| 149 | qfeed 22 x expert |
| 150 | for j ulong 2048 |
| 151 | put y j 0.0f32 |
| 152 | end |
| 153 | qaddexpert y expert f32 qb_sig f64 get gate 0 |
| 154 | for j ulong 8 |
| 155 | slot = add 32 mul 3 ulong get qtop j |
| 156 | qfeed slot x expert |
| 157 | qaddexpert y expert get qprob j |
| 158 | end |
| 159 | end |
| 160 | |
| 161 | fn qlayer x edit f32 * to void |
| 162 | xn = new f32 5120 0.0f32 |
| 163 | dy = new f32 5120 0.0f32 |
| 164 | qnorm qwroleof 0 x xn |
| 165 | if eq rem get qrun 1 4 3 |
| 166 | qattention xn dy |
| 167 | else |
| 168 | qdelta xn dy |
| 169 | end |
| 170 | qresid x dy |
| 171 | qnorm qwroleof 1 x xn |
| 172 | if eq get qrun 0 27 |
| 173 | qfeed 17 xn dy |
| 174 | else |
| 175 | qmoe xn dy |
| 176 | end |
| 177 | qresid x dy |
| 178 | end |
| 179 | |
| 180 | fn qargmax scores view f32 * n ulong to ulong |
| 181 | best = ulong 0 |
| 182 | for j ulong n |
| 183 | b = bitcast uint get scores j |
| 184 | if eq and b 2139095040 2139095040 |
| 185 | qwfail 54 |
| 186 | end |
| 187 | if gt get scores j get scores best |
| 188 | best = j |
| 189 | end |
| 190 | end |
| 191 | ret best |
| 192 | end |
| 193 | |
| 194 | fn qtoken tok ulong pos ulong logits bool to ulong |
| 195 | if or ge tok 248320 ge pos 8192 |
| 196 | qwfail 55 |
| 197 | end |
| 198 | x = new f32 5120 0.0f32 |
| 199 | xn = new f32 5120 0.0f32 |
| 200 | s = new f32 248320 0.0f32 |
| 201 | qdiskrecheck |
| 202 | put qrun 2 pos |
| 203 | qreadrow ulong get qrole 1020 mul tok get qcfg 1 x 0 get qcfg 1 |
| 204 | for l ulong get qcfg 0 |
| 205 | put qrun 1 l |
| 206 | qlayer x |
| 207 | end |
| 208 | if not logits |
| 209 | ret 0 |
| 210 | end |
| 211 | qnorm ulong get qrole 1022 x xn |
| 212 | qproject ulong get qrole 1021 xn s 0 |
| 213 | qdiskrecheck |
| 214 | ret qargmax s 248320 |
| 215 | end |