tokenizers v1: encode, decode and scaling, measured
tokenizers v1 encodes text 3 to 30 times faster than v0.23 single-threaded on an Apple M4 Max and scales at 76% of linear across eight cores, while producing identical token IDs and keeping the same API. The gains come from replacing regex pre-tokenization with SIMD bitstream operations (bitcannon) for common BPE patterns, a thread-local word cache for repeated pre-tokens, an allocation-free merge loop using an intrusive linked list in a scratch buffer with ranks packed into 64-bit integers, batched model calls, and per-thread sub-pools for parallel encoding. The benchmark methodology separates load time, verifies output by hashing IDs, pins to physical cores, and warns that 'warm' benchmarks on repeated versus distinct documents measure very different workloads.
Related posts
- Announcing pg_tiktoken: A Postgres Extension for Fast BPE Tokenization
Neon mediumAdept
pg_tiktoken is a Postgres extension on Neon that wraps OpenAI's tiktoken BPE tokenizer, exposing tiktoken_encode (returns token IDs) and tiktoken_count (returns token counts) for encodings such as cl100k_base, p50k_base, p50k_edit and r50k_base or their model names. A practical pattern stores chat message history with a precomputed n_tokens column, then uses a window-function cumulative sum ordered by recency to select the most recent messages that fit within a model's context budget (MAX_HISTORY_TOKENS = model max minus system and completion tokens) before calling gpt-3.5-turbo.
- Tokenization in Transformers v5: Simpler, Clearer, and More Modular
Hugging Face mediumAdeptTransformers v5 redesigns tokenizers so that tokenizer architecture (normalizer, pre-tokenizer, model, post-processor, decoder) is separated from the trained vocabulary, much as PyTorch separates model architecture from weights. The walkthrough covers the tokenization pipeline stages, the BPE, Unigram and WordPiece algorithms, and how the transformers wrapper adds chat templates, special tokens, truncation and padding on top of the Rust tokenizers library. It also lays out the class hierarchy: PreTrainedTokenizerBase as the common interface, with TokenizersBackend, PythonBackend and SentencePieceBackend beneath it. The v5 changes consolidate on a single fast backend and make tokenizers easier to inspect, customize and train from scratch.
- Assisted Generation: a new direction toward low-latency text generation
Hugging Face mediumAdeptAssisted generation cuts autoregressive LLM latency by letting a much smaller assistant model with the same tokenizer greedily draft candidate tokens, then verifying them all in a single forward pass of the large model. The large model keeps matching tokens plus the first divergent one. The draft length adapts: it grows by 2 when every candidate matches and shrinks by 1 otherwise. The approach exploits the fact that forward passes are memory-bandwidth bound. In 🤗 Transformers it is exposed through an `assistant_model` argument to `generate` (batch size 1 only) and yields up to 2x speedups, 3x with INT8, and up to 10x when the model relies on memory offloading. It works best on input-grounded tasks like ASR and summarization, and with sampling only at low temperatures.
- Prefill and Decode for Concurrent Requests - Optimizing LLM Performance
Hugging Face mediumAdeptLLM token generation splits into a compute-bound prefill phase, which processes all prompt tokens in parallel to produce the first token, and a memory-bandwidth-bound decode phase, which produces later tokens one at a time. These map to time to first token and time per output token. Static batching leaves the GPU underutilized and delays new requests. Prefill-first continuous batching (vLLM, TGI) minimizes time to first token but pauses running decodes. Chunked prefill interleaves prefill chunks with decode steps, trading a small time-to-first-token increase for smoother decoding. At TNG it raised total throughput by about 50%, and the default chunk size is recommended when load patterns are unpredictable.
- Speculative Decoding for 2x Faster Whisper Inference
Hugging Face mediumAdeptSpeculative decoding speeds up Whisper transcription by about 2x while producing mathematically identical outputs. A fast assistant model drafts candidate tokens and the main model verifies them in a single forward pass. With Distil-Whisper (full encoder, 2 decoder layers) as assistant to Whisper large-v2, a 73-sample LibriSpeech benchmark dropped from 73s to 33s at the same 3.5% WER, with only about 8% extra VRAM from sharing the encoder. For multilingual use, a multilingual checkpoint such as Whisper tiny can serve as assistant, since the only hard constraint is an identical tokenizer. Note that large-v3's expanded vocabulary makes it incompatible with older checkpoints.