GigaToken: Achieving ≈1000× Acceleration in LM Tokenization
GigaToken is a high-performance, drop-in replacement for standard language model tokenizers, designed to push tokenization speeds into the GB/s range.
Important Context: It is worth noting that both tiktoken and HuggingFace (HF) tokenizers are already implemented in multithreaded Rust. GigaToken manages to significantly outperform them regardless.
The library is compatible with a vast array of CPU architectures and supports nearly every widely-used tokenizer currently in existence.
🚀 Getting Started
Installation
To integrate GigaToken into your environment, simply run:
pip install gigatoken
Setup Checklist
🛠 Usage Patterns
GigaToken offers two distinct ways to operate: a Compatibility Mode for ease of integration and a Native API for maximum throughput.
1. Compatibility Mode (The "Easy" Path)
This mode allows you to swap your existing tokenizer with GigaToken with minimal code changes.
import gigatoken as gt
# For HuggingFace users
hf_tokenizer = ...
tokenizer = hf_tokenizer.as_hf()
tokens = tokenizer.encode_batch(["This is a test string", "And here is another"])
# For tiktoken users
tiktokenizer = ...
tokenizer = tiktokenizer.as_tiktoken()
tokens = tokenizer.encode_batch(["This is a test string", "And here is another"])
Nuance Note: While GigaToken strives for exact output parity with HF tokenizers in this mode, achieving this precision comes at a zero non-negligible performance cost. You will still see massive gains, but you won't hit the peak 1000× speedup.
2. GigaToken Native API (The "Fastest" Path)
To unlock the full potential of the Rust backend, use the native API. This allows the system to read data directly from disk, bypassing Python's overhead and maximizing parallelism.
import gigatoken as gt
# Initialize using an HF model identifier
tokenizer = gt.Tokenizer("Qwen/Qwen3-8B")
# Define a file source with a specific separator
file_source = gt.TextFileSource(["owt_train.txt"], separator=b"|endoftext|")
# Execute high-speed encoding
tokens = tokenizer.encode_files(file_source)
Data Flow Comparison
📊 Performance Benchmarks
The following tests were conducted using the owt_train.txt dataset (size: 11.9 GB).
Hardware: AMD EPYC 9565 (144 Cores)
| Tokenizer | GigaToken | HF Tokenizers | tiktoken | vs HF | vs tiktoken |
|---|
| GPT-2 | 24.53 GB/s | 24.8 MB/s | 36.0 MB/s | 989× | 681× |
| Phi-4 | 24.00 GB/s | 29.9 MB/s | — | 801× | — |
| GPT-OSS | 23.96 GB/s | 49.7 MB/s | 42.8 MB/s | 482× | 560× |
| OLMo 2/3 | 23.06 GB/s | 27.7 MB/s | — | 833× | — |
| Nemotron 3 | 22.79 GB/s | 49.4 MB/s | — | 462× | — |
| Qwen 3 | 22.16 GB/s | 34.2 MB/s | — | 648× | — |
| Llama 3/3.1/3.2 | 22.15 GB/s | 48.5 MB/s | — | 457× | — |
| GLM 5 | 20.97 GB/s | 74.8 MB/s | — | 280× | — |
| Llama 3.3 | 20.82 GB/s | 48.3 MB/s | — | 431× | — |
| Llama 4 | 20.77 GB/s | 72.7 MB/s | — | 286× | — |
| GLM 4 | 20.61 GB/s | 72.3 MB/s | — | 285× | — |
| Phi-4-mini | 20.05 GB/s | 27.6 MB/s | — | 726× | — |
| DeepSeek V3/R1/V4 | 19.69 GB/s | 26.2 MB/s | — | 750× | — |
| Qwen 2/2.5 | 19.12 GB/s | 27.7 MB/s | — | 691× | — |
| Kimi K2 | 18.85 GB/s | — | — | — | — |
| Qwen 3.5/3.6 | 15.49 GB/s | 27.7 MB/s | — | 558× | — |
| Gemma 4 | 4.82 GB/s | 334.1 MB/s | — | 14× | — |
| ModernBERT | 4.18 GB/s | 26.9 MB/s | — | 155× | — |
| Mistral 7B v0.3 | 3.57 GB/s | 354.7 MB/s | — | 10× | — |
| TinyLlama/Phi-3 | 3.48 GB/s | 323.6 MB/s | — | 11× | — |
| CodeLlama | 3.47 GB/s | 347.4 MB/s | — | 10.0× | — |
| Gemma 3 | 3.43 GB/s | 357.2 MB/s | — | 9.6× | — |
| Gemma 1 | 2.51 GB/s | 342.2 MB/s | — | 7.3× | — |
Hardware: Apple M4 Max (16 Cores)
| Tokenizer | GigaToken | HF Tokenizers | tiktoken | vs HF | vs tiktoken |
|---|
| GPT-2 | 8.79 GB/s | 6.9 MB/s | 62.8 MB/s | 1,268× | 140× |
| Nemotron 3 | 7.82 GB/s | 10.9 MB/s | — | 715× | — |
| Phi-4 | 7.76 GB/s | 7.7 MB/s | — | 1,012× | — |
| Llama 3/3.1/3.2 | 7.60 GB/s | 11.2 MB/s | — | 676× | — |
| OLMo 2/3 | 7.56 GB/s | 5.8 MB/s | — | 1,299× | — |
| Llama 3.3 | 7.50 GB/s | 15.7 MB/s | — | 479× | — |
| Phi-4-mini | 6.97 GB/s | 7.2 MB/s | — | 964× | — |
| Kimi K2 | 6.88 GB/s | — | — | — | — |
| Llama 4 | 6.81 GB/s | 11.6 MB/s | — | 590× | — |
| Qwen 2/2.5 | 6.37 GB/s | 5.8 MB/s | — | 1,105× | — |
| Qwen 3 | 6.36 GB/s | 6.9 MB/s | — | 918× | — |
| Qwen 3.5/3.6 | 6.31 GB/s | 6.3 MB/s | — | 994× | — |
| GPT-OSS | 6.20 GB/s | 20.2 MB/s | 87.2 MB/s | 306× | 71× |
| GLM 4 | 6.17 GB/s | 15.8 MB/s | — | 392× | — |
| DeepSeek V3/R1/V4 | 5.68 GB/s | 7.2 MB/s | — | 788× | — |
| GLM 5 | 5.55 GB/s | 12.2 MB/s | — | 456× | — |
| ModernBERT | 2.64 GB/s | 5.8 MB/s | — | 452× | — |
| Mistral 7B v0.3 | 1.99 GB/s | 95.1 MB/s | — | 21× | — |
| Gemma 4 | 1.82 GB/s | 85.2 MB/s | — | 21× | — |
| CodeLlama | 1.73 GB/s | 80.2 MB/s | — | 22× | — |
| TinyLlama/Phi-3 | 1.69 GB/s | 80.1 MB/s | — | 21× | — |
| Gemma 1 | 1.42 GB/s | 85.7 MB/s | — | 17× | — |
| Gemma 3 | 1.38 GB/s | 82.2 MB/s | — | 17× | — |
Hardware: AMD Ryzen 7 9800X3D (16 Cores)
| Tokenizer | GigaToken |