okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
97a50dc24
main
1"""Tests for tools/strata_tokenizer.py: llama.cpp's reference vectors, the piece cache (0.1.41: the ids are the ones the 2merge loop gives, cache cold, warm or switched off), and the incremental prompt encoder, which must give exactly the 3ids of a plain encode. 4 5python -m unittest tools.test_strata_tokenizer -v 6 7The real vocabulary comes from $STRATA_TOKENIZER (a pack's tokenizer/ directory) when set, else from llama.cpp's 8`models/ggml-vocab-qwen35.gguf` next to the gguf-py the tools use ($STRATA_GGUF_PY, third_party/llama.cpp); the 9tests that need it are skipped without one. The chat template's USER_DEFINED tokens (`<think>`, `<tool_call>`, 10...) are added to the llama.cpp vocabulary, which does not have them, as the pack's has. 11""" 12from __future__import annotations 13 14import json 15import os 16import random 17import sys 18import unittest 19from pathlib import Path 20 21ROOT = Path (__file__ ).resolve ().parents [1 ] 22sys .path .insert (0 ,str (ROOT / "tools" )) 23sys .path .insert (0 ,str (ROOT )) 24import strata_tokenizer as ST # noqa: E402 25 26ADDED = ["<think>" ,"</think>" ,"<tool_call>" ,"</tool_call>" ,"<tool_response>" ,"</tool_response>" , 27"<|vision_start|>" ,"<|image_pad|>" ,"<|vision_end|>" ] 28 29 30def vocab_gguf ()-> Path | None : 31cands = [os .environ .get ("STRATA_GGUF_PY" ),ROOT / "third_party" / "llama.cpp" / "gguf-py" ,"/opt/llama.cpp/gguf-py" ] 32for c in cands : 33if c and (Path (c ).parent / "models" / "ggml-vocab-qwen35.gguf" ).is_file (): 34return Path (c ).parent / "models" / "ggml-vocab-qwen35.gguf" 35return None 36 37 38def load_tokenizer (): 39pack = os .environ .get ("STRATA_TOKENIZER" ) 40if pack and (Path (pack )/ "vocab.json" ).is_file (): 41t = Path (pack ) 42vocab = json .loads ((t / "vocab.json" ).read_text (encoding = "utf-8" )) 43tokens = [None ]* len (vocab ) 44for s ,i in vocab .items (): 45tokens [i ]= s 46return ST .Tokenizer (tokens , (t / "merges.txt" ).read_text (encoding = "utf-8" ).split ("\n" ), 47json .loads ((t / "token_type.json" ).read_text ())) 48path = vocab_gguf () 49return None if path is None else gguf_tokenizer (path ) 50 51 52def gguf_tokenizer (path ): 53"""llama.cpp's qwen35 vocabulary with the template's added tokens: the one its test vectors were made with.""" 54from gguf_reader import GGUFFile 55md = GGUFFile (path ).metadata 56tokens ,types = list (md ["tokenizer.ggml.tokens" ]),list (md ["tokenizer.ggml.token_type" ]) 57for s in ADDED : 58if s not in tokens : 59tokens .append (s ) 60types .append (4 ) 61return ST .Tokenizer (tokens ,list (md ["tokenizer.ggml.merges" ]),types ) 62 63 64def byte_tokenizer (specials :list [str ])-> ST .Tokenizer : 65"""A vocabulary of the 256 byte tokens and `specials` (CONTROL), no merges: small enough to build per test.""" 66tokens = [ST .BYTE_TO_UNICODE [b ]for b in range (256 )]+ specials 67return ST .Tokenizer (tokens , [], [1 ]* 256 + [3 ]* len (specials )) 68 69 70WORDS = ["the" ,"tokenizer" ," " ," " ,"\n" ,"\n\n" ,"\t" ,"def" ,"f(x):" ,"return" ,"x" ,"==" ,"->" ,"café" , 71"你好" ,"\U0001f600" ,"é" ,"1234" ,"don't" ,"I'm" ,"<|im_" ,"<think" ,"</" ,"tool" ,"_call>" , 72" " ,"\r\n" ,"Hello," ,"world!" ,"<" ,">" ,"|" ," " ,"x" * 70 ] 73 74 75def random_text (rnd :random .Random ,n :int ,specials = ())-> str : 76parts = [] 77for _ in range (n ): 78parts .append (rnd .choice (WORDS )if not specials or rnd .random ()> 0.05 else rnd .choice (specials )) 79if rnd .random ()< 0.5 : 80parts .append (" " ) 81return "" .join (parts ) 82 83 84def conversation_prompts (template ,rnd :random .Random )-> list [tuple [str ,str ]]: 85"""Rendered prompts, in the order a server would see them, from clients that grow a conversation turn after turn, 86use tools, send images, change the start of the prompt, edit an earlier turn, send a shorter conversation, and 87interleave with each other: (what happens, prompt).""" 88out :list [tuple [str ,str ]]= [] 89specials = ["<|im_start|>" ,"<|im_end|>" ,"<think>" ,"</think>" ,"<tool_call>" ,"</tool_response>" ] 90weather = [{"type" :"function" ,"function" : {"name" :"get_weather" ,"description" :"Get the weather" , 91"parameters" : {"type" :"object" ,"properties" : { 92"city" : {"type" :"string" }},"required" : ["city" ]}}}] 93 94def add (what ,msgs ,tools = None ,** kw ): 95out .append ((what ,template .render (msgs ,tools = tools ,** kw ))) 96 97# several turns, with unicode, a literal special token inside the text, and reasoning kept or not 98msgs = [{"role" :"system" ,"content" :"Be brief. Réponds en français si on te parle en français." }] 99for turn in range (6 ): 100msgs .append ({"role" :"user" ,"content" :random_text (rnd ,60 ,specials )+ " é你\U0001f600 " * turn }) 101add (f"turn { turn } " ,msgs ) 102answer = {"role" :"assistant" ,"content" :random_text (rnd ,30 )} 103if turn % 2 : 104answer ["reasoning_content" ]= random_text (rnd ,30 ) 105msgs .append (answer ) 106grown = list (msgs ) 107 108# tools: definitions, a call, its response, then a following turn 109tmsgs = [{"role" :"user" ,"content" :"Weather in Oslo?" }] 110add ("tools 1" ,tmsgs ,weather ) 111tmsgs += [{"role" :"assistant" ,"content" :"" ,"tool_calls" : [{"type" :"function" ,"function" : { 112"name" :"get_weather" ,"arguments" : {"city" :"Oslo" }}}]}, 113 {"role" :"tool" ,"content" :"{\"temp\": 3}" ,"name" :"get_weather" }] 114add ("tools 2" ,tmsgs ,weather ) 115tmsgs += [{"role" :"assistant" ,"content" :"3 degrees." }, {"role" :"user" ,"content" :"And in Bergen? " * 20 }] 116add ("tools 3" ,tmsgs ,weather ) 117 118# images: one per user turn, the placeholder tokens are specials 119imsgs = [] 120for turn in range (3 ): 121imsgs .append ({"role" :"user" ,"content" : [{"type" :"image" ,"source" :f"img { turn } " }, 122 {"type" :"text" ,"text" :f"What is on picture { turn } ?" }]}) 123add (f"images { turn } " ,imsgs ) 124imsgs .append ({"role" :"assistant" ,"content" :"A cat." }) 125 126# the start of the prompt changes (a thinking level, a system message), then the old conversation grows again 127add ("effort changed" ,grown ,reasoning_effort = "low" ) 128add ("system changed" , [dict (grown [0 ],content = grown [0 ]["content" ]+ " Be kind." )]+ grown [1 :]) 129grown .append ({"role" :"user" ,"content" :"one more question" }) 130add ("grown again" ,grown ) 131 132# an earlier turn edited, then a conversation that got shorter, then the full one again 133edited = list (grown ) 134edited [3 ]= dict (edited [3 ],content = edited [3 ]["content" ]+ " (edited)" ) 135add ("edited" ,edited ) 136add ("shorter" ,grown [:5 ]) 137add ("empty user" , [{"role" :"user" ,"content" :"" }]) 138add ("full again" ,grown ) 139return out 140 141 142class Oracle (unittest .TestCase ): 143"""llama.cpp's own tokenizer test vectors for qwen35.""" 144 145def test_llama_cpp_vectors (self ): 146path = vocab_gguf () 147if path is None or not path .with_suffix (".gguf.inp" ).is_file (): 148self .skipTest ("llama.cpp's ggml-vocab-qwen35.gguf test vectors are not here" ) 149tk = gguf_tokenizer (path )# not $STRATA_TOKENIZER: the vectors belong to this vocabulary 150inp = path .with_suffix (".gguf.inp" ).read_text (encoding = "utf-8" ).split ("\n__ggml_vocab_test__\n" ) 151out = path .with_suffix (".gguf.out" ).read_text (encoding = "utf-8" ).split ("\n" ) 152n = 0 153for text ,want in zip (inp ,out ): 154if text .endswith ("\n__ggml_vocab_test__" ): 155text = text [:- len ("\n__ggml_vocab_test__" )] 156self .assertEqual (tk .encode (text ), [int (x )for x in want .split ()],repr (text [:40 ])) 157n += 1 158self .assertGreater (n ,40 ) 159 160 161class Marks (unittest .TestCase ): 162@classmethod 163def setUpClass (cls ): 164cls .tk = load_tokenizer () 165if cls .tk is None : 166raise unittest .SkipTest ("no tokenizer (set STRATA_TOKENIZER or STRATA_GGUF_PY)" ) 167 168def test_marks (self ): 169text = "a<|im_start|>user\nhi<|im_end|>\n<think>\n" 170ids ,marks = self .tk .encode_marked (text ,parse_special = True ) 171self .assertEqual (ids ,self .tk .encode (text ,parse_special = True )) 172self .assertEqual ([m [0 ]for m in marks ], [text .index ("user" ),text .index ("<|im_end|>" )+ len ("<|im_end|>" ), 173len (text )- 1 ]) 174for end ,n in marks :# each mark: the ids of the text up to it 175self .assertEqual (ids [:n ],self .tk .encode (text [:end ],parse_special = True )) 176 177 178class Prompts (unittest .TestCase ): 179"""PromptEncoder: the ids of a plain encode, whatever the earlier prompts were.""" 180 181@classmethod 182def setUpClass (cls ): 183cls .tk = load_tokenizer () 184if cls .tk is None : 185raise unittest .SkipTest ("no tokenizer (set STRATA_TOKENIZER or STRATA_GGUF_PY)" ) 186from serve .frontend import ChatTemplate 187cls .template = ChatTemplate (ROOT / "serve" / "chat_template.jinja" ) 188 189def check (self ,enc ,text ): 190self .assertEqual (enc .encode (text ),self .tk .encode (text ,parse_special = True )) 191 192def test_chat_golden (self ): 193cases = json .loads ((ROOT / "serve" / "chat_golden.json" ).read_text (encoding = "utf-8" )) 194enc = ST .PromptEncoder (self .tk ) 195for c in cases + cases :# the second round finds its own earlier prompts 196if c .get ("rendered" ): 197with self .subTest (case = c ["name" ]): 198self .check (enc ,c ["rendered" ]) 199 200def test_conversations (self ): 201for seed in range (3 ): 202prompts = conversation_prompts (self .template ,random .Random (seed )) 203wants = [self .tk .encode (prompt ,parse_special = True )for _ ,prompt in prompts ] 204for keep in (1 ,2 ,4 ): 205enc = ST .PromptEncoder (self .tk ,keep = keep ) 206for (what ,prompt ),want in zip (prompts ,wants ): 207with self .subTest (seed = seed ,keep = keep ,what = what ): 208self .assertEqual (enc .encode (prompt ),want ) 209 210def test_growing_turn_reuses_the_previous_prompt (self ): 211enc = ST .PromptEncoder (self .tk ) 212msgs = [{"role" :"user" ,"content" :"first question " * 50 }] 213prev = "" 214for turn in range (4 ): 215prompt = self .template .render (msgs ) 216self .check (enc ,prompt ) 217if turn : 218self .assertGreater (enc .last_reused ,len (prev )- 100 ) 219prev = prompt 220msgs += [{"role" :"assistant" ,"content" :f"answer { turn } " }, {"role" :"user" ,"content" :f"question { turn } " }] 221 222def test_prefix_of_an_earlier_prompt_and_unrelated_prompts (self ): 223enc = ST .PromptEncoder (self .tk ,keep = 2 ) 224a = self .template .render ([{"role" :"user" ,"content" :"first question " * 50 }]) 225b = self .template .render ([{"role" :"user" ,"content" :"another conversation" }]) 226c = self .template .render ([{"role" :"user" ,"content" :"a third one" }]) 227for text in (a ,a [:len (a )// 2 ],b ,c ,a ,a + "tail" ,"" ,"<|im_end|>" ,"<|im_end|><|im_end|>x" ): 228with self .subTest (text = text [:30 ]): 229self .check (enc ,text ) 230 231def test_a_read_only_encode_gives_the_ids_and_stores_nothing (self ): 232enc = ST .PromptEncoder (self .tk ) 233a = self .template .render ([{"role" :"user" ,"content" :"first question " * 50 }]) 234enc .encode (a ) 235kept = list (enc .entries ) 236for text in (a + "<|im_start|>user\nand a follow-up<|im_end|>\n" ,a [:len (a )// 2 ],"<|im_end|>x" , 237self .template .render ([{"role" :"user" ,"content" :"another conversation" }])): 238with self .subTest (text = text [:30 ]): 239self .assertEqual (enc .encode (text ,store = False ),self .tk .encode (text ,parse_special = True )) 240self .assertTrue (enc .entries == kept ,"a read-only encode wrote an entry" ) 241self .assertEqual (enc .encode (a + "tail" ,store = False ),self .tk .encode (a + "tail" ,parse_special = True )) 242self .assertGreater (enc .last_reused ,len (a )// 2 ) 243 244def test_the_returned_ids_are_the_callers (self ): 245enc = ST .PromptEncoder (self .tk ) 246text = "<|im_start|>user\nhi<|im_end|>\n" + "and a tail longer than the look-ahead margin. " * 3 247want = self .tk .encode (text ,parse_special = True ) 248got = enc .encode (text ) 249got [0 ]= - 1 # inside the part the next call takes from this one 250got .append (- 1 ) 251self .assertEqual (enc .encode (text ),want ) 252self .assertGreater (enc .last_reused ,0 ) 253 254 255class Margin (unittest .TestCase ): 256"""A special literal that is a prefix of a longer one: cutting at the shorter one's end without the look-ahead 257margin would give different ids.""" 258 259def test_longer_literal_past_the_common_prefix (self ): 260tk = byte_tokenizer (["<|a|>" ,"<|a|>zz" ]) 261enc = ST .PromptEncoder (tk ) 262first = "x<|a|>y" + "<|a|>" * 3 + "q" 263self .assertEqual (enc .encode (first ),tk .encode (first ,parse_special = True )) 264second = "x<|a|>y" + "<|a|>" * 3 + "zz" # shares everything up to the last <|a|> 265got = enc .encode (second ) 266self .assertEqual (got ,tk .encode (second ,parse_special = True )) 267self .assertEqual (got [- 1 ],tk .special_tokens ["<|a|>zz" ]) 268self .assertGreater (enc .last_reused ,0 )# the earlier boundaries were still reused 269 270def test_literal_ending_inside_another (self ): 271tk = byte_tokenizer (["<|a|>" ,"b<|a|>c" ]) 272enc = ST .PromptEncoder (tk ) 273for text in ("zzb<|a|>d" ,"zzb<|a|>c" ,"zzb<|a|>cz<|a|>" ,"zzb<|a|>cz<|a|>b<|a|>c" ): 274with self .subTest (text = text ): 275self .assertEqual (enc .encode (text ),tk .encode (text ,parse_special = True )) 276 277def test_random_specials (self ): 278"""Literals that extend or end inside one another, texts that change right after one of them.""" 279rnd = random .Random (3 ) 280 281def word (lo ,hi ): 282return "" .join (rnd .choice ("<|ab>" )for _ in range (rnd .randint (lo ,hi ))) 283for trial in range (60 ): 284a ,b = word (2 ,4 ),word (2 ,4 ) 285lits = sorted ({a ,a + word (1 ,3 ),b ,word (1 ,2 )+ b + word (0 ,2 )}) 286tk = byte_tokenizer (lits ) 287enc = ST .PromptEncoder (tk ,keep = 3 ) 288pieces = lits + [x [:rnd .randint (1 ,len (x ))]for x in lits ]+ ["x" ,"y" ,"a" ,"|" ] 289base = "" .join (rnd .choice (pieces )for _ in range (60 )) 290for _ in range (30 ): 291cut = rnd .randint (0 ,len (base )) 292text = base [:cut ]+ "" .join (rnd .choice (pieces )for _ in range (rnd .randint (0 ,6 ))) 293self .assertEqual (enc .encode (text ),tk .encode (text ,parse_special = True ), (lits ,text )) 294if rnd .random ()< 0.3 : 295base = text + base [cut :] 296 297 298class CommonPrefix (unittest .TestCase ): 299def test_against_a_loop (self ): 300rnd = random .Random (5 ) 301for _ in range (500 ): 302a = "" .join (rnd .choice ("ab" )for _ in range (rnd .randint (0 ,9000 ))) 303k = rnd .randint (0 ,len (a )) 304b = a [:k ]+ rnd .choice (["" ,"c" ,"cd" ])+ a [k :k + rnd .randint (0 ,50 )] 305want = 0 306while want < min (len (a ),len (b ))and a [want ]== b [want ]: 307want += 1 308self .assertEqual (ST .common_prefix_len (a ,b ),want ) 309self .assertEqual (ST .common_prefix_len (b ,a ),want ) 310 311 312 313def toy ()-> ST .Tokenizer : 314base = [ST .BYTE_TO_UNICODE [b ]for b in range (256 )] 315merges = ["t h" ,"th e" ,"i n" ,"a n" ,"an d" ,"Ġ t" ,"Ġt h" ,"Ġth e" ,"e r" ,"o n" ] 316merges = [m .replace ("Ġ" ,ST .BYTE_TO_UNICODE [32 ])for m in merges ] 317tokens = list (base ) 318for m in merges : 319a ,b = m .split (" " ) 320tokens .append (a + b ) 321return ST .Tokenizer (tokens ,merges ) 322 323 324class PieceCache (unittest .TestCase ): 325def test_same_ids_cold_warm_and_off (self ): 326rng = random .Random (7 ) 327words = ["the" ,"and" ,"in" ,"on" ,"there" ,"other" ,"x" * 70 ,"你好" ,"def" ,"return" ,"\n\n" ," " ] 328text = "" .join (rng .choice (words )+ rng .choice ([" " ,"" ,"\n" ,"\t" ])for _ in range (3000 )) 329a = toy () 330a .PIECE_CACHE_MAX = 0 331want = a .encode (text ) 332b = toy () 333cold = b .encode (text ) 334warm = b .encode (text ) 335self .assertEqual (cold ,want ) 336self .assertEqual (warm ,want ) 337self .assertGreater (len (b ._piece_ids ),0 ) 338self .assertEqual (b .decode (warm ),text ) 339 340def test_the_cache_is_bounded (self ): 341t = toy () 342t .PIECE_CACHE_MAX = 5 343t .encode (" " .join ("w%d" % i for i in range (100 ))) 344self .assertLessEqual (len (t ._piece_ids ),5 ) 345 346 347class ByteCache (unittest .TestCase ): 348def test_decode_before_encode_cold_and_warm (self ): 349t = toy () 350text = "café 日本語 🙂\r\n\x00" 351ids = list (text .encode ("utf-8" ))# toy's first 256 token IDs are the raw bytes 352self .assertEqual (t .decode (ids ,errors = "strict" ),text ) 353self .assertEqual (t .decode (ids ,errors = "strict" ),text ) 354self .assertEqual (t .decode ([]),"" ) 355for i in range (256 ): 356self .assertEqual (t .token_bytes (i ),bytes ([i ])) 357 358def test_invalid_ids_before_and_after_cache_use (self ): 359t = toy () 360for _ in range (2 ): 361for i in (- 1 ,len (t .tokens ),len (t .tokens )+ 100 ): 362with self .assertRaises (IndexError ): 363t .token_bytes (i ) 364self .assertEqual (t .token_bytes (65 ),b"A" ) 365 366def test_instances_with_different_vocabularies_stay_independent (self ): 367tokens = [ST .BYTE_TO_UNICODE [b ]for b in range (256 )] 368a ,b = ST .Tokenizer (tokens , []),ST .Tokenizer (tokens [::- 1 ], []) 369text = "the café 日本語 🙂\n" 370for t in (a ,b ,a ,b ): 371expected = [t .ids [ST .BYTE_TO_UNICODE [byte ]]for byte in text .encode ("utf-8" )] 372self .assertEqual (t .encode (text ),expected ) 373self .assertEqual (t .decode (expected ,errors = "strict" ),text ) 374self .assertEqual (a .token_bytes (0 ),b"\x00" ) 375self .assertEqual (b .token_bytes (0 ),b"\xff" ) 376 377def test_shared_tokenizer_concurrent_first_decode (self ): 378import threading 379from concurrent .futures import ThreadPoolExecutor 380t = toy () 381texts = ["café" ,"日本語" ,"🙂\r\n" ,"\x00plain" ] 382barrier = threading .Barrier (len (texts )) 383def decode (text ): 384ids = list (text .encode ("utf-8" )) 385barrier .wait (timeout = 5 ) 386for _ in range (100 ): 387if t .decode (ids ,errors = "strict" )!= text : 388raise AssertionError ("concurrent decode changed the text" ) 389return text 390with ThreadPoolExecutor (len (texts ))as pool : 391self .assertEqual (list (pool .map (decode ,texts )),texts ) 392 393 394if __name__ == "__main__" : 395unittest .main () 396 397 398class PreTokenizerType (unittest .TestCase ): 399"""P4 (Qwen4 prep): an unknown tokenizer.ggml.pre is refused, never split with another model's rule. The types that were 400accepted before (qwen35, an empty one, anything starting with deepseek) still build and split exactly as they did.""" 401 402def test_known_types (self ): 403self .assertEqual (ST .pre_tokenizer_kind ("qwen35" ),"qwen35" ) 404self .assertEqual (ST .pre_tokenizer_kind (None ),"qwen35" ) 405self .assertEqual (ST .pre_tokenizer_kind ("" ),"qwen35" ) 406for p in ("deepseek3" ,"deepseek-v3" ,"deepseek-llm" ,"deepseek41" ): 407self .assertEqual (ST .pre_tokenizer_kind (p ),"deepseek3" ,p ) 408 409def test_unknown_types_are_refused_with_the_name (self ): 410for p in ("qwen2" ,"qwen3" ,"qwen4" ,"default" ,"gpt2" ,"llama-bpe" ,"joyai-llm" ,"Qwen35" ," qwen35" ): 411with self .subTest (p ): 412self .assertIsNone (ST .pre_tokenizer_kind (p )) 413with self .assertRaises (ST .UnknownPreTokenizer )as cm : 414ST .Tokenizer ([chr (i )for i in range (4 )], [],None ,p ) 415self .assertIn (repr (p ),str (cm .exception )) 416self .assertIsInstance (cm .exception ,ValueError )# callers that catch ValueError keep working 417 418def test_from_gguf_refuses_an_unknown_type (self ): 419import tempfile 420import struct 421from gguf_reader import GGUF_MAGIC 422from gguf_writer import GGUFWriter 423w = GGUFWriter () 424w .add ("tokenizer.ggml.model" ,"gpt2" ) 425w .add ("tokenizer.ggml.pre" ,"qwen4" ) 426w .add ("tokenizer.ggml.tokens" , ["a" ,"b" ],"array:string" ) 427w .add ("tokenizer.ggml.merges" , ["a b" ],"array:string" ) 428with tempfile .TemporaryDirectory ()as d : 429p = w .write (Path (d )/ "x.gguf" ) 430with self .assertRaises (ST .UnknownPreTokenizer ): 431ST .Tokenizer .from_gguf (p ) 432w .add ("tokenizer.ggml.pre" ,"qwen35" ) 433w .add ("tokenizer.ggml.tokens" , ["a" ,"b" ,"ab" ],"array:string" ) 434w .add ("tokenizer.ggml.merges" , ["a b" ],"array:string" ) 435ok = ST .Tokenizer .from_gguf (w .write (Path (d )/ "y.gguf" )) 436self .assertEqual (ok .pre ,"qwen35" ) 437self .assertEqual (ok .encode ("ab" ), [2 ]) 438 439def test_accepted_types_split_as_before (self ): 440rnd = random .Random (7 ) 441toks = [chr (i )for i in range (32 ,127 )]+ ["\n" ,"\t" ,"你" ,"好" ] 442text = "" .join (rnd .choice (toks )for _ in range (400 ))+ "Hello, World 123 你好\n\n x_y" 443a = ST .Tokenizer (toks , [],None ,"qwen35" ) 444self .assertEqual (a ._split (text ),ST .regex .compile (ST .QWEN35_PATTERN ).findall (text )) 445self .assertEqual (ST .Tokenizer (toks , [],None ,None )._split (text ),a ._split (text )) 446self .assertEqual (ST .Tokenizer (toks , [],None ,"" )._split (text ),a ._split (text )) 447d = ST .Tokenizer (toks , [],None ,"deepseek3" ) 448seq = [ST .regex .compile (x )for x in ST .DEEPSEEK3_PATTERNS ] 449self .assertEqual (d ._split (text ),ST ._sequence_findall (seq ,text )) 450self .assertEqual (ST .Tokenizer (toks , [],None ,"deepseek-v3" )._split (text ),d ._split (text ))