Open Source · MIT License オープンソース · MIT ライセンス

The Fastest BPE Tokenizer 世界最速
BPEトークナイザー

Drop-in replacement for tiktoken. Zig + hand-written assembly. ARM64, Metal GPU, WASM, AVX, CUDA, RISC-V. One library, every platform. tiktokenをそのまま置き換えるだけ。中身はZigと手書きアセンブリ。 ARM64、Metal GPU、WASM、AVX、CUDA、RISC-V。たった1つのライブラリで全プラットフォームに対応。

pip install turbotoken

Why Tokenization Matters トークナイゼーションが世界を変える理由

Every message you send to ChatGPT, Claude, or Gemini must be converted into numbers before the AI can read it. That conversion is called tokenization. It happens on every single API call, billions of times a day, across the entire industry. ChatGPTやClaude、Geminiにメッセージを送るたび、文章はまずAIが理解できる「数値」に変換されます。これがトークナイゼーション。すべてのAIリクエストの入口であり、1日に数百億回、世界中で実行されている処理です。

The Scale 圧倒的な処理量

The world processes over 50 trillion tokens per day. OpenAI alone handles 6 billion tokens per minute. Google processes 1.3 quadrillion tokens per month. Every single one goes through a tokenizer. 世界全体で1日あたり50兆トークン以上が処理されています。OpenAIだけで毎分60億トークン、Googleに至っては月間1.3京トークン。この膨大な処理のすべてが、トークナイザーを通っています。

50T+ tokens/day globally 全世界で1日50兆トークン以上

The Cost 削減できるコスト

AI inference is a $106B market. 6.75x faster tokenization means ~62 million CPU-hours freed per year globally. On GPU instances where tokenization blocks the pipeline, that translates to $50-200M in recoverable infrastructure cost. AI推論は約16兆円規模の市場です。トークナイゼーションが6.75倍速くなるだけで、年間約6,200万CPU時間が不要に。GPUパイプラインのボトルネック解消分を含めると、年間75億〜300億円規模のインフラコスト削減につながります。

~62M CPU-hours saved/year 年間約6,200万CPU時間を削減

The Energy 環境へのインパクト

AI data centers consume 415 TWh per year globally, and 80-90% of that is inference. Faster tokenization at full adoption could save millions of tonnes of CO2 per year. Performance is sustainability. 世界のAIデータセンターは年間415TWhの電力を消費し、その8〜9割が推論処理です。トークナイゼーションの高速化を全面的に導入すれば、年間数百万トン規模のCO2削減が見込めます。速さは、そのまま環境への貢献です。

415 TWh/year in AI inference AI推論だけで年間415TWh消費

Think of it this way: tokenization is the toll booth on the highway to AI. Every request stops there. Making the toll booth 6.75x faster means the entire highway moves faster. For every person using AI, for every API call, for every company building on top of LLMs. たとえるなら。トークナイゼーションは、AIにつながる高速道路の料金所です。どんなリクエストも、必ずここを通る。この料金所を6.75倍速くすれば、道路全体の流れが変わります。AIを使うすべての人、すべての企業、すべてのサービスの体験が変わるのです。

Hand-tuned Zig, ARM64 NEON assembly, Metal GPU shaders, AVX-512, CUDA, RISC-V vectors. A project like this would normally take a dedicated team years to build. The secret: rigorous tests, relentless benchmarking, and AI code agents. Thousands of hyperfine runs. Byte-perfect compatibility tests against tiktoken. Let the agents iterate, measure everything, and refuse to stop until every microsecond is accounted for. When the feedback loop is airtight, AI writes code that beats the best hand-tuned implementations in the world. Everything has changed. Zigの最適化、ARM64 NEONアセンブリ、Metal GPUシェーダー、AVX-512、CUDA、RISC-Vベクター演算。これだけの規模のプロジェクトは普通、専門チームが何年もかけてようやく完成させるものです。 鍵を握ったのは、徹底したテスト、際限のないベンチマーク、そしてAIコードエージェント。 hyperfineを何千回も回し、tiktokenとのバイト単位の完全一致を検証し続ける。エージェントにひたすら反復させ、すべてを計測し、1マイクロ秒の無駄も許さない。 このフィードバックループが完璧に回ったとき、AIは世界最高峰の手書き実装すら超えるコードを生み出した。時代が変わった。
Tests + Benchmarks + AI Agents = the fastest code on Earth テスト + ベンチマーク + AIエージェント = 世界最速のコード
6.75x
faster than tiktoken tiktokenより高速

Measured on 100KB encode, Apple M4 Max 100KBエンコード、Apple M4 Maxで計測

Python Encode 100KB Pythonエンコード 100KB

turbotoken
43.4 ms
43.4 ms
tiktoken
215.9 ms
215.9 ms

Browser Startup Latency ブラウザ起動レイテンシ

turbotoken
8.5 ms
8.5 ms
gpt-tokenizer
613.2 ms
613.2 ms
js-tiktoken
1414.2 ms
1414.2 ms

Training 100KB トレーニング 100KB

turbotoken
45.7 ms
45.7 ms
rustbpe
60.8 ms
60.8 ms
minbpe
764.6 ms
764.6 ms
16.7x faster than minbpe minbpeより16.7倍高速

O(n) Algorithm O(n) アルゴリズム

Linear-time backtracking BPE, not tiktoken's O(n²) greedy approach. 線形時間のバックトラッキングBPE。tiktokenのO(n²)貪欲法とは根本的に違います。

turbotoken

O(n)
Backtracking BPE バックトラッキングBPE

tiktoken

O(n²)
Greedy merge 貪欲マージ

6 Hardware Backends 6つのハードウェアバックエンド

One codebase, native acceleration everywhere. ひとつのコードベースから、すべてのプラットフォームでネイティブ高速化。

ARM64 NEON
Apple Metal
WebAssembly
AVX2/512
NVIDIA CUDA
RISC-V Vector

Drop-in Replacement そのまま差し替え可能

Same API as tiktoken. Change one import line and get instant speedup. Byte-perfect output guaranteed. tiktokenとまったく同じAPI。import文を1行書き換えるだけで、即座に高速化。出力はバイト単位で完全一致を保証します。

# Before
import tiktoken

# After (that's it!)
import turbotoken as tiktoken

enc = tiktoken.encoding_for_model("gpt-4o")
tokens = enc.encode("Hello world!")
text = enc.decode(tokens)

Parity Verified 互換性を完全検証済み

  • o200k_base (GPT-4o)
  • cl100k_base (GPT-4)
  • p50k_base (Codex)
  • r50k_base (GPT-3)

WASM Ready WASM対応

Same Zig core compiles to wasm32. Runs in any browser, edge function, or serverless worker. 同じZigコアがそのままwasm32にコンパイル。ブラウザでもエッジでもサーバーレスでも動きます。

<150 KB optimized binary 最適化バイナリ

166x faster startup than js-tiktoken js-tiktokenより166倍高速な起動

Zig + Assembly

Zero-overhead core. comptime-generated merge tables. Hand-written NEON/AVX hot loops for the last 5% of perf. オーバーヘッドゼロの設計。マージテーブルはコンパイル時に生成。残り5%の性能を絞り出すためにNEON/AVXのホットループは手書き。

@Vector(16, u8) → NEON
@Vector(32, u8) → AVX2
@Vector(64, u8) → AVX-512
comptime → 0ms init

27 Language Wrappers 27言語に対応

Native bindings for every major language and runtime. 主要な言語とランタイムすべてにネイティブバインディングを提供。

Python JavaScript Rust Go C C++ Java C# F# Ruby Swift Kotlin Scala Deno React Native Flutter Elixir Gleam Clojure Groovy Lua PHP R Julia Mojo JNI Erlang NIF

Custom BPE Training 独自語彙のBPEトレーニング

Train your own tokenizer vocabularies. Beats rustbpe and minbpe on benchmarked workloads. 自前のトークナイザー語彙をトレーニング可能。ベンチマークではrustbpeもminbpeも上回ります。

from turbotoken import train_encoding_from_iterator

with open("corpus.txt") as f:
  enc = train_encoding_from_iterator(
    f, vocab_size=4096, name="custom"
  )
ids = enc.encode("Hello!")

Metal GPU Acceleration Metal GPU高速化

Production-grade compute shaders for Apple Silicon. On-device BPE merge loop with active compaction. Apple Silicon向けの本番品質コンピュートシェーダー。アクティブコンパクション付きのオンデバイスBPEマージを実現。

1.72x
GPU throughput boost GPUスループット向上
40
GPU cores (M4 Max) GPUコア (M4 Max)

Benchmark Results ベンチマーク結果

Every number measured with Hyperfine. No hand-waving. No "approximately". すべての数値はHyperfineで実測。推測なし。曖昧な表現なし。

Workload ワークロード turbotoken tiktoken Speedup 高速化
Encode 100KB エンコード 100KB 43.4 ms 215.9 ms ~5.0x
Encode 1MB エンコード 1MB 72.4 ms - -
Cold Startup コールドスタート 64.4 ms - -
Count 100KB カウント 100KB 44.5 ms - -
Browser Startup ブラウザ起動 8.5 ms 1414 ms ~166x
JS Native Encode 1MB JSネイティブエンコード 1MB 9.83 ms - 101.75 MiB/s
GPU Long-lane 1MB GPU ロングレーン 1MB 1.72x throughput boost 1.72倍スループット向上 Metal
Training 100KB トレーニング 100KB 45.7 ms 764.6 ms minbpe ~16.7x

All benchmarks: Apple M4 Max (16-core, 40 GPU), macOS Sequoia, Hyperfine v1.19+ 全ベンチマーク: Apple M4 Max(16コア、GPU 40基)、macOS Sequoia、Hyperfine v1.19+

Python

Identical to tiktoken API tiktoken APIとまったく同じ

import turbotoken as tiktoken

enc = tiktoken.encoding_for_model("gpt-4o")
tokens = enc.encode("Hello, world!")
text = enc.decode(tokens)
count = enc.encode("...", count_only=True)

JavaScript / WASM

Browser + Node + Bun + Deno ブラウザ + Node + Bun + Deno

import { getEncodingAsync } from "turbotoken";

const enc = await getEncodingAsync("o200k_base");
const ids = await enc.encodeAsync("Hello!");
const text = await enc.decodeAsync(ids);

Ready to go turbo? ターボ、始めませんか?

One line change. Instant speedup. Byte-perfect compatibility. 変更はたった1行。即座に高速化。出力は完全互換。

pip install turbotoken

Work in Progress. turbotoken is under active development. APIs may change. ARM64 NEON and Metal GPU backends are production-grade. WASM is functional. AVX, CUDA, and RISC-V are in progress. Follow the GitHub repo for updates. 現在開発中です。 turbotokenは活発に開発が進んでいます。APIは今後変更される場合があります。ARM64 NEONとMetal GPUは本番レベルの品質に到達済み。WASMは動作確認済み。AVX、CUDA、RISC-Vは現在実装中です。最新情報はGitHubリポジトリでご確認ください。

Also by the same author 同じ作者による別のプロジェクト

AssemblyClaw Pure assembly claw machine game 純粋アセンブリ言語で書かれたクレーンゲーム