GigaToken: ~1000x faster Language model tokenization
TL;DR Highlight
Rewriting the tokenizer with SIMD and caching made it up to 1,299x faster than HF tokenizers
Who Should Read
A data or ML infrastructure developer whose preprocessing of hundreds of GB of text for training is too slow
Core Mechanics
- 24.53 GB/s on GPT-2
- Measured on owt_train.txt (11.9 GB) with an AMD EPYC 9565 (144 cores).
- In the same setup HF tokenizers hit 24.8 MB/s and tiktoken 36.0 MB/s.
- SIMD replaces the regex engine
- Pretokenization (the first split into word-like chunks), usually left to a regex engine, is hand-written with SIMD.
- Branching is minimized and each pretoken's encoding is looked up from a cache.
- Speedup varies a lot by tokenizer
- On Apple M4 Max, OLMo 2/3 is 1,299x vs HF and GPT-2 is 1,268x.
- Gemma 1 gets 17x on the same chip and 13x on the Ryzen 9800X3D.
- Compatibility mode is slower than the headline
- Matching HF and tiktoken output exactly costs performance.
- The README says it is still much faster across the board.
- Top speed needs the dedicated API
- Use gt.Tokenizer with TextFileSource so Rust reads files directly.
- This cuts Python overhead and communication between threads.
- Known limits are clear
- SentencePiece is less optimized and WordPiece is unsupported.
- CJK-heavy data is much slower and Windows is barely tested.
Community Reactions
- Tokenization is under 0.1% of inference time, one commenter noted
- They said the gain is small for inference.
- Others said it should help workloads that only tokenize.
- Offline training data prep is the real use, per commenters
- Tokenizing terabyte-scale corpora saves time and possibly money.
- It speeds up the loop of adjusting datasets.
- Caching and regex replacement seen as reusable ideas
- One commenter cloned the repo after seeing it in the tokenization Discord.
- They said the community wants to learn from these techniques.
- Requests for per-core numbers and compatibility-mode benchmarks
- One commenter wanted the README to focus on per-core performance.
- Another asked whether compatibility mode has its own benchmarks.
How to Apply
- Check your tokenizer with the bench command
- Download the sample file today and run uvx gigatoken bench with your HF model name.
- Turn on --validate to confirm the output matches HF.
- Swap in compatibility mode
- Wrap your HF or tiktoken tokenizer with gt.Tokenizer(...).as_hf() or .as_tiktoken().
- Compare encode_batch output to the old one, then time it.
- Move bulk preprocessing to encode_files
- In pipelines handling multi-GB text files, use TextFileSource and encode_files.
- Set the separator to your document boundary token (e.g. <|endoftext|>).
- Check the limits before adopting
- Check whether you use SentencePiece, WordPiece, or CJK-heavy data.
- If so, benchmark on your own data first and then decide.
Try It
# Paste into a terminal (shell) — check GigaToken speed and correctness via uvx, no install
wget https://huggingface.co/datasets/stanford-cs336/owt-sample/resolve/main/owt_train.txt.gz
gunzip owt_train.txt.gz
uvx --with tokenizers gigatoken bench 'openai-community/gpt2' owt_train.txt --validate --doc-separator "<|endoftext|>"
# Next: replace 'openai-community/gpt2' with the HF model name you use
# See options: uvx gigatoken bench --helpTerminology
Related Papers
A Beginner's Guide to Local AI with Inkling, Qwen, and Unsloth
Install Unsloth Desktop, load a quantized Qwen model, and share a private ChatGPT-like AI on your home LAN.
Muru – AI-assisted Rust server for Python apps by mod_WSGI's creator
mod_wsgi's creator is building Muru, an AI-assisted Rust ASGI/WSGI server, documenting it in public
87% of the Anthropic power will come from gas and 11% from coal in 2028
Analysis of Anthropic's contracted data centers: 87% gas, 11% coal power in 2028
Anthropic’s Nasdaq debut
Anthropic listed on Nasdaq and closed its first day below its opening price.
OpenAI still has a WebRTC Problem
WebRTC drops late audio, hurting voice AI; MoQ retransmits and buffers instead
Gemini 4 Neon
Gemini 4 Neon cuts cost per task 32% versus Carbon, at $3 input and $15 output per million tokens
AI is killing All About Berlin
After Google AI Overviews, a Berlin guide site lost 70-75% of its traffic.
Not Everything Needs an LLM
PostHog used small decision models to skip 98.7% of expensive LLM calls