Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/aien-sovereign-core-mv/blob/main/om/qwen-native/tokenizer/model.om # 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 Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `aien-sovereign-core-mv / om / qwen-native / tokenizer / model.om` 287 lines ยท 5041 bytes Raw Blame History 1 note Read the frozen JSON once, authenticate those same bytes before interpreting its layout. 2 text q27hash "`0997f410c57a1f4e53b09e4be8f4a172d90edd9564368fb0847030937229b9f3`" 3 text q35hash "`5f9e4d4901a92b997e463c1f46055088b6cca5ca61a6522d1b9f64c4bb81cb42`" 4 text suffix "/tokenizer.json" 5 global pathbuf uchar 4096 6 global modeldata uchar * 7 global spelling uchar * 8 global starts ulong 248077 9 global sizes uint 248077 10 global vocabmap uint 524288 11 global pairkeys ulong 524288 12 global ranks uint 524288 13 global results uint 524288 14 global baseids uint 256 15 global inverse uint 324 16 global wordbuf uchar 512 17 global meta ulong 4 18 note meta: bytes of spelling, number of valid ids, model byte length, current merge separator offset. 19 fn equalbytes a view uchar * b view uchar * to bool 20 if ne len a len b 21 ret false 22 end 23 for i ulong len a 24 if ne get a i get b i 25 ret false 26 end 27 end 28 ret true 29 end 30 31 global qtidentity ulong 1 32 fn authmodel to void 33 n = argread 2 pathbuf 0 sub len pathbuf len suffix 34 if le n 0 35 exit 2 36 end 37 for i ulong len suffix 38 put pathbuf add ulong n i get suffix i 39 end 40 fd = fopen pathbuf 0 add ulong n len suffix 0 0 41 if lt fd 0 42 exit 3 43 end 44 nbytes = ulong 0 45 hreset 46 while true 47 r = enlarge modeldata add nbytes 65536 48 if lt r 0 49 exit 4 50 end 51 r = read int fd modeldata nbytes 65536 52 if lt r 0 53 exit 3 54 end 55 if eq r 0 56 break 57 end 58 for i ulong ulong r 59 if not hpush get modeldata add nbytes i 60 exit 3 61 end 62 end 63 nbytes = add nbytes ulong r 64 if gt nbytes `12809320` 65 exit 3 66 end 67 end 68 r = fclose int fd 69 if not hfinal 70 exit 3 71 end 72 a = true 73 b = true 74 for i ulong 64 75 if ne get hd i get q27hash i 76 a = false 77 end 78 if ne get hd i get q35hash i 79 b = false 80 end 81 end 82 if not or a b 83 exit 3 84 end 85 if a 86 put qtidentity 0 27 87 else 88 put qtidentity 0 35 89 end 90 put meta 2 nbytes 91 r = enlarge spelling nbytes 92 if lt r 0 93 exit 4 94 end 95 end 96 97 note ByteLevel inverse alphabet, plain printable bytes followed by escaped bytes. 98 fn alphabet to void 99 k = ulong 256 100 for c ulong 256 101 if or or and ge c 33 le c 126 and ge c 161 le c 172 ge c 174 102 put inverse c uint c 103 else 104 put inverse k uint c 105 k = add k 1 106 end 107 end 108 end 109 110 note Convert a decoded JSON string into raw spelling; merge separator is ASCII space. 111 fn bytesof s view uchar * n ulong merge bool to ulong 112 i = ulong 0 113 w = ulong 0 114 while lt i n 115 c = ulong get s i 116 i = add i 1 117 if ge c 128 118 c = add shl and c 31 6 and ulong get s i 63 119 i = add i 1 120 end 121 if and merge eq c 32 122 put meta 3 w 123 else 124 put wordbuf w uchar get inverse c 125 w = add w 1 126 end 127 end 128 ret w 129 end 130 131 fn wordmatches id ulong o ulong n ulong to bool 132 if ne ulong get sizes id n 133 ret false 134 end 135 base = get starts id 136 for j ulong n 137 if ne get spelling add base j get wordbuf add o j 138 ret false 139 end 140 end 141 ret true 142 end 143 144 fn vslot o ulong n ulong to ulong 145 h = ulong `14695981039346656037` 146 for j ulong n 147 h = mul xor h ulong get wordbuf add o j `1099511628211` 148 end 149 s = and h 524287 150 while ne get vocabmap s 0 151 id = sub ulong get vocabmap s 1 152 if wordmatches id o n 153 break 154 end 155 s = and add s 1 524287 156 end 157 ret s 158 end 159 160 fn saveword id ulong n ulong to void 161 o = get meta 0 162 put starts id o 163 put sizes id uint n 164 for j ulong n 165 put spelling add o j get wordbuf j 166 end 167 put meta 0 add o n 168 end 169 170 note Multiplicative pair hash and linear probing adapted from seeded tkcore.om tkslot/tkrins. 171 fn pairslot key ulong to ulong 172 s = shr mul add key 1 ulong `11400714819323198485` 45 173 while ne get ranks s 0 174 if eq get pairkeys s key 175 break 176 end 177 s = and add s 1 524287 178 end 179 ret s 180 end 181 182 fn pairkey a ulong b ulong to ulong 183 ret or shl a 32 b 184 end 185 186 fn addmerge n ulong rank ulong to void 187 cut = get meta 3 188 a = get vocabmap vslot 0 cut 189 b = get vocabmap vslot cut sub n cut 190 v = get vocabmap vslot 0 n 191 if or or eq a 0 eq b 0 eq v 0 192 exit 3 193 end 194 key = pairkey sub ulong a 1 sub ulong b 1 195 s = pairslot key 196 put pairkeys s key 197 put ranks s uint rank 198 put results s sub v 1 199 end 200 201 fn keyat line view uchar * k ulong name view uchar * to bool 202 if gt add k len name len line 203 ret false 204 end 205 for i ulong len name 206 if ne get line add k i get name i 207 ret false 208 end 209 end 210 ret true 211 end 212 213 text vocabkey "\"vocab\": {" 214 text mergekey "\"merges\": [" 215 text contentkey "\"content\": " 216 text idkey "\"id\": " 217 fn loadmodel to void 218 authmodel 219 alphabet 220 line = new uchar 1024 0 221 s = new uchar 512 0 222 p = ulong 0 223 phase = ulong 0 224 id = ulong 0 225 rank = ulong 0 226 while lt p get meta 2 bound `9223372036854775807` 227 n = ulong 0 228 while lt p get meta 2 229 c = get modeldata p 230 p = add p 1 231 if eq c 10 232 break 233 end 234 put line n c 235 n = add n 1 236 end 237 k = ulong 0 238 while and lt k n eq get line k 32 239 k = add k 1 240 end 241 if keyat line k vocabkey 242 phase = ulong 1 243 id = ulong 0 244 else 245 if keyat line k mergekey 246 phase = ulong 2 247 else 248 if eq phase 0 249 if keyat line k idkey 250 id = js_tou line add k len idkey 251 end 252 if keyat line k contentkey 253 z = js_sget line add k len contentkey s 254 if lt z 0 255 exit 3 256 end 257 for j ulong ulong z 258 put wordbuf j get s j 259 end 260 saveword id ulong z 261 put meta 1 add id 1 262 end 263 else 264 if eq get line k 34 265 z = js_sget line k s 266 if lt z 0 267 exit 3 268 end 269 w = bytesof s ulong z eq phase 2 270 if eq phase 1 271 slot = vslot 0 w 272 saveword id w 273 put vocabmap slot uint add id 1 274 if eq w 1 275 put baseids get wordbuf 0 uint id 276 end 277 id = add id 1 278 else 279 rank = add rank 1 280 addmerge w rank 281 end 282 end 283 end 284 end 285 end 286 end 287 end