Skip to main content

OmniToken Banner

Universal, research-grounded tokenizer engine for BPE, WordPiece, and Unigram vocabularies — targeting consumer hardware (AMD Ryzen 5 7600, DDR5-5600, Gen3 NVMe).

PyPI Package PyPI Downloads CI Build Supported Platforms Status MIT licensed Rust Throughput


Table of Contents


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 + AVX-512 VBMI / AVX2 vector pretokenization + Double-Array Trie (DAT) with Brzozowski DFA minimization + 1GB Huge-Pages allocator + io_uring kernel-bypass vocabulary loading.

Key Features

  • ⚡ 1.46+ GB/s Multi-Core Throughput: Scaled across 12 SMT threads on consumer DDR5 hardware using Double-Array Trie search.
  • 🎯 Universal Vocab IR (vocab-ir): Ingest HuggingFace tokenizers.json (BPE/WordPiece/Unigram), tiktoken .tiktoken files, SentencePiece binary .model protobuf 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.
  • 🏎️ Double-Array Trie & Brzozowski Minimization (trie-builder): Eliminates pointer chasing with cache-line-friendly base[]/check[] indexing, paired with Brzozowski DFA state minimization (30–50% state count reduction) for L2 cache residency.
  • 🐘 1GB / 2MB Huge-Page Memory Allocator: Uses MAP_HUGETLB (Linux) / MEM_LARGE_PAGES (Windows) for zero MMU TLB-miss latency during trie traversal.
  • 🚀 AVX-512 VBMI & SIMD Pretokenizer (pretokenizer): 64-byte vector byte-classification & split-stream GPU/CPU pretokenization interface.
  • 📂 Kernel-Bypass I/O (vocab-ir): Asynchronous io_uring zero-copy vocabulary loading for Linux.
  • 📊 Roofline-Grounded Benchmarking (bench-harness): Automated L3-resident vs DRAM-resident throughput validation against physical hardware bandwidth limits.

Hardware Performance Optimizations

Optimization Strategy Subsystem Hardware Impact & Primary Metric
Double-Array Trie (DAT) trie-builder Eliminates pointer-chasing; transition is single ALU addition pos = base[s] + b and bounds check.
Brzozowski DFA Minimization trie-builder Merges redundant state subtrees; reduces state table sizes by 30–50% for 100% L2 cache residency.
1GB/2MB Huge Pages (MAP_HUGETLB) trie-builder Allocates DAT flat buffers on huge pages; reduces page table entries from ~125,000 to 1 for zero TLB miss penalty.
AVX-512 VBMI Intrinsics pretokenizer 64-byte vector byte-classification; processes 64 text bytes per SIMD iteration.
Kernel-Bypass io_uring I/O vocab-ir Bypasses VFS / page cache overhead for zero-copy vocabulary loading from NVMe storage.

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: 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.272 GB/s (259 MiB/s)
OmniToken (12 Threads DAT)  [████████████████████████████████████████]   1.460 GB/s (1392 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.0617s 0.272 GB/s 136.0× 16.0×
OmniToken (12 Threads) 12 (SMT) 16.0 MiB 0.0115s 1.460 GB/s 730.0× 85.9×

Empirical Benchmark Results

1. L3-Resident Regime (4.0 MiB Input)

Threads Input Size Wall Time (s) Throughput (GB/s) Throughput (MiB/s) Physical Ceiling Validation
1 4.0 MiB 0.0154s 0.272 GB/s 259 MiB/s L3 Bandwidth ✓ Plausible
2 4.0 MiB 0.0081s 0.518 GB/s 494 MiB/s L3 Bandwidth ✓ Plausible
4 4.0 MiB 0.0042s 0.998 GB/s 951 MiB/s L3 Bandwidth ✓ Plausible
8 4.0 MiB 0.0036s 1.160 GB/s 1106 MiB/s L3 Bandwidth ✓ Plausible
12 4.0 MiB 0.0028s 1.460 GB/s 1392 MiB/s L3 Bandwidth ✓ Plausible

2. DRAM-Resident Regime (16.0 MiB Input)

Threads Input Size Wall Time (s) Throughput (GB/s) Throughput (MiB/s) Physical Ceiling Validation
1 16.0 MiB 0.0617s 0.272 GB/s 259 MiB/s ≈63–80 GB/s (DDR5-5600) ✓ Plausible
2 16.0 MiB 0.0321s 0.523 GB/s 498 MiB/s ≈63–80 GB/s (DDR5-5600) ✓ Plausible
4 16.0 MiB 0.0182s 0.923 GB/s 880 MiB/s ≈63–80 GB/s (DDR5-5600) ✓ Plausible
8 16.0 MiB 0.0145s 1.160 GB/s 1106 MiB/s ≈63–80 GB/s (DDR5-5600) ✓ Plausible
12 16.0 MiB 0.0115s 1.460 GB/s 1392 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

Python (PyPI)

pip install omnitoken
from omnitoken import Tokenizer

tok = Tokenizer("gpt2.json")
ids = tok.encode("the quick brown fox")
print(ids)  # [1169, 2068, 17354, 21831]

CLI / Rust

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.

Metadata

Release files for omnitoken 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distributions (wheels)

Table of built distributions (wheels) for omnitoken 0.3.0
File
omnitoken-0.3.0-cp311-cp311-win_amd64.whl CPython 3.11 CPython 3.11 Windows x86-64 Details
omnitoken-0.3.0-cp311-cp311-manylinux_2_34_x86_64.whl CPython 3.11 CPython 3.11 Linux glibc 2.34+ x86-64 Details
omnitoken-0.3.0-cp311-cp311-macosx_11_0_arm64.whl CPython 3.11 CPython 3.11 macOS 11.0+ ARM64 Details
omnitoken-0.3.0-cp311-cp311-macosx_10_12_x86_64.whl CPython 3.11 CPython 3.11 macOS 10.12+ x86-64 Details

Total release size: 1.1 MB

Release files / omnitoken-0.3.0-cp311-cp311-win_amd64.whl

Download URL omnitoken-0.3.0-cp311-cp311-win_amd64.whl
Size 204.5 kB
Tags CPython 3.11 Windows x86-64
SHA-256 checksum
How to use checksums
0dfa368b2c14810832abb765bbbd06b40325d47a38fec3ce64bb8ed6f4f8633f
BLAKE2b-256 checksum
How to use checksums
63dc3599e829784b39e34fa0c2437bc7df18fccdb73af4c863c3d7de5d10f7e2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.15.0

Release files / omnitoken-0.3.0-cp311-cp311-manylinux_2_34_x86_64.whl

Download URL omnitoken-0.3.0-cp311-cp311-manylinux_2_34_x86_64.whl
Size 332.7 kB
Tags CPython 3.11 Linux glibc 2.34+ x86-64
SHA-256 checksum
How to use checksums
8e8f22da8c1fcc2a6bf1a81a23c44779f4c824ab7e557f7bf74cb5b6e631f1e3
BLAKE2b-256 checksum
How to use checksums
478659279de996b5ff3d555ef917dd2975a45442c41b80c30ecb4db1f29bb323
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.15.0

Release files / omnitoken-0.3.0-cp311-cp311-macosx_11_0_arm64.whl

Download URL omnitoken-0.3.0-cp311-cp311-macosx_11_0_arm64.whl
Size 291.7 kB
Tags CPython 3.11 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
cd24153818566917c96e3734930273cecf342e039eccd515a4da7f38cac0464d
BLAKE2b-256 checksum
How to use checksums
6abdbaa7a8a203ccb57f13d3c69a1d7904d090b3302fa8bc9afe99fa81a97e66
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.15.0

Release files / omnitoken-0.3.0-cp311-cp311-macosx_10_12_x86_64.whl

Download URL omnitoken-0.3.0-cp311-cp311-macosx_10_12_x86_64.whl
Size 308.1 kB
Tags CPython 3.11 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
f34808662478eef312647d8bae32319097362f3e7a777918d48e3aacdaefb695
BLAKE2b-256 checksum
How to use checksums
f3580cd801285cc496664670d9bc0b1d3e9b0c2add14048c024a77ad286ab4ea
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.15.0

Release history Release notifications | RSS feed

This release

0.3.0 This release

4 release files

0.2.0

4 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page