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 / om / gpu / dsv41 / decoder / layer-map.om
| 1 | note SPDX-License-Identifier: AGPL-3.0-only |
| 2 | note Map every resident Zone 1 tensor in tensors.bin into fixed per-layer slots |
| 3 | note for O(1) GPU binding during the 40-layer forward pass. |
| 4 | const lmStride ulong 41 |
| 5 | const lmMissing ulong 18446744073709551615 |
| 6 | global lmGlobal ulong 3 |
| 7 | global lmLayer ulong 1640 |
| 8 | |
| 9 | text lmTNorm "norm.weight" |
| 10 | text lmTHead "head.weight" |
| 11 | text lmTAttnNorm "attn_norm.weight" |
| 12 | text lmTFfnNorm "ffn_norm.weight" |
| 13 | text lmTHcAttnBase "hc_attn_base" |
| 14 | text lmTHcAttnFn "hc_attn_fn" |
| 15 | text lmTHcAttnScale "hc_attn_scale" |
| 16 | text lmTHcFfnBase "hc_ffn_base" |
| 17 | text lmTHcFfnFn "hc_ffn_fn" |
| 18 | text lmTHcFfnScale "hc_ffn_scale" |
| 19 | text lmTAttnSink "attn.attn_sink" |
| 20 | text lmTQNorm "attn.q_norm.weight" |
| 21 | text lmTKvNorm "attn.kv_norm.weight" |
| 22 | text lmTWqAW "attn.wq_a.weight" |
| 23 | text lmTWqAS "attn.wq_a.scale" |
| 24 | text lmTWqBW "attn.wq_b.weight" |
| 25 | text lmTWqBS "attn.wq_b.scale" |
| 26 | text lmTWkvW "attn.wkv.weight" |
| 27 | text lmTWkvS "attn.wkv.scale" |
| 28 | text lmTWoAW "attn.wo_a.weight" |
| 29 | text lmTWoAS "attn.wo_a.scale" |
| 30 | text lmTWoBW "attn.wo_b.weight" |
| 31 | text lmTWoBS "attn.wo_b.scale" |
| 32 | text lmTGateW "ffn.gate.weight" |
| 33 | text lmTGateB "ffn.gate.bias" |
| 34 | text lmTShW1W "ffn.shared_experts.w1.weight" |
| 35 | text lmTShW1S "ffn.shared_experts.w1.scale" |
| 36 | text lmTShW2W "ffn.shared_experts.w2.weight" |
| 37 | text lmTShW2S "ffn.shared_experts.w2.scale" |
| 38 | text lmTShW3W "ffn.shared_experts.w3.weight" |
| 39 | text lmTShW3S "ffn.shared_experts.w3.scale" |
| 40 | text lmTCmpNorm "attn.compressor.norm.weight" |
| 41 | text lmTCmpWkv "attn.compressor.wkv.weight" |
| 42 | text lmTCmpWgate "attn.compressor.wgate.weight" |
| 43 | text lmTIdxWqbW "attn.indexer.wq_b.weight" |
| 44 | text lmTIdxWqbS "attn.indexer.wq_b.scale" |
| 45 | text lmTIdxWproj "attn.indexer.weights_proj.weight" |
| 46 | text lmTIdxWk "attn.indexer.wk.weight" |
| 47 | text lmTIdxKnorm "attn.indexer.k_norm.weight" |
| 48 | text lmTEngWkvW "engram.wkv.weight" |
| 49 | text lmTEngWkvS "engram.wkv.scale" |
| 50 | text lmTEngQW "engram.q_weight" |
| 51 | text lmTEngKW "engram.k_weight" |
| 52 | |
| 53 | fn lmExact row view uchar 160 pos ulong needle view uchar * to bool |
| 54 | if not dcMatch row pos needle |
| 55 | ret false |
| 56 | end |
| 57 | endp = add pos len needle |
| 58 | if ge endp 160 |
| 59 | ret true |
| 60 | end |
| 61 | ret eq get row endp 0 |
| 62 | end |
| 63 | |
| 64 | fn lmSlotCore row view uchar 160 pos ulong to long |
| 65 | if lmExact row pos lmTAttnNorm |
| 66 | ret 0 |
| 67 | end |
| 68 | if lmExact row pos lmTFfnNorm |
| 69 | ret 1 |
| 70 | end |
| 71 | if lmExact row pos lmTHcAttnBase |
| 72 | ret 2 |
| 73 | end |
| 74 | if lmExact row pos lmTHcAttnFn |
| 75 | ret 3 |
| 76 | end |
| 77 | if lmExact row pos lmTHcAttnScale |
| 78 | ret 4 |
| 79 | end |
| 80 | if lmExact row pos lmTHcFfnBase |
| 81 | ret 5 |
| 82 | end |
| 83 | if lmExact row pos lmTHcFfnFn |
| 84 | ret 6 |
| 85 | end |
| 86 | if lmExact row pos lmTHcFfnScale |
| 87 | ret 7 |
| 88 | end |
| 89 | if lmExact row pos lmTAttnSink |
| 90 | ret 8 |
| 91 | end |
| 92 | if lmExact row pos lmTQNorm |
| 93 | ret 9 |
| 94 | end |
| 95 | if lmExact row pos lmTKvNorm |
| 96 | ret 10 |
| 97 | end |
| 98 | if lmExact row pos lmTWqAW |
| 99 | ret 11 |
| 100 | end |
| 101 | if lmExact row pos lmTWqAS |
| 102 | ret 12 |
| 103 | end |
| 104 | if lmExact row pos lmTWqBW |
| 105 | ret 13 |
| 106 | end |
| 107 | if lmExact row pos lmTWqBS |
| 108 | ret 14 |
| 109 | end |
| 110 | if lmExact row pos lmTWkvW |
| 111 | ret 15 |
| 112 | end |
| 113 | if lmExact row pos lmTWkvS |
| 114 | ret 16 |
| 115 | end |
| 116 | if lmExact row pos lmTWoAW |
| 117 | ret 17 |
| 118 | end |
| 119 | if lmExact row pos lmTWoAS |
| 120 | ret 18 |
| 121 | end |
| 122 | if lmExact row pos lmTWoBW |
| 123 | ret 19 |
| 124 | end |
| 125 | if lmExact row pos lmTWoBS |
| 126 | ret 20 |
| 127 | end |
| 128 | ret -1 |
| 129 | end |
| 130 | |
| 131 | fn lmSlotFfn row view uchar 160 pos ulong to long |
| 132 | if lmExact row pos lmTGateW |
| 133 | ret 21 |
| 134 | end |
| 135 | if lmExact row pos lmTGateB |
| 136 | ret 22 |
| 137 | end |
| 138 | if lmExact row pos lmTShW1W |
| 139 | ret 23 |
| 140 | end |
| 141 | if lmExact row pos lmTShW1S |
| 142 | ret 24 |
| 143 | end |
| 144 | if lmExact row pos lmTShW2W |
| 145 | ret 25 |
| 146 | end |
| 147 | if lmExact row pos lmTShW2S |
| 148 | ret 26 |
| 149 | end |
| 150 | if lmExact row pos lmTShW3W |
| 151 | ret 27 |
| 152 | end |
| 153 | if lmExact row pos lmTShW3S |
| 154 | ret 28 |
| 155 | end |
| 156 | if lmExact row pos lmTCmpNorm |
| 157 | ret 29 |
| 158 | end |
| 159 | if lmExact row pos lmTCmpWkv |
| 160 | ret 30 |
| 161 | end |
| 162 | if lmExact row pos lmTCmpWgate |
| 163 | ret 31 |
| 164 | end |
| 165 | if lmExact row pos lmTIdxWqbW |
| 166 | ret 32 |
| 167 | end |
| 168 | if lmExact row pos lmTIdxWqbS |
| 169 | ret 33 |
| 170 | end |
| 171 | if lmExact row pos lmTIdxWproj |
| 172 | ret 34 |
| 173 | end |
| 174 | if lmExact row pos lmTIdxWk |
| 175 | ret 35 |
| 176 | end |
| 177 | if lmExact row pos lmTIdxKnorm |
| 178 | ret 36 |
| 179 | end |
| 180 | if lmExact row pos lmTEngWkvW |
| 181 | ret 37 |
| 182 | end |
| 183 | if lmExact row pos lmTEngWkvS |
| 184 | ret 38 |
| 185 | end |
| 186 | if lmExact row pos lmTEngQW |
| 187 | ret 39 |
| 188 | end |
| 189 | if lmExact row pos lmTEngKW |
| 190 | ret 40 |
| 191 | end |
| 192 | ret -1 |
| 193 | end |
| 194 | |
| 195 | fn lmParseLayer row view uchar 160 to long |
| 196 | if or ne get row 56 108 ne get row 62 46 |
| 197 | ret -1 |
| 198 | end |
| 199 | val = ulong 0 |
| 200 | pos = ulong 63 |
| 201 | digits = ulong 0 |
| 202 | while and ge get row pos 48 le get row pos 57 |
| 203 | val = add mul val 10 sub ulong get row pos 48 |
| 204 | pos = add pos 1 |
| 205 | digits = add digits 1 |
| 206 | end |
| 207 | if or eq digits 0 or ge val 40 ne get row pos 46 |
| 208 | ret -1 |
| 209 | end |
| 210 | ret long val |
| 211 | end |
| 212 | |
| 213 | fn lmSuffixPos row view uchar 160 to ulong |
| 214 | pos = ulong 63 |
| 215 | while and ge get row pos 48 le get row pos 57 |
| 216 | pos = add pos 1 |
| 217 | end |
| 218 | ret add pos 1 |
| 219 | end |
| 220 | |
| 221 | fn lmIndex fd int to bool |
| 222 | row = new uchar 160 0 |
| 223 | for i ulong 3 |
| 224 | put lmGlobal i lmMissing |
| 225 | end |
| 226 | for i ulong 1640 |
| 227 | put lmLayer i lmMissing |
| 228 | end |
| 229 | for i ulong 96085 |
| 230 | if ne get dcLength i 0 |
| 231 | if not diRead fd row mul i 160 160 |
| 232 | ret false |
| 233 | end |
| 234 | off = get dcOffset i |
| 235 | if lmExact row 56 dcEmbedding |
| 236 | put lmGlobal 0 off |
| 237 | end |
| 238 | if lmExact row 56 lmTNorm |
| 239 | put lmGlobal 1 off |
| 240 | end |
| 241 | if lmExact row 56 lmTHead |
| 242 | put lmGlobal 2 off |
| 243 | end |
| 244 | layer = lmParseLayer row |
| 245 | if ge layer 0 |
| 246 | spos = lmSuffixPos row |
| 247 | slot = lmSlotCore row spos |
| 248 | if lt slot 0 |
| 249 | slot = lmSlotFfn row spos |
| 250 | end |
| 251 | if ge slot 0 |
| 252 | put lmLayer add mul ulong layer lmStride ulong slot off |
| 253 | end |
| 254 | end |
| 255 | end |
| 256 | end |
| 257 | for i ulong 3 |
| 258 | if eq get lmGlobal i lmMissing |
| 259 | ret false |
| 260 | end |
| 261 | end |
| 262 | for l ulong 40 |
| 263 | for s ulong 29 |
| 264 | if eq get lmLayer add mul l lmStride s lmMissing |
| 265 | ret false |
| 266 | end |
| 267 | end |
| 268 | end |
| 269 | ret true |
| 270 | end |