StackMap
Subscribe
Explore / gigatoken
marcelroed

gigatoken

Tokenization at GB/s: ~1000x faster than HuggingFace tokenizers with drop-in compatibility modes for HF and tiktoken — Rust reading your files directly. pip install gigatoken.

3,486 167 Rust MITupdated yesterday
Curator's take

For anyone tokenizing serious corpora, this deletes a pipeline stage from your critical path: the native API reads files directly in Rust and saturates CPUs (the benchmark honestly notes HF and tiktoken are ALREADY multithreaded Rust — the 1000x is architecture, not language), and compatibility modes make adoption a two-line change with exact-output matching. NOT magic everywhere: compat mode costs real speed (the 1000x needs the native file-reading API), Python-object round-trips eat the gains, and if you tokenize kilobytes per request at inference time, none of this matters — it's a data-prep tool, not a serving optimization.

Mapped by ShipWithAI editors · links verified
README.md

Gigatoken

~1000x faster than HuggingFace's tokenizers, drop-in replacement.

Tokenize your text data at GB/s!

GPT-2 Speedup

Note that both HF tokenizers and tiktoken are already running multithreaded Rust!

What is Gigatoken?

Gigatoken is the fastest tokenizer for language modeling. It supports a wide range of CPU hardware, and nearly all commonly used tokenizers. See the Benchmarks section for detailed throughput numbers across tokenizers and CPUs.

Installation

pip install gigatoken

Usage

Gigatoken can be used with its own API, or in compatibility mode with HuggingFace Tokenizers or Tiktoken.

Compatibility Mode (Easiest)

import gigatoken as gt

# Minimum change from existing HuggingFace tokenizers usage (compatibility mode)
hf_tokenizer = ...
tokenizer = gt.Tokenizer(hf_tokenizer).as_hf()

# tokenizer can be used in the same contexts as hf_tokenizer
tokens = tokenizer.encode_batch(["This is a test string", "And here is another"])

# OR with tiktoken
tiktokenizer = ...
tokenizer = gt.Tokenizer(tiktokenizer).as_tiktoken()

# Now works like existing tiktoken tokenizers
tokens = tokenizer.encode_batch(["This is a test string", "And here is another"])

A substantial amount of effort has been put into making sure the outputs match exactly with what you would get with HuggingFace Tokenizers in this setting, but this is at a non-negligible cost to performance. You can still expect way faster performance across the board, but not quite the 1000x you will get with the Gigatoken API.

Gigatoken API (Fastest)

import gigatoken as gt

tokenizer = gt.Tokenizer("Qwen/Qwen3-8B")  # Accepts HF model names
file_source = gt.TextFileSource(["owt_train.txt"], separator=b"<|endoftext|>")
tokens = tokenizer.encode_files(file_source)

Using the Gigatoken API lets the Rust implementation read data directly, and skips as much overhead as possible while allowing for maximum parallelism. Keep in mind that passing Python data structures through this API still incurs the overhead of reading from Python.

Benchmarks

Encoding throughput on owt_train.txt (11.9 GB) — AMD EPYC 9565 72-Core Processor x 2 sockets (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 (Llama 2) 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×
Encoding throughput on owt_train.txt (11.9 GB) — Apple M4 Max (16 cores)

| Tokenizer | gigatoken | HF tokenizers | tiktoken | vs HF | vs tiktoken | |---|---:

Continue your stack

What teams reach for next — and why each earns a place beside gigatoken. Ranked by curator confidence.