You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Performance]: Kimi K2.5/K3 text-only prompts are tokenized through the slow-tokenizer pipeline (~0.5 s per 128K-token prompt) #20533
KimiK25InputProcessor.call_with_text_prompt (also used by KimiK3InputProcessor) tokenizes text-only prompts with self._tokenizer(text_prompt, return_tensors="pt").input_ids[0]. The Kimi K2.5 / K3 tokenizer (TikTokenTokenizer, trust_remote_code) is a slow (pure Python) tokenizer, so this goes through the transformers slow-tokenizer pipeline: a per-character Python trie split on the added tokens, then for every tiktoken id a byte-level token string that convert_tokens_to_ids maps back to the same id, then a BatchEncoding and a tensor. The tiktoken encode inside that pipeline is only a small part of the time.
Measured with transformers 5.5.4 and tiktoken 0.14.0, host CPU only:
prompt
tokenizer(text, return_tensors="pt")
same ids without the per-character / per-token Python work
~130K-token chat prompt (Arm server CPU)
0.57 s
0.055 s
~393K-token chat prompt (Arm server CPU)
1.69 s
0.17 s
383K-token synthetic text with many added tokens, public Kimi-K2.5 tokenizer (x86 Cascade Lake)
4.45 s
0.87 s
This time is spent before the request reaches the executor, so it adds directly to TTFT: about 0.5 s for a 128K-token prompt and about 1.5 s for a 393K-token prompt, roughly 10% of the 128K TTFT of Kimi K3 on Rubin, TP8 across 2 nodes (MNNVL).
Proposal: for text-only prompts, run the same steps as __call__ without the per-character and per-token Python work: split on the added tokens with one regex over the trie's tokens (longest first, leftmost match, like Trie.split), call the tokenizer's own encode on each piece (what its _tokenize calls), map ids through a precomputed id -> token -> id table (the identity for the Kimi vocabulary), and finish with build_inputs_with_special_tokens. Enable it only when the tokenizer has the expected structure (slow tokenizer, transformers' own tokenize / id conversion / model-input methods, model-provided encode, no stripping or single-word added tokens, split_special_tokens off) and a probe string that contains every added token gives the same ids as __call__; otherwise keep __call__. The ids are unchanged by construction. PR to follow.
Activity