{"id":495775,"date":"2026-09-23T13:26:42","date_gmt":"2026-09-23T13:26:42","guid":{"rendered":"https:\/\/savepearlharbor.com\/?p=495775"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=495775","title":{"rendered":"\u041d\u0438 \u0441\u043b\u043e\u0432\u0430 \u043f\u043e-\u043a\u0438\u0442\u0430\u0439\u0441\u043a\u0438"},"content":{"rendered":"<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u0418\u043d\u043e\u0433\u0434\u0430 LLM\u043a\u0438 \u043f\u0443\u0442\u0430\u044e\u0442\u0441\u044f \u0432 \u044f\u0437\u044b\u043a\u0435, \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043e\u043d\u0438 \u043e\u0442\u0432\u0435\u0447\u0430\u044e\u0442 (<a href=\"https:\/\/habr.com\/ru\/companies\/selectel\/articles\/1044854\/\" rel=\"noopener nofollow\">\u041f\u7dad\u0447\u0435\u043c\u0443 \u043d\u0435\u0439\u0440\u043e\u8003\u0435\u0442\u0438 \u0434\u0435\u043b\u601d\u044e\u0442 \u0442\u0430\u043a<\/a>). \u0422\u0430\u043a \u043f\u043e\u0447\u0435\u043c\u0443 \u0431\u044b \u043d\u0435 \u043f\u043e\u043c\u043e\u0447\u044c \u0438\u043c \u0437\u0430\u0431\u044b\u0442\u044c \u043f\u0440\u043e \u044f\u0437\u044b\u043a\u0438, \u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043c\u044b \u043d\u0435 \u0437\u0430\u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043e\u0432\u0430\u043d\u044b.<\/p>\n<figure class=\"full-width \"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/827\/362\/94f\/82736294f2ad4c3e8009f4b559a09540.png\" width=\"1222\" height=\"519\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/getpro\/habr\/upload_files\/827\/362\/94f\/82736294f2ad4c3e8009f4b559a09540.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/827\/362\/94f\/82736294f2ad4c3e8009f4b559a09540.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/figure>\n<p>\u041a\u0430\u043a \u043c\u044b \u0437\u043d\u0430\u0435\u043c, LLM\u043a\u0438 \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0442 \u0441 \u0442\u043e\u043a\u0435\u043d\u0430\u043c\u0438: \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u044f\u0442 \u043a\u0443\u0441\u043a\u0438 \u0441\u043b\u043e\u0432 \u0432 \u043c\u043d\u043e\u0433\u043e\u043c\u0435\u0440\u043d\u044b\u0435 \u0432\u0435\u043a\u0442\u043e\u0440\u0430, \u043c\u043d\u043e\u0433\u043e \u0440\u0430\u0437 \u043f\u0435\u0440\u0435\u043c\u043d\u043e\u0436\u0430\u044e\u0442 \u0438\u0445 \u043d\u0430 \u0441\u0432\u043e\u0438 \u0432\u0435\u0441\u0430, \u0441\u043a\u043b\u0430\u0434\u044b\u0432\u0430\u044e\u0442 \u0434\u0440\u0443\u0433 \u0441 \u0434\u0440\u0443\u0433\u043e\u043c, \u0430 \u043f\u043e\u0442\u043e\u043c \u043f\u043e \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u043c\u0443 \u0432\u0435\u043a\u0442\u043e\u0440\u0443, \u0432\u043e\u0431\u0440\u0430\u0432\u0448\u0435\u043c\u0443 \u0432 \u0441\u0435\u0431\u044f \u0432\u0435\u0441\u044c \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442, \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u044e\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0442\u043e\u043a\u0435\u043d. \u0421\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u043d\u0435 \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u0437\u0430\u0442\u0440\u0443\u0434\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u043c \u0437\u0430\u043f\u0440\u0435\u0442\u0438\u0442\u044c \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0442\u044c \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u0435 \u0442\u043e\u043a\u0435\u043d\u044b \u0438\u0437 \u044f\u0437\u044b\u043a\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0430\u043c \u043d\u0435 \u043d\u0443\u0436\u043d\u044b.<\/p>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u043f\u0440\u0435\u043f\u0430\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043c\u0430\u043b\u0435\u043d\u044c\u043a\u0443\u044e \u043c\u043e\u0434\u0435\u043b\u044c\u043a\u0443 <a href=\"https:\/\/huggingface.co\/unsloth\/Qwen3.5-0.8B-GGUF\" rel=\"noopener nofollow\">Qwen3.5-0.8B-Q8_0.gguf<\/a> \u0438 \u043f\u043e\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u0435\u0451.<\/p>\n<figure class=\"full-width \"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/75b\/626\/27d\/75b62627d3d735cb9791bb6cdae7ea05.png\" alt=\"\u0418\u0441\u0445\u043e\u0434\u043d\u043e\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435\" title=\"\u0418\u0441\u0445\u043e\u0434\u043d\u043e\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435\" width=\"1236\" height=\"509\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/getpro\/habr\/upload_files\/75b\/626\/27d\/75b62627d3d735cb9791bb6cdae7ea05.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/75b\/626\/27d\/75b62627d3d735cb9791bb6cdae7ea05.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<div><figcaption>\u0418\u0441\u0445\u043e\u0434\u043d\u043e\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435<\/figcaption><\/div>\n<\/figure>\n<pre><code class=\"python\">import ggufreader = gguf.GGUFReader(\".\/Qwen3.5-0.8B-Q8_0.gguf\")tokens = reader.fields.get(\"tokenizer.ggml.tokens\").contents()print(f\"Total tokens {len(tokens)}\")types = reader.fields.get(\"tokenizer.ggml.token_type\").contents()print(f\"Total token types {len(set(types))} : {set(types)}\")# Total tokens 248320# Total token types 4 : {1, 3, 4, 5}<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><img style=\"width:87px;height:14px;object-fit:cover;object-position:left;\"\/><\/a><\/div><\/pre>\n<p>\u041e\u043d\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 byte-pair encoding \u0442\u043e\u043a\u0435\u043d\u0438\u0437\u0430\u0442\u043e\u0440 \u0441\u043e \u0441\u043b\u043e\u0432\u0430\u0440\u0451\u043c \u0432 248320 \u0442\u043e\u043a\u0435\u043d\u043e\u0432, \u0440\u0430\u0437\u0434\u0435\u043b\u0451\u043d\u043d\u044b\u043c \u043d\u0430 4 \u0442\u0438\u043f\u0430 (1 &#8212; \u0442\u0435\u043a\u0441\u0442, 3 &#8212; &lt;|\u0441\u043f\u0435\u0446|&gt;&lt;|\u0442\u043e\u043a\u0435\u043d\u044b|&gt;, 4 &#8212; &lt;\u0441\u043f\u0435\u0446&gt;&lt;\/\u0442\u043e\u043a\u0435\u043d\u044b&gt;, 5 &#8212; \u043f\u0430\u0434\u0434\u0438\u043d\u0433). \u0422\u0435\u043a\u0441\u0442\u043e\u0432\u044b\u0435 \u0442\u043e\u043a\u0435\u043d\u044b \u043d\u0430\u0447\u0438\u043d\u0430\u044e\u0442\u0441\u044f \u0441 <code>id_0=!<\/code> \u0438 \u0434\u043e\u0445\u043e\u0434\u044f\u0442 \u0434\u043e <code>id_248043=\u3042\u308a\u307e\u3059\u304b<\/code> . \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u043c \u0441\u043f\u0438\u0441\u043e\u043a \u0442\u043e\u043a\u0435\u043d\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c:<\/p>\n<pre><code class=\"python\">import syskeep_check = regex.compile(r\"[\"  r\"[\\p{N}\\p{P}\\p{S}&amp;&amp;\\p{Script=Common}]\" # \u0427\u0438\u0441\u043b\u0430, \u0437\u043d\u0430\u043a\u0438 \u043f\u0440\u0435\u043f\u0438\u043d\u0430\u043d\u0438\u044f \u0438 \u0441\u0438\u043c\u0432\u043e\u043b\u044b  r\"\\s\"                                   # \u041f\u0440\u043e\u0431\u0435\u043b\u044c\u043d\u044b\u0435 \u0441\u0438\u043c\u0432\u043e\u043b\u044b  r\"\u0430-\u044f\u0410-\u042f\u0451\u0401\"                             # \u041a\u0438\u0440\u0438\u043b\u043b\u0438\u0446\u0430  r\"a-zA-Z\"                               # \u041b\u0430\u0442\u0438\u043d\u0441\u043a\u0438\u0439 \u0430\u043b\u0444\u0430\u0432\u0438\u0442r\"]\", regex.V1)symbols_to_keep = set()for cp in range(sys.maxunicode + 1):  if keep_check.fullmatch(chr(cp)):    symbols_to_keep.add(chr(cp))print(f\"{len(symbols_to_keep)} symbols\")# 7994 symbols<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><img style=\"width:14px;height:14px;object-fit:cover;object-position:left;\"\/><\/a><\/div><\/pre>\n<p>\u0422\u0430\u043a \u0443 \u043d\u0430\u0441 \u043f\u043e\u044f\u0432\u0438\u043b\u0441\u044f \u0441\u043f\u0438\u0441\u043e\u043a \u0438\u0437 7994 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432. \u0422\u0435\u043f\u0435\u0440\u044c \u043c\u043e\u0436\u043d\u043e \u043e\u0442\u0444\u0438\u043b\u044c\u0442\u0440\u043e\u0432\u0430\u0442\u044c \u0442\u043e\u043a\u0435\u043d\u044b LLM\u043a\u0438, \u0447\u0442\u043e\u0431\u044b \u043e\u043d\u0438 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u043b\u0438 \u0442\u043e\u043b\u044c\u043a\u043e \u044d\u0442\u0438 \u0441\u0438\u043c\u0432\u043e\u043b\u044b.<\/p>\n<pre><code class=\"python\">from gguf.vocab import bytes_to_unicodebyte_decoder = {ch: b for b, ch in bytes_to_unicode().items()}tokens_to_rm = set()for i, t in enumerate(tokens):  if types[i] != 1:    # \u041d\u0430\u0441 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u0443\u044e\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u0442\u0435\u043a\u0441\u0442\u043e\u0432\u044b\u0435 \u0442\u043e\u043a\u0435\u043d\u044b    continue  raw = bytes(byte_decoder[ch] for ch in t)  try:    text = raw.decode(\"utf-8\")    if not all((ch in symbols_to_keep) for ch in text):      tokens_to_rm.add(i)  except UnicodeDecodeError:    # \u041e\u0431\u043b\u043e\u043c\u043a\u0438 utf-8, \u043f\u0443\u0441\u0442\u044c \u0431\u0443\u0434\u0443\u0442    continue  print(f\"Remove {len(tokens_to_rm)} tokens\")    # Remove 100468 tokens<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><img style=\"width:14px;height:14px;object-fit:cover;object-position:left;\"\/><\/a><\/div><\/pre>\n<p>\u0418\u0442\u043e\u0433\u043e \u043e\u0442 \u0438\u0437\u043d\u0430\u0447\u0430\u043b\u044c\u043d\u044b\u0445 248320 \u0442\u043e\u043a\u0435\u043d\u043e\u0432 \u043c\u044b \u0443\u0434\u0430\u043b\u0438\u043c 100468. \u0411\u0443\u0434\u0435\u043c \u044d\u0442\u043e \u0434\u0435\u043b\u0430\u0442\u044c \u0437\u0430\u043d\u0443\u043b\u044f\u044f \u0432\u0435\u0441\u0430 \u0432 \u043f\u0440\u0435\u0434\u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u043c \u0441\u043b\u043e\u0435, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0437\u0430\u043d\u0438\u043c\u0430\u0435\u0442\u0441\u044f \u0434\u0435\u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u043c\u043d\u043e\u0433\u043e\u043c\u0435\u0440\u043d\u043e\u0433\u043e \u0432\u0435\u043a\u0442\u043e\u0440\u0430 \u0432 logit \u0442\u043e\u043a\u0435\u043d\u0430.<\/p>\n<pre><code class=\"python\">for t in reader.tensors:  print(t.name)# output_norm.weight# token_embd.weight# blk.0.attn_gate.weight# ... \u0435\u0449\u0451 329 \u0441\u043b\u043e\u0451\u0432# blk.24.nextn.shared_head_norm.weight# blk.24.post_attention_norm.weight<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><img style=\"width:14px;height:14px;object-fit:cover;object-position:left;\"\/><\/a><\/div><\/pre>\n<p>\u0412\u043e\u0442 \u044d\u0442\u043e\u0442 <code>token_embd.weight<\/code> \u043d\u0430\u043c \u0438 \u043d\u0443\u0436\u0435\u043d. \u042d\u0442\u043e \u043e\u0431\u0449\u0438\u0439 encode\/decode \u0441\u043b\u043e\u0439, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0437\u0430\u043d\u0443\u043b\u0435\u043d\u0438\u0435 \u0442\u043e\u043a\u0435\u043d\u043e\u0432 \u043e\u0442\u0440\u0430\u0437\u0438\u0442\u0441\u044f \u0438 \u043d\u0430 \u0443\u043c\u0435\u043d\u0438\u0438 LLM\u043a\u0438 \u0447\u0438\u0442\u0430\u0442\u044c \u0442\u0435\u043a\u0441\u0442\u044b \u043d\u0430 \u044d\u0442\u0438\u0445 \u044f\u0437\u044b\u043a\u0430\u0445. \u041d\u0443 \u0447\u0442\u043e \u0436, \u044d\u0442\u043e \u0436\u0435\u0440\u0442\u0432\u0430, \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u044f \u0433\u043e\u0442\u043e\u0432 \u043f\u043e\u0439\u0442\u0438.<\/p>\n<pre><code class=\"python\">import numpy as nptoken_embd = next(t for t in reader.tensors if t.name == \"token_embd.weight\")n_vocab, bytes_per_row = token_embd.data.shapeblock_size = 1*2 + 32*1 # Q8_0: \u043e\u0434\u0438\u043d fp16 \u043c\u0430\u0441\u0448\u0442\u0430\u0431\u043d\u044b\u0439 \u043a\u043e\u044d\u0444\u0444\u0438\u0446\u0438\u0435\u043d\u0442 + 32 int8n_blocks = bytes_per_row \/\/ block_size# \u0431\u0443\u0434\u0435\u043c \u043f\u0430\u0442\u0447\u0438\u0442\u044c \u0444\u0430\u0439\u043b \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044etoken_embd_data = np.memmap(  gguf_file,  dtype=np.uint8,  mode=\"r+\",  offset=token_embd.data_offset,  shape=(n_vocab, n_blocks, block_size))# \u0437\u0430\u043d\u0443\u043b\u044f\u0435\u043c fp16 \u043c\u0430\u0441\u0448\u0442\u0430\u0431\u043d\u044b\u0439 \u043a\u043e\u044d\u0444\u0444\u0438\u0446\u0438\u0435\u043d\u0442token_embd_data[tokens_to_rm, :, 0:2] = 0token_embd_data.flush()del token_embd_data<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><img style=\"width:14px;height:14px;object-fit:cover;object-position:left;\"\/><\/a><\/div><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c, \u0447\u0442\u043e \u0443 \u043d\u0430\u0441 \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c. \u0417\u0430\u043f\u0443\u0441\u0442\u0438\u043c \u044d\u0442\u0443 \u043c\u043e\u0434\u0435\u043b\u044c \u0432 llama.cpp \u0438 \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u0434\u043e\u0431\u0438\u0442\u044c\u0441\u044f \u043e\u0442 \u043d\u0435\u0451 \u0438\u0435\u0440\u043e\u0433\u043b\u0438\u0444\u043e\u0432.<\/p>\n<figure class=\"full-width \"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/4f0\/c24\/2fd\/4f0c242fd12198f91d4f36d2ed3c7eac.png\" alt=\"\u041d\u0438 \u0441\u043b\u043e\u0432\u0430\" title=\"\u041d\u0438 \u0441\u043b\u043e\u0432\u0430\" width=\"1003\" height=\"1122\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/getpro\/habr\/upload_files\/4f0\/c24\/2fd\/4f0c242fd12198f91d4f36d2ed3c7eac.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/4f0\/c24\/2fd\/4f0c242fd12198f91d4f36d2ed3c7eac.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<div><figcaption>\u041d\u0438 \u0441\u043b\u043e\u0432\u0430<\/figcaption><\/div>\n<\/figure>\n<p>\u041d\u0430 \u044d\u0442\u043e\u043c, \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u0432\u0441\u0451.<\/p>\n<details class=\"spoiler\">\n<summary>\u041a\u043e\u0434 \u0446\u0435\u043b\u0438\u043a\u043e\u043c<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"python\">import shutilgguf_file = shutil.copyfile(    \".\/Qwen3.5-0.8B-Q8_0.gguf\",    \".\/Qwen3.5-0.8B-Q8_0.latcyr.gguf\")import ggufreader = gguf.GGUFReader(gguf_file)tokens = reader.fields.get(\"tokenizer.ggml.tokens\").contents()print(f\"Total tokens {len(tokens)}\")types = reader.fields.get(\"tokenizer.ggml.token_type\").contents()print(f\"Total token types {len(set(types))} : {set(types)}\")import sysimport regexkeep_check = regex.compile(r\"[\"  r\"[\\p{N}\\p{P}\\p{S}&amp;&amp;\\p{Script=Common}]\" # \u041e\u0431\u0449\u0438\u0435 \u0447\u0438\u0441\u043b\u0430, \u0437\u043d\u0430\u043a\u0438 \u043f\u0440\u0435\u043f\u0438\u043d\u0430\u043d\u0438\u044f \u0438 \u0441\u0438\u043c\u0432\u043e\u043b\u044b  r\"\\s\"                                   # \u041f\u0440\u043e\u0431\u0435\u043b\u044c\u043d\u044b\u0435 \u0441\u0438\u043c\u0432\u043e\u043b\u044b  r\"\u0430-\u044f\u0410-\u042f\u0451\u0401\"                             # \u041a\u0438\u0440\u0438\u043b\u043b\u0438\u0446\u0430  r\"a-zA-Z\"                               # \u041b\u0430\u0442\u0438\u043d\u0441\u043a\u0438\u0439 \u0430\u043b\u0444\u0430\u0432\u0438\u0442r\"]\", regex.V1)symbols_to_keep = set()for cp in range(sys.maxunicode + 1):  if keep_check.fullmatch(chr(cp)):    symbols_to_keep.add(chr(cp))print(f\"{len(symbols_to_keep)} symbols\")from gguf.vocab import bytes_to_unicodeBYTE_DECODER = {ch: b for b, ch in bytes_to_unicode().items()}tokens_to_rm = []for i, t in enumerate(tokens):    if types[i] != 1:        continue    raw = bytes(BYTE_DECODER[ch] for ch in t)    try:        text = raw.decode(\"utf-8\")        if not all((ch in symbols_to_keep) for ch in text):            tokens_to_rm.append(i)    except UnicodeDecodeError:        # \u041e\u0431\u043b\u043e\u043c\u043a\u0438 utf-8        continueprint(f\"Remove {len(tokens_to_rm)} tokens\")import numpy as nptoken_embd = next(t for t in reader.tensors if t.name == \"token_embd.weight\")n_vocab, bytes_per_row = token_embd.data.shapeblock_size = 1*2 + 32*1 # Q8_0: \u043e\u0434\u0438\u043d fp16 \u043c\u0430\u0441\u0448\u0442\u0430\u0431\u043d\u044b\u0439 \u043a\u043e\u044d\u0444\u0444\u0438\u0446\u0438\u0435\u043d\u0442 + 32 int8n_blocks = bytes_per_row \/\/ block_sizetoken_embd_data = np.memmap(    gguf_file,    dtype=np.uint8,    mode=\"r+\",    offset=token_embd.data_offset,    shape=(n_vocab, n_blocks, block_size))token_embd_data[tokens_to_rm, :, 0:2] = 0 # \u0437\u0430\u043d\u0443\u043b\u044f\u0435\u043c fp16 \u043c\u0430\u0441\u0448\u0442\u0430\u0431\u043d\u044b\u0439 \u043a\u043e\u044d\u0444\u0444\u0438\u0446\u0438\u0435\u043d\u0442token_embd_data.flush()del token_embd_data<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><img style=\"width:14px;height:14px;object-fit:cover;object-position:left;\"\/><\/a><\/div><\/pre>\n<\/div>\n<\/details>\n<\/div>\n<p>\u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/1085742\/\">https:\/\/habr.com\/ru\/articles\/1085742\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u0418\u043d\u043e\u0433\u0434\u0430 LLM\u043a\u0438 \u043f\u0443\u0442\u0430\u044e\u0442\u0441\u044f \u0432 \u044f\u0437\u044b\u043a\u0435, \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043e\u043d\u0438 \u043e\u0442\u0432\u0435\u0447\u0430\u044e\u0442 (\u041f\u7dad\u0447\u0435\u043c\u0443 \u043d\u0435\u0439\u0440\u043e\u8003\u0435\u0442\u0438 \u0434\u0435\u043b\u601d\u044e\u0442 \u0442\u0430\u043a). \u0422\u0430\u043a \u043f\u043e\u0447\u0435\u043c\u0443 \u0431\u044b \u043d\u0435 \u043f\u043e\u043c\u043e\u0447\u044c \u0438\u043c \u0437\u0430\u0431\u044b\u0442\u044c \u043f\u0440\u043e \u044f\u0437\u044b\u043a\u0438, \u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043c\u044b \u043d\u0435 \u0437\u0430\u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043e\u0432\u0430\u043d\u044b.\u041a\u0430\u043a \u043c\u044b \u0437\u043d\u0430\u0435\u043c, LLM\u043a\u0438 \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0442 \u0441 \u0442\u043e\u043a\u0435\u043d\u0430\u043c\u0438: \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u044f\u0442 \u043a\u0443\u0441\u043a\u0438 \u0441\u043b\u043e\u0432 \u0432 \u043c\u043d\u043e\u0433\u043e\u043c\u0435\u0440\u043d\u044b\u0435 \u0432\u0435\u043a\u0442\u043e\u0440\u0430, \u043c\u043d\u043e\u0433\u043e \u0440\u0430\u0437 \u043f\u0435\u0440\u0435\u043c\u043d\u043e\u0436\u0430\u044e\u0442 \u0438\u0445 \u043d\u0430 \u0441\u0432\u043e\u0438 \u0432\u0435\u0441\u0430, \u0441\u043a\u043b\u0430\u0434\u044b\u0432\u0430\u044e\u0442 \u0434\u0440\u0443\u0433 \u0441 \u0434\u0440\u0443\u0433\u043e\u043c, \u0430 \u043f\u043e\u0442\u043e\u043c \u043f\u043e \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u043c\u0443 \u0432\u0435\u043a\u0442\u043e\u0440\u0443, \u0432\u043e\u0431\u0440\u0430\u0432\u0448\u0435\u043c\u0443 \u0432 \u0441\u0435\u0431\u044f \u0432\u0435\u0441\u044c \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442, \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u044e\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0442\u043e\u043a\u0435\u043d. \u0421\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u043d\u0435 \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u0437\u0430\u0442\u0440\u0443\u0434\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u043c \u0437\u0430\u043f\u0440\u0435\u0442\u0438\u0442\u044c \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0442\u044c \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u0435 \u0442\u043e\u043a\u0435\u043d\u044b \u0438\u0437 \u044f\u0437\u044b\u043a\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0430\u043c \u043d\u0435 \u043d\u0443\u0436\u043d\u044b.\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u043f\u0440\u0435\u043f\u0430\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043c\u0430\u043b\u0435\u043d\u044c\u043a\u0443\u044e \u043c\u043e\u0434\u0435\u043b\u044c\u043a\u0443 Qwen3.5-0.8B-Q8_0.gguf \u0438 \u043f\u043e\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u0435\u0451.\u0418\u0441\u0445\u043e\u0434\u043d\u043e\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435import ggufreader = gguf.GGUFReader(&#171;.\/Qwen3.5-0.8B-Q8_0.gguf&#187;)tokens = reader.fields.get(&#171;tokenizer.ggml.tokens&#187;).contents()print(f&#187;Total tokens {len(tokens)}&#187;)types = reader.fields.get(&#171;tokenizer.ggml.token_type&#187;).contents()print(f&#187;Total token types {len(set(types))} : {set(types)}&#187;)# Total tokens 248320# Total token types 4 : {1, 3, 4, 5}\u041e\u043d\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 byte-pair encoding \u0442\u043e\u043a\u0435\u043d\u0438\u0437\u0430\u0442\u043e\u0440 \u0441\u043e \u0441\u043b\u043e\u0432\u0430\u0440\u0451\u043c \u0432 248320 \u0442\u043e\u043a\u0435\u043d\u043e\u0432, \u0440\u0430\u0437\u0434\u0435\u043b\u0451\u043d\u043d\u044b\u043c \u043d\u0430 4 \u0442\u0438\u043f\u0430 (1 &#8212; \u0442\u0435\u043a\u0441\u0442, 3 &#8212; &lt;|\u0441\u043f\u0435\u0446|&gt;&lt;|\u0442\u043e\u043a\u0435\u043d\u044b|&gt;, 4 &#8212; &lt;\u0441\u043f\u0435\u0446&gt;&lt;\/\u0442\u043e\u043a\u0435\u043d\u044b&gt;, 5 &#8212; \u043f\u0430\u0434\u0434\u0438\u043d\u0433). \u0422\u0435\u043a\u0441\u0442\u043e\u0432\u044b\u0435 \u0442\u043e\u043a\u0435\u043d\u044b \u043d\u0430\u0447\u0438\u043d\u0430\u044e\u0442\u0441\u044f \u0441 id_0=! \u0438 \u0434\u043e\u0445\u043e\u0434\u044f\u0442 \u0434\u043e id_248043=\u3042\u308a\u307e\u3059\u304b . \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u043c \u0441\u043f\u0438\u0441\u043e\u043a \u0442\u043e\u043a\u0435\u043d\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c:import syskeep_check = regex.compile(r&#187;[&#187;  r&#187;[\\p{N}\\p{P}\\p{S}&amp;&amp;\\p{Script=Common}]&#187; # \u0427\u0438\u0441\u043b\u0430, \u0437\u043d\u0430\u043a\u0438 \u043f\u0440\u0435\u043f\u0438\u043d\u0430\u043d\u0438\u044f \u0438 \u0441\u0438\u043c\u0432\u043e\u043b\u044b  r&#187;\\s&#187;                                   # \u041f\u0440\u043e\u0431\u0435\u043b\u044c\u043d\u044b\u0435 \u0441\u0438\u043c\u0432\u043e\u043b\u044b  r&#187;\u0430-\u044f\u0410-\u042f\u0451\u0401&#187;                             # \u041a\u0438\u0440\u0438\u043b\u043b\u0438\u0446\u0430  r&#187;a-zA-Z&#187;                               # \u041b\u0430\u0442\u0438\u043d\u0441\u043a\u0438\u0439 \u0430\u043b\u0444\u0430\u0432\u0438\u0442r&#187;]&#187;, regex.V1)symbols_to_keep = set()for cp in range(sys.maxunicode + 1):  if keep_check.fullmatch(chr(cp)):    symbols_to_keep.add(chr(cp))print(f&#187;{len(symbols_to_keep)} symbols&#187;)# 7994 symbols\u0422\u0430\u043a \u0443 \u043d\u0430\u0441 \u043f\u043e\u044f\u0432\u0438\u043b\u0441\u044f \u0441\u043f\u0438\u0441\u043e\u043a \u0438\u0437 7994 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432. \u0422\u0435\u043f\u0435\u0440\u044c \u043c\u043e\u0436\u043d\u043e \u043e\u0442\u0444\u0438\u043b\u044c\u0442\u0440\u043e\u0432\u0430\u0442\u044c \u0442\u043e\u043a\u0435\u043d\u044b LLM\u043a\u0438, \u0447\u0442\u043e\u0431\u044b \u043e\u043d\u0438 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u043b\u0438 \u0442\u043e\u043b\u044c\u043a\u043e \u044d\u0442\u0438 \u0441\u0438\u043c\u0432\u043e\u043b\u044b.from gguf.vocab import bytes_to_unicodebyte_decoder = {ch: b for b, ch in bytes_to_unicode().items()}tokens_to_rm = set()for i, t in enumerate(tokens):  if types[i] != 1:    # \u041d\u0430\u0441 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u0443\u044e\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u0442\u0435\u043a\u0441\u0442\u043e\u0432\u044b\u0435 \u0442\u043e\u043a\u0435\u043d\u044b    continue  raw = bytes(byte_decoder[ch] for ch in t)  try:    text = raw.decode(&#171;utf-8&#8243;)    if not all((ch in symbols_to_keep) for ch in text):      tokens_to_rm.add(i)  except UnicodeDecodeError:    # \u041e\u0431\u043b\u043e\u043c\u043a\u0438 utf-8, \u043f\u0443\u0441\u0442\u044c \u0431\u0443\u0434\u0443\u0442    continue  print(f&#187;Remove {len(tokens_to_rm)} tokens&#187;)    # Remove 100468 tokens\u0418\u0442\u043e\u0433\u043e \u043e\u0442 \u0438\u0437\u043d\u0430\u0447\u0430\u043b\u044c\u043d\u044b\u0445 248320 \u0442\u043e\u043a\u0435\u043d\u043e\u0432 \u043c\u044b \u0443\u0434\u0430\u043b\u0438\u043c 100468. \u0411\u0443\u0434\u0435\u043c \u044d\u0442\u043e \u0434\u0435\u043b\u0430\u0442\u044c \u0437\u0430\u043d\u0443\u043b\u044f\u044f \u0432\u0435\u0441\u0430 \u0432 \u043f\u0440\u0435\u0434\u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u043c \u0441\u043b\u043e\u0435, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0437\u0430\u043d\u0438\u043c\u0430\u0435\u0442\u0441\u044f \u0434\u0435\u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u043c\u043d\u043e\u0433\u043e\u043c\u0435\u0440\u043d\u043e\u0433\u043e \u0432\u0435\u043a\u0442\u043e\u0440\u0430 \u0432 logit \u0442\u043e\u043a\u0435\u043d\u0430.for t in reader.tensors:  print(t.name)# output_norm.weight# token_embd.weight# blk.0.attn_gate.weight# &#8230; \u0435\u0449\u0451 329 \u0441\u043b\u043e\u0451\u0432# blk.24.nextn.shared_head_norm.weight# blk.24.post_attention_norm.weight\u0412\u043e\u0442 \u044d\u0442\u043e\u0442 token_embd.weight \u043d\u0430\u043c \u0438 \u043d\u0443\u0436\u0435\u043d. \u042d\u0442\u043e \u043e\u0431\u0449\u0438\u0439 encode\/decode \u0441\u043b\u043e\u0439, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0437\u0430\u043d\u0443\u043b\u0435\u043d\u0438\u0435 \u0442\u043e\u043a\u0435\u043d\u043e\u0432 \u043e\u0442\u0440\u0430\u0437\u0438\u0442\u0441\u044f \u0438 \u043d\u0430 \u0443\u043c\u0435\u043d\u0438\u0438 LLM\u043a\u0438 \u0447\u0438\u0442\u0430\u0442\u044c \u0442\u0435\u043a\u0441\u0442\u044b \u043d\u0430 \u044d\u0442\u0438\u0445 \u044f\u0437\u044b\u043a\u0430\u0445. \u041d\u0443 \u0447\u0442\u043e \u0436, \u044d\u0442\u043e \u0436\u0435\u0440\u0442\u0432\u0430, \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u044f \u0433\u043e\u0442\u043e\u0432 \u043f\u043e\u0439\u0442\u0438.import numpy as nptoken_embd = next(t for t in reader.tensors if t.name == &#171;token_embd.weight&#187;)n_vocab, bytes_per_row = token_embd.data.shapeblock_size = 1*2 + 32*1 # Q8_0: \u043e\u0434\u0438\u043d fp16 \u043c\u0430\u0441\u0448\u0442\u0430\u0431\u043d\u044b\u0439 \u043a\u043e\u044d\u0444\u0444\u0438\u0446\u0438\u0435\u043d\u0442 + 32 int8n_blocks = bytes_per_row \/\/ block_size# \u0431\u0443\u0434\u0435\u043c \u043f\u0430\u0442\u0447\u0438\u0442\u044c \u0444\u0430\u0439\u043b \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044etoken_embd_data = np.memmap(  gguf_file,  dtype=np.uint8,  mode=&#187;r+&#187;,  offset=token_embd.data_offset,  shape=(n_vocab, n_blocks, block_size))# \u0437\u0430\u043d\u0443\u043b\u044f\u0435\u043c fp16 \u043c\u0430\u0441\u0448\u0442\u0430\u0431\u043d\u044b\u0439 \u043a\u043e\u044d\u0444\u0444\u0438\u0446\u0438\u0435\u043d\u0442token_embd_data[tokens_to_rm, :, 0:2] = 0token_embd_data.flush()del token_embd_data\u0422\u0435\u043f\u0435\u0440\u044c \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c, \u0447\u0442\u043e \u0443 \u043d\u0430\u0441 \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c. \u0417\u0430\u043f\u0443\u0441\u0442\u0438\u043c \u044d\u0442\u0443 \u043c\u043e\u0434\u0435\u043b\u044c \u0432 llama.cpp \u0438 \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u0434\u043e\u0431\u0438\u0442\u044c\u0441\u044f \u043e\u0442 \u043d\u0435\u0451 \u0438\u0435\u0440\u043e\u0433\u043b\u0438\u0444\u043e\u0432.\u041d\u0438 \u0441\u043b\u043e\u0432\u0430\u041d\u0430 \u044d\u0442\u043e\u043c, \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u0432\u0441\u0451.\u041a\u043e\u0434 \u0446\u0435\u043b\u0438\u043a\u043e\u043cimport shutilgguf_file = shutil.copyfile(    &#171;.\/Qwen3.5-0.8B-Q8_0.gguf&#187;,    &#171;.\/Qwen3.5-0.8B-Q8_0.latcyr.gguf&#187;)import ggufreader = gguf.GGUFReader(gguf_file)tokens = reader.fields.get(&#171;tokenizer.ggml.tokens&#187;).contents()print(f&#187;Total tokens {len(tokens)}&#187;)types = reader.fields.get(&#171;tokenizer.ggml.token_type&#187;).contents()print(f&#187;Total token types {len(set(types))} : {set(types)}&#187;)import sysimport regexkeep_check = regex.compile(r&#187;[&#187;  r&#187;[\\p{N}\\p{P}\\p{S}&amp;&amp;\\p{Script=Common}]&#187; # \u041e\u0431\u0449\u0438\u0435 \u0447\u0438\u0441\u043b\u0430, \u0437\u043d\u0430\u043a\u0438 \u043f\u0440\u0435\u043f\u0438\u043d\u0430\u043d\u0438\u044f \u0438 \u0441\u0438\u043c\u0432\u043e\u043b\u044b  r&#187;\\s&#187;                                   # \u041f\u0440\u043e\u0431\u0435\u043b\u044c\u043d\u044b\u0435 \u0441\u0438\u043c\u0432\u043e\u043b\u044b  r&#187;\u0430-\u044f\u0410-\u042f\u0451\u0401&#187;                             # \u041a\u0438\u0440\u0438\u043b\u043b\u0438\u0446\u0430  r&#187;a-zA-Z&#187;                               # \u041b\u0430\u0442\u0438\u043d\u0441\u043a\u0438\u0439 \u0430\u043b\u0444\u0430\u0432\u0438\u0442r&#187;]&#187;, regex.V1)symbols_to_keep = set()for cp in range(sys.maxunicode + 1):  if keep_check.fullmatch(chr(cp)):    symbols_to_keep.add(chr(cp))print(f&#187;{len(symbols_to_keep)} symbols&#187;)from gguf.vocab import bytes_to_unicodeBYTE_DECODER = {ch: b for b, ch in bytes_to_unicode().items()}tokens_to_rm = []for i, t in enumerate(tokens):    if types[i] != 1:        continue    raw = bytes(BYTE_DECODER[ch] for ch in t)    try:        text = raw.decode(&#171;utf-8&#8243;)        if not all((ch in symbols_to_keep) for ch in text):            tokens_to_rm.append(i)    except UnicodeDecodeError:        # \u041e\u0431\u043b\u043e\u043c\u043a\u0438 utf-8        continueprint(f&#187;Remove {len(tokens_to_rm)} tokens&#187;)import numpy as nptoken_embd = next(t for t in reader.tensors if t.name == &#171;token_embd.weight&#187;)n_vocab, bytes_per_row = token_embd.data.shapeblock_size = 1*2 + 32*1 # Q8_0: \u043e\u0434\u0438\u043d fp16 \u043c\u0430\u0441\u0448\u0442\u0430\u0431\u043d\u044b\u0439 \u043a\u043e\u044d\u0444\u0444\u0438\u0446\u0438\u0435\u043d\u0442 + 32 int8n_blocks = bytes_per_row \/\/ block_sizetoken_embd_data = np.memmap(    gguf_file,    dtype=np.uint8,    mode=&#187;r+&#187;,    offset=token_embd.data_offset,    shape=(n_vocab, n_blocks, block_size))token_embd_data[tokens_to_rm, :, 0:2] = 0 # \u0437\u0430\u043d\u0443\u043b\u044f\u0435\u043c fp16 \u043c\u0430\u0441\u0448\u0442\u0430\u0431\u043d\u044b\u0439 \u043a\u043e\u044d\u0444\u0444\u0438\u0446\u0438\u0435\u043d\u0442token_embd_data.flush()del token_embd_data\u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 https:\/\/habr.com\/ru\/articles\/1085742\/<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-495775","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/495775","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=495775"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/495775\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=495775"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=495775"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=495775"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}