tokenizers
Library Featured
Fastest implementation of the most used tokenizers in AI.
- Downloads
- 7,490,451
- Dependents
- 1,021
- Stars
- 11,230
- Forks
- 1,246
- Contributors
- 147
- Commits
- 2,212
- Latest release
- 0.23.2 Β·
About
The SOTA tokenization library on all languages, all models, all hardwares.
Our goal with tokenizers is to develop and maintain the industry's standard tokenization engine, making it the defacto place for everyone to contribute to the whole ecosystem.
Release candidate: v1.0.0.rc.x
As we are switching from 0.23 to v1.0.0, the current library does not ship all features. If you are worried, check the v1 features section for more details of what we are bringing back. We will publish a blog about what breaking changes we introduced. We strived to keep them as small as possible.
Installation
pip install --pre tokenizers
For Rust, add the crate to your Cargo.toml:
[dependencies]
tokenizers = "1.0.0"
Training (train) and downloading from the Hub (http) are opt-in features. The crate's
Using the crate section lists every feature and how to
build a smaller binary.
Read the full README
Usage
>>> from tokenizers import Tokenizer
>>> tokenizer = Tokenizer.from_pretrained("meta-llama/Llama-3.1-8B") # or .from_file(path)
>>> compiled = tokenizer.compile()
>>> compiled.encode("Hello, y'all! How are you π ?")
Encoding(ids=[128000, 9906, 11, 379, 65948, 0, 2650, 527, 499, 27623, 223, 949], type_ids=[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], attention_mask=[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1])
>>> compiled.encode(("What is this?", "A pair.")).type_ids
[0, 0, 0, 0, 0, 1, 1, 1, 1]
>>> compiled.tokenize("Hello")
['<|begin_of_text|>', 'Hello']
>>> compiled.decode([15339, 1917])
'hello world'
>>> compiled.decode_tokens(compiled.encode("Hello"))
['<|begin_of_text|>', 'Hello']
Tokenizer holds the tokenizer.json config and can be edited (e.g. tokenizer.truncation = ...);
compile() builds the CompiledTokenizer that encodes and decodes.
Performances
For more details, checkout https://huggingface-tokenizers-v1.static.hf.space/index.html.
Bindings
| status | |
|---|---|
| Rust | β reference implementation |
| Python | β |
| Node.js | β |
| WebAssembly | β
tokenizers-wasm on npm |
| C / C++ / Java / Go/ etc | π§ planned |
| Ruby | community, external repo |
v1.0.0 roadmap:
As we work toward v1, we are gonna bring back the entire python API that allows transformers' style of interacting with a tokenizer object:
TODOS:
Python Bindings
- Bring training back: this should be easy, but we want the perfs gains to come as well.
- Batch encoding API with zero-copy views on encoded ids
- dlpack API for torch / JAX / numpy interop.
- Composition: edit components of the pipeline (
tokenizer.normalizer = [...]). The editableTokenizerspec andcompile()have landed; per-component handles are next. tokenizer.saveto persist a modified or trained tokenizer on disk.role_to_tokenoverride.- Bring back offset output: this should be useful for people training.
- Windowing / stride in encode.
decode_stream.
Rust core
bitnorm: more performance from optimized normalization, as this will bring breaking changes we want to make sure it gets to v1.- Windowing (truncation with stride).
- Improve training performance
- Improve decode performance
- Offset tracking
- Padding: 2D flat buffer
- Wordcache:
shrnvs emulated movemask - Fix ModernBERT / OLMo load failure ("64-bit hash collision").
- Unroll more regex: we need to cover the most used ones, we might have missed one or two.
Other
- C & C++ bindings for loading, encode and decode APIs
After 1.0.0
- Improve / rewrite the
bitcannoncrate - Java, Go, Swift... bindings, supported by the C bindings
tk-devicesβ exploratory GPU encoding and batch decoding that keeps text and ids on the device: upload the vocabulary once, compute output positions in parallel, gather the bytes on the GPU. An optional component aimed at large batches, subject to prototyping and measurement.
Crate details
Crate size
Sub-crates
tk-encode β the inference engine
The models (BPE, Unigram, WordPiece, WordLevel) and the full pipeline: Normalizer,
PreTokenizer, Model, PostProcessor, Decoder.
Why separate: you don't need all features to serve a model in production settings. Splitting it from training means a serving binary never links a trainer, a corpus reader, legacy converters, etc.
bitcannon β bitstream pre-tokenization
Unicode tag classification plus pre-tokenization as a bitstream program. Follows Interleaved Bitstream Execution for Multi-Pattern Regex Matching on GPUs
(MICRO'25, 10.1145/3725843.3756052) but we added our own algorithm to make sure we don't need a parabix engine.
Characters are first classified into "tags", which use a sparse table generated when compiling bitcannon. This means there are 0 depencencies to the heavy unicode tables.
Ships byte-exact grammars for gpt2 / ByteLevel, cl100k, o200k, tekken, deepseek and kimi-k2. The classes or tags each have a high and low nibble (encoded on a u8), and carry refinement when needed. Using u8 tags allows us to leverage less bitsream, meaning have a simpler / faster pre tokenization.
Why separate: we just thought it might be useful to some people someday. As far as we know, this implementation is the fastest for every single pretokenizer regex on CPU.
tk-serialize β the reader
from_json_file turns a canonical tokenizer.json into a PipelineTokenizer.
Why separate: this just makes it optional for some usecases!
tk-convert β the upgrade pass
canonicalize_file rewrites legacy a tokenizer.json written by any older version of this library into
the canonical form the reader accepts. A pure JSONβJSON rewrite; it depends on nothing but
std::path and serde_json.
Why separate: every config ever published stays readable without the runtime carrying a decade of compatibility branches. But, the legacy code amounted to quite a lot of the final crate size. Disabling it allows on device builds to be smaller.
tk-train β the training half
The Trainer trait, every concrete *Trainer, TrainerWrapper and the Trainable extension.
The tokenizers crate re-exports it behind the train feature, which is off by default. It
trains only the models whose feature is on (bpe, unigram, wordpiece, wordlevel). Add
esaxx_fast for the C++ suffix array behind Unigram training.
Why separate: training is a batch job on a workstation; inference is a hot loop in a server. They have opposite constraints, so they get opposite dependency budgets.
bitmap_gen β dev-only table generator
cargo run -p bitmap_gen regenerates bitcannon's committed classify tables from unicode-properties, emitting one Atom tag per codepoint.
Why separate β this is what buys the zero Unicode dependency. unicode-properties is a
dependency of this crate and of nothing else: the tables it produces are checked into
bitcannon/src/classify/atom_tables.rs as ordinary source, so the Unicode data is resolved once, at
development time, by a crate that is never linked into anything that ships and is never published.
No build script either β bitcannon compiles with no code generation step, and a release binary
contains the tags without containing a Unicode crate to derive them. The release workflow re-runs
the generator and fails if the committed table differs, so "baked" cannot silently mean "stale".
tokenizers β umbrella
A thin re-export so existing tokenizers::β¦ paths keep working. Depend on this one unless you know
you want less.
Hardware
No SIMD is required. Every kernel has a portable path that is always compiled and is the byte-exact test oracle for its vectorised siblings, so correctness never depends on a kernel being present β only throughput does.
Which ops are hardware-adapted
| op | aarch64 | x86_64 | wasm32 | portable fallback |
|---|---|---|---|---|
| Unicode atom classify | NEON (baseline) | AVX-512 VBMI β SSE4.1/SSSE3, runtime-detected | SIMD128 | classify_scalar |
| bitstream block build | NEON | SSE/AVX | β | build_block_scalar |
| literal & added-token scan | NEON | x86_64 | β | scalar |
| vocab bucket nibble match | NEON | β | β | scalar |
aarch64 selects at compile time (NEON is baseline). x86_64 dispatches at runtime via
is_x86_feature_detected!, so one binary covers every x86_64 CPU since 2008. wasm32 needs the
simd128 target feature; without it, the scalar walk.
Acknowledgements
This work stands on the shoulders of a lot of open source projects. Thanks to all of them for their great work.
gigatoken, tiktoken, kitoken, tokie, fastokens, wordchipper and ai-tokenizer each pushed on what a fast tokenizer can be; we read that work, and several of the ideas above reached us because another project showed they were worth trying.
Compatibility
- Runs on
- GPU support unknown
What shows it
- no dependency or feature matches a backend row
- Native code
- Required
- Binds native code: tikv-jemalloc-sys, onig_sys (feature default)
- Python bindings
- No Python binding crate found
- License
- Apache-2.0
Compare with similar projects
Order: strongest tier first, then most downloads, then name, with unmeasured values last. A library counts downloads over 30 days. An app counts binary downloads per release. An app with none counts its crate downloads over 30 days. ML Rust runs this catalogue, so its closest project always gets a row.
| Project | Downloads | Dependents | Stars | Latest release | Runs on (GPU) | Native code | License |
|---|---|---|---|---|---|---|---|
|
Fastest implementation of the most used tokenizers in AI. |
7,490,451 downloads over 30 days | 1,021 | 11,230 | 0.23.2 | GPU support unknown | Binds native code: tikv-jemalloc-sys, onig_sys (feature default) | Apache-2.0 |
|
tiktoken-rs Featured
Library for encoding and decoding with the tiktoken library in Rust |
3,939,182 downloads over 30 days | 449 | 410 | 0.12.1 | GPU support unknown | No native code found | MIT |
|
A rust implementation of some popular snowball stemming algorithms |
5,399,112 downloads over 30 days | 128 | 136 | 1.2.0 | GPU support unknown | No native code found | BSD-3-Clause OR MIT |
|
splintr Listed
Tokenizer for Rust and Python: pure Rust by default, with 18 bundled vocabularies and four backends covering BPE, SentencePiece and WordPiece. Its output matches Hugging Face tokenizers id for id on 14 model families, including GPT-2, Qwen, Whisper, T5 and BERT. Python bindings |
8,204 downloads over 30 days | 7 | 63 | 0.22.2 | GPU support unknown | Binds native code: pcre2-sys (feature pcre2) | MIT |
|
chunk Listed
The fastest semantic text chunking library β up to 1TB/s chunking throughput |
5,407 downloads over 30 days | 8 | 361 | 0.10.2 | GPU support unknown | No native code found | Apache-2.0 OR MIT |
|
From-scratch pure-Rust SentencePiece inference (encode/decode), differentially verified against the upstream C++/Python implementation. |
8,442 downloads over 30 days | 3 | 1 | 0.1.1 | GPU support unknown | No native code found | Apache-2.0 |
|
π¦ A Rust implementation of a RoBERTa classification model for the SNLI dataset |
Not measured | Not applicable | 13 | Not measured | Not measured | Not measured | None stated |
Why FeaturedIt passes every Featured gate.
What it meets
- It has 597 active dependents and 555 new dependents in 365 days. Featured needs 11 active dependents or 9 new dependents in 365 days.
- Active dependents are at 100% of their peak. Featured needs at least 50%.
- Docs are present. The release commit or a manifest ties the crate to the repository.
- No vulnerability advisory stays unpatched past the grace window. At least one version is neither a prerelease nor 0.0.x.
- The last activity is on 6 Nov 2026, 3 days ago. The rules expect an update within 1200 days. Dormancy rule
What else the check found
- The latest release requires the deprecated dependency paste. RUSTSEC-2024-0436 Rot signals rule
Exact rules: Featured library. The check on applied thresholds version 9.
Every rule outcome, as the check records it
expected-interval: version 0.23.2 base 300, doubled for 7490451 downloads per month, doubled for 597 active users: E = 1200 daysdormancy: last activity 2026-11-06, 3 days ago, E = 1200: activerot: deprecated requirement `paste (RUSTSEC-2024-0436, https://rustsec.org/advisories/RUSTSEC-2024-0436.html)`featured: featured: active_users 597, new_adopters 555.33, former_glory 1
Crates7 crates
Measurements and sources
Each signal row shows the raw value, its source and the fetch date. The Sources list gathers every distinct source on this page. Movement needs more history.
Sources6 sources
- Description: the crates.io description
- crates.io database dump, fetched
- RustSec advisory database, fetched
- GitHub repository, fetched
- crates.io package, fetched
- GitHub contributors, fetched
Adoption597 active dependents, 555 new dependents in 365 days1 not measured
| Signal | Value | Source | Fetched | Counts |
|---|---|---|---|---|
| Active dependents | 597 | crates.io database dump | Yes | |
| New dependents (365 days) | 555.3333 | crates.io database dump | Yes | |
| Peak active dependents | 592.5 | crates.io database dump | Yes | |
| Active dependents as a share of the peak | 1 | crates.io database dump | Yes | |
| Binary downloads per release | Not measured | Yes |
MaintenanceLatest human commit: 3 days ago3 not measured
| Signal | Value | Source | Fetched | Counts |
|---|---|---|---|---|
| Latest human commit | 2026-11-06 | GitHub repository | Yes | |
| Latest release | 2026-10-19 | crates.io database dump | Yes | |
| First release | 2019-08-08 | crates.io database dump | Yes | |
| Latest version | 0.23.2 | crates.io database dump | Yes | |
| Days the oldest outside issue waits for a reply | 44 | GitHub repository | Yes | |
| Maintainer replies over 365 days | 28 | GitHub repository | Yes | |
| Repository archived | false | GitHub repository | Yes | |
| Repository gone | false | GitHub repository | Yes | |
| Release commit or manifest in the repo | true | crates.io package | Yes | |
| Published docs | true | crates.io database dump | Yes | |
| Latest release fails cargo check | Not measured | Yes | ||
| Build check date | Not measured | Yes | ||
| Build check toolchain | Not measured | Yes |
SecurityUnpatched vulnerabilities: none
| Signal | Value | Source | Fetched | Counts |
|---|---|---|---|---|
| Unpatched vulnerabilities past the grace window | none | RustSec advisory database | Yes | |
| RustSec unmaintained advisory | none | RustSec advisory database | Yes | |
| Deprecation notice | none | crates.io database dump | Yes | |
| Deprecated requirement | paste (RUSTSEC-2024-0436, https://rustsec.org/advisories/RUSTSEC-2024-0436.html) | crates.io database dump | Yes |
Distribution42 releases, 7,490,451 downloads over 30 days5 not measured
| Signal | Value | Source | Fetched | Counts |
|---|---|---|---|---|
| Releases | 42 | crates.io database dump | Yes | |
| Downloads over 30 days | 7490451 | crates.io database dump | Yes | |
| Binary downloads over the last 3 releases | Not measured | Yes | ||
| Homebrew installs on request over 365 days | Not measured | Yes | ||
| Repology repository families | Not measured | Yes | ||
| Docker pull growth over 90 days | Not measured | Yes | ||
| Docker pulls at the growth baseline | Not measured | Yes | ||
| Every version a prerelease | false | crates.io database dump | Yes | |
| Every version 0.0.x | false | crates.io database dump | Yes | |
| Every version yanked | false | crates.io database dump | Yes | |
| Crate deleted from crates.io | false | crates.io database dump | Yes |
Repository11,230 stars, 1,246 forks, 147 contributors, 2,212 commits. Stars alone never qualify a project.
| Signal | Value | Source | Fetched | Counts |
|---|---|---|---|---|
| GitHub stars | 11230 | GitHub repository | Yes β one part of the repository route | |
| GitHub forks | 1246 | GitHub repository | Yes β one part of the repository route | |
| Contributors with a GitHub account | 147 | GitHub contributors | Yes β one part of the repository route | |
| Commits on the default branch | 2212 | GitHub repository | No | |
| Repository's main crate left out of the entry | none | crates.io database dump | Yes |
Facts that never count
| Signal | Value | Source | Fetched | Counts |
|---|---|---|---|---|
| License | Apache-2.0 | crates.io database dump | No | |
| Runs on, from listed crates and their direct dependencies | GPU support unknown | crates.io database dump | No | |
| What shows each backend | no dependency or feature matches a backend row | crates.io database dump | No | |
| Native code, from listed crates and their dependencies | Binds native code: tikv-jemalloc-sys, onig_sys (feature default) | crates.io database dump | No | |
| Python bindings, from direct dependencies of listed crates | No Python binding crate found | crates.io database dump | No | |
| Crates that depend on a listed crate directly | 1021 | crates.io database dump | No |
Corrections and review history
No correction applies to this entry.
Judgments
A judgment enters only through an approved issue and a merged pull request.
No judgment applies to this entry.