Universal, research-grounded tokenizer engine for BPE, WordPiece, and Unigram vocabularies — targeting consumer hardware (AMD Ryzen 5 7600, DDR5-5600, Gen3 NVMe).
Table of Contents
- Overview
- Key Features
- Comparative Benchmark Matrix
- Empirical Benchmark Results
- Roofline Sanity Matrix
- Command Line Interface & Flags
- System Architecture
- AI Use Disclosure & Credit Attribution
- Quick Start & Usage
- Verification & Tests
- Citation & Licensing
Overview
OmniToken is a high-performance, universal tokenization engine written in Rust. It ingests every major tokenizer vocabulary format into one universal intermediate representation (VocabIr) and encodes with a unified automaton that executes BPE, WordPiece, and Unigram in the same trie-walk loop.
- Primary Competitor: gigatoken — BPE engine benchmarked on a 144-core server.
- Our Wedge: Universal format support (BPE, WordPiece, Unigram, tiktoken, SentencePiece binary
.model, GGUF) + inference-time low latency + SWAR/AVX2 pretokenization + hybrid hot-tier cache grounded in PtrHash literature.
Key Features
- ⚡ 1.77+ GB/s Multi-Core Throughput: Scaled across 6 physical cores / 12 SMT threads on consumer DDR5 hardware.
- 🎯 Universal Vocab IR (
vocab-ir): Ingest HuggingFacetokenizers.json(BPE/WordPiece/Unigram), tiktoken.tiktokenfiles, SentencePiece binary.modelprotobuf blobs, and GGUF metadata. - 🔄 Unified Automaton (
walker): One trie walker handles BPE priority queues ($O(N \log M)$ per Zouhar et al.), WordPiece LinMaxMatch ($O(N)$ per Song et al.), and Unigram Viterbi DP. - 🚀 SWAR / SIMD Pretokenizer (
pretokenizer): 256-entry byte-class table with 8-byte u64 branchless SWAR dispatch and AVX2 vectorization (x86-64-v3). - 💎 Hybrid Hot-Tier Cache (
hot-cache): Lock-free RCU double-buffered static tier, automatic background rebuild thread, XXH3-64 fingerprint verification, 64-byte paddedCountMinSketch, and SwissTable fallback. - 📊 Roofline-Grounded Benchmarking (
bench-harness): Automated L3-resident vs DRAM-resident throughput validation against physical hardware bandwidth limits.
Comparative Benchmark Matrix
Hardware Environment: AMD Ryzen 5 7600 (6 Cores / 12 SMT Threads @ 5.1 GHz), Dual-Channel DDR5-5600, Ubuntu Linux 24.04 LTS (WSL2).
Corpus Test Input: GPT-2 standard vocabulary (16.0 MiB text buffer).
Single-Thread & Multi-Thread Throughput Comparison (16.0 MiB Corpus)
========================================================================================
HuggingFace tokenizers (Py) [█░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░] 0.002 GB/s ( 2 MiB/s)
tiktoken (Py / Rust Core) [███░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░] 0.017 GB/s ( 17 MiB/s)
gigatoken (EPYC Server Ref) [████████████████████████░░░░░░░░░░░░░░░░] 0.830 GB/s (830 MiB/s)
OmniToken (1 Thread) [████████░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░] 0.279 GB/s (266 MiB/s)
OmniToken (6 Cores / 12 T) [████████████████████████████████████████] 1.771 GB/s (1689 MiB/s)
========================================================================================
| Tokenizer Engine | Execution Threads | Input Buffer | Wall Time (s) | Throughput (GB/s) | Speedup vs. HF | Speedup vs. tiktoken |
|---|---|---|---|---|---|---|
HuggingFace tokenizers |
1 (Single) | 16.0 MiB | 7.6523s | 0.002 GB/s | 1.0× | 0.12× |
tiktoken |
1 (Single) | 16.0 MiB | 0.9686s | 0.017 GB/s | 8.5× | 1.00× |
gigatoken (EPYC ref) |
1 (Single) | 16.0 MiB | — | 0.830 GB/s | 415× | 48.8× |
| OmniToken (1 Thread) | 1 (Single) | 16.0 MiB | 0.0573s | 0.279 GB/s | 139.5× | 16.4× |
| OmniToken (12 Threads) | 12 (SMT) | 16.0 MiB | 0.0090s | 1.771 GB/s | 885.5× | 104.1× |
Empirical Benchmark Results
1. L3-Resident Regime (4.0 MiB Input ≤ 32MB L3 Cache)
| Threads | Input Size | Wall Time (s) | Throughput (GB/s) | Throughput (MiB/s) | Physical Ceiling | Validation |
|---|---|---|---|---|---|---|
| 1 | 4.0 MiB | 0.0150s | 0.279 GB/s | 266 MiB/s | L3 Bandwidth | ✓ Plausible |
| 2 | 4.0 MiB | 0.0084s | 0.498 GB/s | 475 MiB/s | L3 Bandwidth | ✓ Plausible |
| 4 | 4.0 MiB | 0.0043s | 0.983 GB/s | 937 MiB/s | L3 Bandwidth | ✓ Plausible |
| 6 | 4.0 MiB | 0.0034s | 1.242 GB/s | 1184 MiB/s | L3 Bandwidth | ✓ Plausible |
| 12 | 4.0 MiB | 0.0042s | 0.993 GB/s | 947 MiB/s | L3 Bandwidth | ✓ Saturation Point |
2. DRAM-Resident Regime (64.0 MiB Input > 32MB L3 Cache)
| Threads | Input Size | Wall Time (s) | Throughput (GB/s) | Throughput (MiB/s) | Physical Ceiling | Validation |
|---|---|---|---|---|---|---|
| 1 | 64.0 MiB | 0.2275s | 0.295 GB/s | 281 MiB/s | ≈63–80 GB/s (DDR5-5600) | ✓ Plausible |
| 2 | 64.0 MiB | 0.1344s | 0.499 GB/s | 476 MiB/s | ≈63–80 GB/s (DDR5-5600) | ✓ Plausible |
| 4 | 64.0 MiB | 0.0642s | 1.045 GB/s | 997 MiB/s | ≈63–80 GB/s (DDR5-5600) | ✓ Plausible |
| 6 | 64.0 MiB | 0.0480s | 1.399 GB/s | 1334 MiB/s | ≈63–80 GB/s (DDR5-5600) | ✓ Plausible |
| 12 | 64.0 MiB | 0.0379s | 1.771 GB/s | 1689 MiB/s | ≈63–80 GB/s (DDR5-5600) | ✓ Plausible |
Roofline Sanity Matrix
| Resource | Hardware Spec | Sustained Physical Ceiling | OmniToken Status |
|---|---|---|---|
| L3 Cache | 32 MB shared (Zen 4 CCD) | ~50-cycle latency (~8–9 ns) | Verified L3 resident at 4.0 MiB |
| DRAM | Dual-Channel DDR5-5600 | ≈63–80 GB/s sustained | Verified DRAM resident at 64.0 MiB |
| NVMe | PCIe Gen3 x4 | ≈3.5 GB/s sequential read | In-memory processing path |
| CPU FPU | 6C / 12T Zen 4 | 256-bit AVX2 vector execution | SWAR + AVX2 (x86-64-v3) active |
Command Line Interface & Flags
⚙️ omnitoken — CLI Options & Subcommands
omnitoken encode — Tokenize input text from stdin or string:
omnitoken encode --vocab <path> [OPTIONS]
| Flag | Short | Type | Default | Description |
|---|---|---|---|---|
--vocab |
-v |
path | required | Path to tokenizers.json, .tiktoken, or .model binary. |
--input |
-i |
string | stdin |
Direct input text string to tokenize. |
⚙️ bench — Benchmarking & Roofline Harness
bench — Measure throughput and cross-check roofline physical ceilings:
bench --vocab <path> [OPTIONS]
| Flag | Short | Type | Default | Description |
|---|---|---|---|---|
--vocab |
-v |
path | required | Path to HuggingFace tokenizers.json or .model. |
--corpus |
-c |
path | synthetic |
Optional path to text corpus file. |
--threads |
-t |
int | 1 |
Number of Rayon threads (1 = single-thread baseline). |
--bytes |
-b |
int | 16777216 |
Bytes of synthetic corpus to generate if no file provided. |
--parity |
-p |
flag | off |
Run token-by-token parity check against vocabulary table. |
--mmap |
flag | off |
Enable memory-mapped file reader for disk streaming. |
System Architecture
Workspace Directory Layout
crates/
├── vocab-ir/ # Universal IR loader (HF tokenizers.json, tiktoken, SPM proto, GGUF)
├── trie-builder/ # Offline Aho-Corasick trie + failure links & continuation prefixes
├── pretokenizer/ # SWAR / AVX2 256-entry byte classifier & UTF-8 chunk splitter
├── walker/ # Unified automaton: O(N log M) BPE, MaxMatch WordPiece, Viterbi Unigram
├── hot-cache/ # Hybrid MPHF static tier + CountMin sketch + SwissTable overflow + RCU thread
├── omnitoken/ # Unified CLI binary + PyO3 Python bindings + mimalloc allocator
└── bench-harness/ # Reproducible roofline-checked benchmark harness
Dependency Architecture
vocab-ir ────────► trie-builder ──────► walker ◄───── pretokenizer
│ ▲
└─────────────────────┼───────── hot-cache
│
omnitoken / bench-harness
AI Use Disclosure & Credit Attribution
🤖 AI Use Disclosure & Development Methodology
Project Concept & Architectural Direction: The overall system design, universal IR specifications, mathematical memory roofline modeling, trie walker algorithms (Song et al., Zouhar et al.), and empirical benchmark harness methodology were formulated and directed by Sunay Hegde.
AI Pair Programming Assistance: An AI coding assistant was utilized during development as an agentic pair programmer. Specifically, AI tools assisted with:
- Generating repetitive Rust boilerplate code and module interfaces.
- Standardizing error handling (
anyhow::Context) and trait implementations. - Refactoring type definitions and creating test harness stubs.
- Formatting SVG brand assets and markdown documentation tables.
All core performance claims, SIMD vectorization routines, and roofline sanity checks were verified and tested directly on physical hardware.
Quick Start & Usage
1. Download Standard Vocab
pip install tokenizers
python3 -c "from tokenizers import Tokenizer; Tokenizer.from_pretrained('gpt2').save('gpt2.json')"
2. Build Release Binaries
cargo build --release
3. Run OmniToken CLI
echo "the quick brown fox jumps over the lazy dog" | ./target/release/omnitoken encode --vocab gpt2.json
4. Run Benchmark Harness
# Single-thread baseline benchmark
./target/release/bench --vocab gpt2.json --threads 1 --bytes 16777216
# Multi-thread 6-core scaling benchmark
./target/release/bench --vocab gpt2.json --threads 6 --bytes 67108864
# Parity verification mode
./target/release/bench --vocab gpt2.json --parity
Verification & Tests
Run all unit and integration tests across workspace crates:
cargo test --workspace
Citation & Licensing
Cite this repository if used in tokenization performance research:
@software{omnitoken2026,
author = {Hegde, Sunay},
title = {{OmniToken}: Universal High-Performance Tokenizer Engine for Consumer Hardware},
year = {2026},
url = {https://github.com/SunayHegde2006/OmniToken}
}
Licensed under the MIT License.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file omnitoken-0.2.0-cp311-cp311-win_amd64.whl.
File metadata
- Download URL: omnitoken-0.2.0-cp311-cp311-win_amd64.whl
- Upload date:
- Size: 184.5 kB
- Tags: CPython 3.11, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
maturin/1.14.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8e29fc84030cd1792b822f412244e8fc0294ba7cdf31e7fce2126935a75432f9
|
|
| MD5 |
1e43024796522e3114c2f384b582670e
|
|
| BLAKE2b-256 |
88127fa0195bb0a04aae64a3609ed6f4469e2266b5ea385d4cdc9cbc51538f5c
|
File details
Details for the file omnitoken-0.2.0-cp311-cp311-manylinux_2_34_x86_64.whl.
File metadata
- Download URL: omnitoken-0.2.0-cp311-cp311-manylinux_2_34_x86_64.whl
- Upload date:
- Size: 308.0 kB
- Tags: CPython 3.11, manylinux: glibc 2.34+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
maturin/1.14.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dda58ed0a0d7f824730d4af55aeccebeedc59670c5b7591e39c5d302f717e500
|
|
| MD5 |
c8de9e6d76120f3092cfb4ecf571e181
|
|
| BLAKE2b-256 |
857c1ce0a1705b4dd27c845c1c1018e05ee5cecfd4e50869ad8ac3fcdbb12a31
|
File details
Details for the file omnitoken-0.2.0-cp311-cp311-macosx_11_0_arm64.whl.
File metadata
- Download URL: omnitoken-0.2.0-cp311-cp311-macosx_11_0_arm64.whl
- Upload date:
- Size: 274.5 kB
- Tags: CPython 3.11, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
maturin/1.14.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cbf9e8d6558913aeeba2dcdb6e25ec1e2f522d802db9599aa55284abdd2adb14
|
|
| MD5 |
933791bf332f3b745b023d32980fd597
|
|
| BLAKE2b-256 |
da4234e556c014411b2b6bf16ed48332dd1ac780ba319b1ef0da4af01ccfe6d5
|
File details
Details for the file omnitoken-0.2.0-cp311-cp311-macosx_10_12_x86_64.whl.
File metadata
- Download URL: omnitoken-0.2.0-cp311-cp311-macosx_10_12_x86_64.whl
- Upload date:
- Size: 289.9 kB
- Tags: CPython 3.11, macOS 10.12+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
maturin/1.14.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b084757e108b9ae5db97ba5840670c7c682e8fc9337af314bab525c96c50c0d1
|
|
| MD5 |
f97b4277eb17e9fcac5ccf24497d6fc7
|
|
| BLAKE2b-256 |
3a6242988dde36d7fedc4e510d291592813d959d3dcd48ab85a0612bb12e40df
|