Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions terminal/serve/test_inkling.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@ def test_the_pattern_is_gpt_4os(self):
self.assertEqual(self.pieces("你好ab"), ["你好ab"])
self.assertEqual(self.pieces("a \nb"), ["a", " \n", "b"])

def test_a_piece_that_is_a_token_is_that_token(self):
# the model's tokenizer.json sets ignore_merges: "ab" is a token, though no merge makes it. (In the real
# vocabulary "kwargs" is such a token: Hugging Face gives [87550], llama.cpp [86226, 70, 82].)
tok = ST.Tokenizer(["a", "b", "ab"], [], pre="inkling2")
self.assertTrue(tok.ignore_merges)
self.assertEqual(tok.encode("ab"), [2])


class Blocks(unittest.TestCase):
def test_thinking_then_text_however_it_arrives(self):
Expand Down
9 changes: 7 additions & 2 deletions terminal/tools/strata_tokenizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,10 @@ def bytes_to_unicode() -> dict[int, str]:
LAGUNA_SEQUENCE = (r"[^\n]+|[\n]+", QWEN2_PATTERN)

# The `inkling2` pre-tokenizer (Thinking Machines' Inkling 2), llama.cpp's LLAMA_VOCAB_PRE_TYPE_GPT4O: a word with
# its capitals first or its small letters first, an English contraction kept on it, digits three at a time.
# its capitals first or its small letters first, an English contraction kept on it, digits three at a time. With
# ignore_merges, as the model's tokenizer.json sets it (Hugging Face's tokenizers are the reference): a piece that is a
# token is that token. llama.cpp 29b52d398b does not set it for this name, and writes "kwargs" (one token that no
# chain of merges reaches) as three tokens.
GPT4O_PATTERN = (
r"[^\r\n\p{L}\p{N}]?[\p{Lu}\p{Lt}\p{Lm}\p{Lo}\p{M}]*[\p{Ll}\p{Lm}\p{Lo}\p{M}]+(?i:'s|'t|'re|'ve|'m|'ll|'d)?"
r"|[^\r\n\p{L}\p{N}]?[\p{Lu}\p{Lt}\p{Lm}\p{Lo}\p{M}]+[\p{Ll}\p{Lm}\p{Lo}\p{M}]*(?i:'s|'t|'re|'ve|'m|'ll|'d)?"
Expand All @@ -163,7 +166,7 @@ def bytes_to_unicode() -> dict[int, str]:
"qwen2": QWEN2_PATTERN, "inkling2": GPT4O_PATTERN}
PRE_SEQUENCES = {"joyai-llm": DEEPSEEK3_SEQUENCE, "deepseek-v3": DEEPSEEK3_SEQUENCE, "flint": FLINT_SEQUENCE,
"laguna": LAGUNA_SEQUENCE}
IGNORE_MERGES = ("glm4", "glm5", "lfm2")
IGNORE_MERGES = ("glm4", "glm5", "lfm2", "inkling2")
RAW = ("gemma4",) # vocabularies of UTF-8 pieces
MODELS = {"gpt2": None, "gemma4": "gemma4"} # tokenizer.ggml.model -> the pre-tokenizer it implies, if any

Expand Down Expand Up @@ -693,6 +696,8 @@ def extract(gguf_path, out_dir) -> dict:
"pre_pattern_source": "llama.cpp src/llama-vocab.cpp (LLAMA_VOCAB_PRE_TYPE_GEMMA4)" if tk.raw
else "llama.cpp src/llama-vocab.cpp (LLAMA_VOCAB_PRE_TYPE_DEEPSEEK3_LLM)"
if tk.pre_sequence
else "llama.cpp src/llama-vocab.cpp (LLAMA_VOCAB_PRE_TYPE_GPT4O), with tokenizer.json's "
"ignore_merges" if tk.pre_pattern == GPT4O_PATTERN
else "llama.cpp src/llama-vocab.cpp (LLAMA_VOCAB_PRE_TYPE_CHATGLM4)" if tk.ignore_merges
else "llama.cpp src/llama-vocab.cpp (LLAMA_VOCAB_PRE_TYPE_QWEN2)"
if tk.pre_pattern == QWEN2_PATTERN
Expand Down
Loading