aien-sovereign-core-mv
AienOS host runtime: inference scheduling, paged KV state, the aien CLI and Spark verification tooling. Its inference engine is in alpha testing (DGX Spark GB10); Omega is the implementation destination.
Brought by drakestapleton
aien-sovereign-core-mv / om / qwen-native / model / profile.om
| 1 | note Fixed architectures of the two text checkpoints. All active parameters are bound before first use. |
| 2 | global qcfg ulong 12 |
| 3 | global qrole uint 102400 |
| 4 | global qscale uint 65536 |
| 5 | global qbound uchar 65536 |
| 6 | text qlayerprefix "model.language_model.layers." |
| 7 | text qexpertprefix "mlp.experts." |
| 8 | text qsep "." |
| 9 | text qscalesuffix "_scale_inv" |
| 10 | text qembed "model.language_model.embed_tokens.weight" |
| 11 | text qfinal "model.language_model.norm.weight" |
| 12 | text qlm "lm_head.weight" |
| 13 | fn qappend buf edit uchar * pos ulong frag view uchar * to ulong |
| 14 | for i ulong len frag |
| 15 | put buf add pos i get frag i |
| 16 | end |
| 17 | ret add pos len frag |
| 18 | end |
| 19 | |
| 20 | fn qdecimal buf edit uchar * pos ulong x ulong to ulong |
| 21 | p = pos |
| 22 | if ge x 100 |
| 23 | put buf p uchar add 48 div x 100 |
| 24 | p = add p 1 |
| 25 | end |
| 26 | if ge x 10 |
| 27 | put buf p uchar add 48 rem div x 10 10 |
| 28 | p = add p 1 |
| 29 | end |
| 30 | put buf p uchar add 48 rem x 10 |
| 31 | ret add p 1 |
| 32 | end |
| 33 | |
| 34 | fn qresolve frag view uchar * to ulong |
| 35 | buf = new uchar 256 0 |
| 36 | p = ulong 0 |
| 37 | l = get qcfg 7 |
| 38 | if lt l 64 |
| 39 | p = qappend buf p qlayerprefix |
| 40 | p = qdecimal buf p l |
| 41 | p = qappend buf p qsep |
| 42 | e = get qcfg 8 |
| 43 | if gt e 0 |
| 44 | p = qappend buf p qexpertprefix |
| 45 | p = qdecimal buf p sub e 1 |
| 46 | p = qappend buf p qsep |
| 47 | end |
| 48 | end |
| 49 | p = qappend buf p frag |
| 50 | ret qwid buf p |
| 51 | end |
| 52 | |
| 53 | fn qbind slot ulong frag view uchar * dtype ulong to ulong |
| 54 | id = qresolve frag |
| 55 | if or ne ulong get qwdtype id dtype ne get qbound id 0 |
| 56 | qwfail 40 |
| 57 | end |
| 58 | put qbound id 1 |
| 59 | put qrole add get qcfg 9 slot uint id |
| 60 | ret id |
| 61 | end |
| 62 | |
| 63 | fn qrank2 id ulong rows ulong cols ulong to void |
| 64 | if ne get qwrank id 2 |
| 65 | qwfail 41 |
| 66 | end |
| 67 | base = mul id 4 |
| 68 | if or ne get qwshape base rows ne get qwshape add base 1 cols |
| 69 | qwfail 41 |
| 70 | end |
| 71 | end |
| 72 | |
| 73 | fn qlinkscale id ulong rows ulong cols ulong to void |
| 74 | buf = new uchar 256 0 |
| 75 | p = ulong get qwnpos id |
| 76 | n = ulong get qwnlen id |
| 77 | for j ulong n |
| 78 | put buf j get qwname add p j |
| 79 | end |
| 80 | n = qappend buf n qscalesuffix |
| 81 | s = qwid buf n |
| 82 | if or ne get qwdtype s 2 ne get qbound s 0 |
| 83 | qwfail 42 |
| 84 | end |
| 85 | put qbound s 1 |
| 86 | qrank2 s div add rows 127 128 div add cols 127 128 |
| 87 | put qscale id uint s |
| 88 | end |
| 89 | |
| 90 | fn qmatrix slot ulong frag view uchar * rows ulong cols ulong dtype ulong to void |
| 91 | id = qbind slot frag dtype |
| 92 | qrank2 id rows cols |
| 93 | if eq dtype 1 |
| 94 | qlinkscale id rows cols |
| 95 | end |
| 96 | end |
| 97 | |
| 98 | fn qvector slot ulong frag view uchar * size ulong to void |
| 99 | id = qbind slot frag 2 |
| 100 | if or ne get qwrank id 1 ne get qwshape mul id 4 size |
| 101 | qwfail 43 |
| 102 | end |
| 103 | end |
| 104 | text qp0 "input_layernorm.weight" |
| 105 | text qp1 "post_attention_layernorm.weight" |
| 106 | fn qnorms to void |
| 107 | qvector 0 qp0 get qcfg 1 |
| 108 | qvector 1 qp1 get qcfg 1 |
| 109 | end |
| 110 | text qp2 "linear_attn.A_log" |
| 111 | text qp3 "linear_attn.dt_bias" |
| 112 | text qp4 "linear_attn.in_proj_a.weight" |
| 113 | text qp5 "linear_attn.in_proj_b.weight" |
| 114 | text qp6 "linear_attn.in_proj_qkv.weight" |
| 115 | text qp7 "linear_attn.in_proj_z.weight" |
| 116 | text qp8 "linear_attn.norm.weight" |
| 117 | text qp9 "linear_attn.out_proj.weight" |
| 118 | fn qgdnweights to void |
| 119 | qvector 2 qp2 div get qcfg 3 128 |
| 120 | qvector 3 qp3 div get qcfg 3 128 |
| 121 | qmatrix 4 qp4 div get qcfg 3 128 get qcfg 1 2 |
| 122 | qmatrix 5 qp5 div get qcfg 3 128 get qcfg 1 2 |
| 123 | qmatrix 6 qp6 add mul 2 get qcfg 2 get qcfg 3 get qcfg 1 1 |
| 124 | qmatrix 7 qp7 get qcfg 3 get qcfg 1 1 |
| 125 | qvector 8 qp8 128 |
| 126 | qmatrix 9 qp9 get qcfg 1 get qcfg 3 1 |
| 127 | end |
| 128 | text qp11 "self_attn.q_norm.weight" |
| 129 | text qp12 "self_attn.k_norm.weight" |
| 130 | text qp13 "self_attn.q_proj.weight" |
| 131 | text qp14 "self_attn.k_proj.weight" |
| 132 | text qp15 "self_attn.v_proj.weight" |
| 133 | text qp16 "self_attn.o_proj.weight" |
| 134 | fn qattnweights to void |
| 135 | qvector 11 qp11 256 |
| 136 | qvector 12 qp12 256 |
| 137 | qmatrix 13 qp13 mul 2 get qcfg 4 get qcfg 1 1 |
| 138 | qmatrix 14 qp14 get qcfg 5 get qcfg 1 1 |
| 139 | qmatrix 15 qp15 get qcfg 5 get qcfg 1 1 |
| 140 | qmatrix 16 qp16 get qcfg 1 get qcfg 4 1 |
| 141 | end |
| 142 | text qp17 "mlp.gate_proj.weight" |
| 143 | text qp18 "mlp.up_proj.weight" |
| 144 | text qp19 "mlp.down_proj.weight" |
| 145 | fn qdenseweights to void |
| 146 | qmatrix 17 qp17 get qcfg 6 get qcfg 1 1 |
| 147 | qmatrix 18 qp18 get qcfg 6 get qcfg 1 1 |
| 148 | qmatrix 19 qp19 get qcfg 1 get qcfg 6 1 |
| 149 | end |
| 150 | text qp20 "mlp.gate.weight" |
| 151 | text qp21 "mlp.shared_expert_gate.weight" |
| 152 | text qp22 "mlp.shared_expert.gate_proj.weight" |
| 153 | text qp23 "mlp.shared_expert.up_proj.weight" |
| 154 | text qp24 "mlp.shared_expert.down_proj.weight" |
| 155 | fn qrouterweights to void |
| 156 | qmatrix 20 qp20 256 get qcfg 1 2 |
| 157 | qmatrix 21 qp21 1 get qcfg 1 2 |
| 158 | qmatrix 22 qp22 512 get qcfg 1 1 |
| 159 | qmatrix 23 qp23 512 get qcfg 1 1 |
| 160 | qmatrix 24 qp24 get qcfg 1 512 1 |
| 161 | end |
| 162 | |
| 163 | text qp10 "linear_attn.conv1d.weight" |
| 164 | text qeg "gate_proj.weight" |
| 165 | text qeu "up_proj.weight" |
| 166 | text qed "down_proj.weight" |
| 167 | fn qconvweight to void |
| 168 | id = qbind 10 qp10 2 |
| 169 | a = mul id 4 |
| 170 | width = add mul 2 get qcfg 2 get qcfg 3 |
| 171 | if or ne get qwrank id 3 ne get qwshape a width |
| 172 | qwfail 44 |
| 173 | end |
| 174 | if or ne get qwshape add a 1 1 ne get qwshape add a 2 4 |
| 175 | qwfail 44 |
| 176 | end |
| 177 | end |
| 178 | |
| 179 | fn qlayerweights layer ulong to void |
| 180 | put qcfg 7 layer |
| 181 | put qcfg 8 0 |
| 182 | put qcfg 9 mul layer 1600 |
| 183 | qnorms |
| 184 | if eq rem layer 4 3 |
| 185 | qattnweights |
| 186 | else |
| 187 | qconvweight |
| 188 | qgdnweights |
| 189 | end |
| 190 | if eq get qcfg 0 64 |
| 191 | qdenseweights |
| 192 | ret |
| 193 | end |
| 194 | qrouterweights |
| 195 | for e ulong 256 |
| 196 | put qcfg 8 add e 1 |
| 197 | slot = add 32 mul e 3 |
| 198 | qmatrix slot qeg 512 2048 1 |
| 199 | qmatrix add slot 1 qeu 512 2048 1 |
| 200 | qmatrix add slot 2 qed 2048 512 1 |
| 201 | end |
| 202 | end |
| 203 | |
| 204 | fn qprofile layers ulong to void |
| 205 | put qcfg 0 layers |
| 206 | if eq layers 64 |
| 207 | put qcfg 1 5120 |
| 208 | put qcfg 2 2048 |
| 209 | put qcfg 3 6144 |
| 210 | put qcfg 4 6144 |
| 211 | put qcfg 5 1024 |
| 212 | put qcfg 6 17408 |
| 213 | else |
| 214 | if ne layers 40 |
| 215 | qwfail 45 |
| 216 | end |
| 217 | put qcfg 1 2048 |
| 218 | put qcfg 2 2048 |
| 219 | put qcfg 3 4096 |
| 220 | put qcfg 4 4096 |
| 221 | put qcfg 5 512 |
| 222 | put qcfg 6 512 |
| 223 | end |
| 224 | for l ulong layers |
| 225 | qlayerweights l |
| 226 | end |
| 227 | put qcfg 7 64 |
| 228 | put qcfg 8 0 |
| 229 | put qcfg 9 0 |
| 230 | note Extra roles in layer zero are separate from the layer and expert slots. |
| 231 | qmatrix 1020 qembed 248320 get qcfg 1 2 |
| 232 | qmatrix 1021 qlm 248320 get qcfg 1 2 |
| 233 | qvector 1022 qfinal get qcfg 1 |
| 234 | for i ulong get qwstate 1 |
| 235 | if eq get qbound add i 1 0 |
| 236 | qwfail 46 |
| 237 | end |
| 238 | end |
| 239 | end |