Repository navigation
Conversation
The Moonshot repo ships tiktoken.model and no tokenizer.json or chat_template.jinja. The Text path now reads the rank file when tokenizer.json is absent: a shared tiktoken loader (TiktokenFileTokenizer, on the existing TiktokenConverter and HfTokenizerJson), the Kimi pre-tokenizer and special-token table, and the XTML chat template ported from encoding_k3.py. tokenizer.json checkpoints and the refusal of a directory with neither tokenizer file are unchanged.
2 of 3 tasks
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacks on #797 (
feat/kimi-k31-text-route). Base this PR on that branch, not onmain; merge #797 first.What changed
The Moonshot repo ships
tiktoken.modeland notokenizer.jsonorchat_template.jinja, so #797 refused the real checkpoint. The Text path now loads the rank file whentokenizer.jsonis absent.TiktokenFileTokenizer(ModelAssets, shared): loads a tiktoken rank file with a pre-tokenizer regex and a special-token table. It reuses the existingTiktokenConverterandHfTokenizerJson, so no second BPE is added. AlsoCountRanksandWithReservedRange(<|reserved_token_N|>fill, as intokenization_kimi.py).KimiK31Tokenizer(LLM/Kimi): thetokenization_kimi.pypat_strrewritten for .NET (see below), plus the special table fromtokenizer_config.jsonand the reserved range.KimiK31ChatTemplate(LLM/Kimi): a text-only port ofbuild_chat_segmentsfromencoding_k3.py. Each segment is encoded separately, as the reference does. Tools, tool turns, tool calls, images, response formats and prefilled turns are refused by name.KimiK31TextModel.LoadandHfTextDirectoryLoader.RequireKimiK31Runnable.tokenizer.jsonwins when present and keeps its old path. Without it,tiktoken.modelis used, and the template ischat_template.jinjaif present, else the built-in template. A directory with neither tokenizer file is still refused.KimiK31Model.csandKimiK31WeightLoader.csare not touched.Real-repo facts
config.json,configuration_kimi_k3.py,encoding_k3.py,generation_config.json,kimi_k3_processor.py,kimi_k3_vision_processing.py,media_utils.py,preprocessor_config.json,tiktoken.model,tokenization_kimi.py,tokenizer_config.json,README.md,LICENSE. Notokenizer.json.resolve/main/tokenizer.jsonandresolve/main/chat_template.jinjaboth return 404.tiktoken.model(https://huggingface.co/moonshotai/Kimi-K3.1-Pro/resolve/main/tiktoken.model): 2,795,286 bytes, 163,584 lines ofbase64 rank, ranks dense from 0. All 256 single bytes present. No token shaped like<|...|>, so theGgufTokenizertemplate-shape heuristic does not misclassify base tokens.tokenizer_config.json:tokenizer_classTikTokenTokenizer; 16 named added tokens at ids 163584 to 163839 (non-contiguous);eos_tokenis[EOS]= 163585.config.jsonandgeneration_config.json:bos_token_id163584,eos_token_id163586 (<|end_of_msg|>),pad_token_id163839,vocab_size163840. The loader uses the config ids, so EOS is 163586. Thetokenizer_config.jsoneos_tokendisagrees and is not used.tokenization_kimi.py:pat_str(Han, cased letters, digits 1 to 3, punctuation, whitespace),num_reserved_special_tokens = 256,TikTokenTokenizer.encoding_k3.py: the XTML chat format.apply_chat_templatedefaultsthinking_efforttomaxand adds a thinking-effort system turn when thinking is on.Tests
TiktokenFileTokenizerTests).KimiK31RealVocabularyTests, Integration, skips unlessHARTSY_KIMI_TOKENIZER_DIRnames a directory withtiktoken.model): 2 passed locally against the downloadedtiktoken.model. Checks six text encodings and the 93-id default chat prompt, plus decode round-trip. No GPU, no checkpoint weights.Not verified
regexmodule on the published pattern. Thetiktokenpackage is not installed, so the ids are not checked against tiktoken itself.encoding_k3.pywas not executed, because it is downloaded code. The expected prompt text was derived by reading the source and mirroring its segmentation. The Python ports are not an oracle for the template; running the realencoding_k3.pyon the same messages would be.\p{Han}or&&set intersection. Han is written as its BMP blocks plus surrogate-pair ranges for planes 2 and 3. .NET letter classes are UTF-16 based, so astral letters outside Han can split differently from Rust regex.GgufTokenizerdoes everywhere. tiktoken would print the literal text of control tokens.[EOT](163593) and other end markers are not verified as stops.<think>channel is not parsed. The engine's numeric reasoning effort is ignored; the reference fixesmax.Notes