Back Home

GitHub Repo

tokenizers v1 release candidate rewrites encoding path, runs 3–30× faster than previous version in M4 Max tests

Hugging Face combines SIMD-based splitting, buffer reuse, and caching to reduce text encoding costs. The benchmarks cover specific tokenization workloads; Python call overhead and end-to-end service gains still require separate testing.

Rohini · CC BY-SA 4.0 · Image source
zh-Hant

Hugging Face released a tokenizers v1 release candidate and benchmark details on September 21, rewriting the CPU execution path that converts text into tokens. In single-threaded tests across ten model families on an Apple M4 Max, the team measured encoding speeds roughly 3 to 30 times those of v0.23. These results apply to the tokenization stage and cannot be directly translated into model generation throughput. [Technical overview](https://huggingface.co/blog/tokenizers-v1)

One change uses bitcannon to handle recognized pre-tokenization rules, applying SIMD bitwise operations to identify text splitting boundaries and reduce the work performed by a general-purpose regular expression engine. BPE merging reuses scratch buffers and tracks adjacent segments by index, reducing the cost of repeated memory allocation and data movement. Unsupported rules still follow the existing regular expression path, so gains vary across models. [Implementation details](https://huggingface.co/blog/tokenizers-v1)

For multithreading, the shared scratch buffer pool is divided into subpools, allowing threads to preferentially reuse their own buffers and text-segment caches while reducing contention on a single lock. The cache stores the token IDs associated with pre-tokenized segments, allowing repeated content to skip another round of merging. When repetition is low, however, cache hits may not sufficiently offset lookup costs. The related pull request also records that an HTTP frontend performing sequential encoding within each connection did not become faster, suggesting that bottlenecks may lie elsewhere. [Concurrency changes](https://github.com/huggingface/tokenizers/pull/2365)

The public tokbench framework provides a starting point for reproducing the tests: vocabulary loading and encoding are timed separately, output IDs are checked using hashes, and results with mismatched outputs are excluded from the rankings. Its documentation specifically notes that text repetition affects caching benefits, and that speedup conclusions cannot be directly carried over between Chinese and English corpora. Some internal corpora are also unpublished, so reproduction efforts should use fixed, accessible datasets and versions. [Benchmark framework](https://github.com/huggingface/tokbench)

For services handling Chinese text, a reasonable validation approach is to include Traditional Chinese, text mixed with code, and both short and long requests; measure encoding time, tail latency, and overall service throughput separately; and verify special tokens, truncation, and offset information. If model computation or network waits account for most of a service's processing time, faster tokenization may have only a limited effect on user-perceived latency. These are deployment evaluation recommendations, not officially verified performance figures for Chinese text.

The current GitHub tag remains `v1.0.0-rc.2`. The maintainers aim to preserve the existing API and token IDs, but the official benchmarks do not include Python wrapper call overhead, and integration with the Transformers ecosystem is listed as future work. Adopters should first pin the release candidate for testing, then track compatibility in the stable release and gains in real applications. [Release announcement](https://github.com/huggingface/tokenizers/releases/tag/v1.0.0-rc.2), [Future plans](https://huggingface.co/blog/tokenizers-v1)

Sources

  1. tokenizers v1: encode, decode and scaling, measured
  2. Release candidate v1.0.0.rc.2
  3. perf(pipeline): give each thread its own scratch sub-pool
  4. tokbench:分詞引擎測試框架