Stanford学生が高速BPEトークナイザー「Gigatoken」公開
スタンフォード大学の博士課程学生が公開した Rust ベースのトークナイザー「Gigatoken」は、既存ライブラリを最大 989 倍上回る速度でテキストエンコードを実現し、LLM の前処理ボトルネックに劇的な変革をもたらす。
キーポイント
圧倒的な処理速度の実現
144 コア環境で 24.53 GB/s、Apple M4 Max で 8.79 GB/s を達成し、HuggingFace トークナイザーと比較して最大 989 倍の高速化を記録した。
BPE マージループ以外の最適化
トークン化の本質である BPE マージ処理ではなく、従来の実装が軽視していた「前処理(Pretokenization)」の完全手書き実装と SIMD 活用により性能を向上させた。
広範なモデルファミリー対応
GPT-2 から Llama 3/4、Qwen、DeepSeek、Kimi まで 23 の主要トークナイザーファミリーをサポートし、互換性モードとネイティブモードの両方を提供している。
オープンソースによる実装
MIT ライセンスで公開され、Rust と Python のハイブリッド構成(約 66% Rust)により、Python バインディングを通じて容易に利用可能となった。
SWAR と並列カーソルによる性能向上
NEON から SWAR(SIMD Within A Register)へ移行し、256 バイトの検索テーブルとブランチレス演算を採用することで処理速度を 830 MiB/s に引き上げました。さらに、レイテンシボトルネックを解消するため 2 つの独立したカーソルで命令レベル並列性(ILP)を活用し、最終的に 1,049 MiB/s の速度を達成しています。
失敗事例と最適化の限界
#[cold] アトリビュートや二段階分類バッファなどの試みは、LLVM の最適化阻害や追加メモリ転送により性能低下を招き、却下されました。また、内側ループが既にブランチレスであるため、プロファイル指向最適化(PGO)も測定可能な効果を示しませんでした。
ベンチマーク環境と文脈
Gigatoken は未分割ファイルを自動処理するのに対し、比較対象は事前に分割されたデータセットで評価されており、厳密な同条件比較ではありません。また、SentencePiece 系トークナイザーでは BPE に比べて速度向上が 10 倍程度と、 headline の数値より低くなります。
重要な引用
Tokenization is the one part of the language modeling stack that almost nobody profiles.
Gigatoken processes data at a staggering 24.53 GB/s... performance advantages of 681x and 989x, respectively.
The gains do not come from a better BPE merge loop. They come from two places that most tokenizers treat as solved.
The insight is that the bottleneck at ~840 MiB/s was latency, not throughput.
A hot/cold split using #[cold] and #[inline(never)] regressed to 580 MiB/s and was reverted, because the inline barrier stopped LLVM from optimizing the combined ASCII and unicode loop.
Gigatoken hits 24.53 GB/s on GPT-2 on a 144-core EPYC, 989x HuggingFace tokenizers and 681x tiktoken.
影響分析・編集コメントを表示
影響分析
このニュースは、大規模言語モデル(LLM)の開発プロセスにおいて長年見過ごされてきたトークン化の前処理段階に革命をもたらすものです。特に、データ前処理のボトルネックが解消されることで、大規模コーパスの事前トレーニングや推論時のスループットが劇的に向上し、計算リソースの効率化とコスト削減に直結します。業界全体として、Rust を活用した低レベル最適化が AI インフラスタックの標準となりつつあることを示す重要な転換点です。
編集コメント
トークン化という地味な工程が、実は AI パイプライン全体のボトルネックとなっていた事実を浮き彫りにした画期的な成果です。Rust の力を借りて前処理の最適化に成功したこのアプローチは、今後の大規模モデル開発における標準的なベストプラクティスとして定着する可能性が高いでしょう。
言語モデルの構築において、トークナイゼーションはほとんど誰も詳細を分析しない部分です。スタンフォード大学の博士課程学生であるマルセル・ロッド氏が MIT ライセンスの下で公開した「Gigatoken」は、この過ちを正すものだと主張しています。このライブラリは単一のマシン上で秒間ギガバイト単位の速度でテキストエンコードを実現し、すでにマルチスレッド化された Rust ベースのベースラインを上回っています。
GPT-2 トークナイザーのベンチマーク結果は驚異的なものです。144 コア構成の AMD EPYC 9565 デュアルソケット環境で、11.9 GB の「owt_train.txt」コーパスを評価したところ、Gigatoken は秒間 24.53 GB という圧倒的な処理速度を記録しました。同じハードウェア構成において、OpenAI の tiktoken は 36.0 MB/s、HuggingFace トークナイザーは 24.8 MB/s に留まります。これは、それぞれ 681 倍、989 倍の性能差を示す結果です。
Apple M4 Max(16 コア)では、同じ GPT-2 ワークロードで秒間 8.79 GB を達成し、HuggingFace トークナイザーに対しては 1,268 倍、tiktoken に対しては 140 倍の高速化を実現しました。また、一般消費者向けの AMD Ryzen 7 9800X3D では秒間 6.27 GB を記録し、それぞれ 106 倍、68 倍の性能向上となりました。この速度向上は、特定の CPU や語彙に依存した一時的な現象ではありません。
Gigatoken とは
Gigatoken は、Rust で書かれ Python バインディングを備えたバイトペアエンコーディング(BPE)トークナイザーです。PyPI には「gigatoken」という名前で公開されており(バージョン 0.9.0、2026 年 7 月 21 日リリース)、pip install gigatoken でインストールできます。リポジトリのコード構成は Rust が約 66%、Python が約 33% です。
公開されたベンチマークでは、GPT-2、GPT-OSS、Llama 3 から 4、Qwen 2 から 3.6、DeepSeek V3/R1/V4、GLM 4 と 5、Kimi K2、Nemotron 3、Phi-4、OLMo 2/3、ModernBERT、Gemma、Mistral など、計 23 の異なるトークナイザーファミリーに対応しています。
利用方法は主に 2 つあります。1 つ目は互換性モードで、既存の HuggingFace や tiktoken トークナイザーをラップし、出力結果を完全に一致させます。ただし、スループットには実質的なコストがかかります。著者(Marcel)は Hacker News で、このモードでもリスト作成や文字列からバイトへの変換に伴う Python のオーバーヘッドが発生するため、利用状況にもよりますが 200〜300 倍程度の高速化になると述べています。
もう 1 つがネイティブな Gigatoken API です。こちらは Rust がファイルを直接読み込むため、公開されている数値の根拠となっているのがこのモードです。
インタラクティブなベンチマークエクスプローラー
以下のすべての数値は、リポジトリ内のベンチマークセクションとプレトークナイザー最適化ログから抽出されたものです。CPU を切り替えて最適化履歴を確認したり、ご自身のコーパスがどれくらいの時間を要するか見積もったりできます。
(function(){var f=document.getElementById("gigatoken-explorer-frame");if(!f)return;
window.addEventListener("message",function(e){
if(e&&e.data&&typeof e.data.gigatokenHeight==="number"){f.style.height=e.data.gigatokenHeight+"px;";}
});})();どうやって実現しているか
この性能向上は、より優れた BPE マージループによるものではありません。むしろ、多くのトークナイザーが「解決済み」と見なしている 2 つの領域からのものです。
(1) プリートークン化:ほとんどの実装では、これは正規表現エンジンに任されています。しかし Gigatoken はこれを自前で実装しています。その最適化ログには、OpenWebText の 100 MB を対象としたシングルスレッド GPT-2 プリートークナイザーのスループット推移が記録されており、その過程は非常に示唆に富んでいます。
「fancy-regex」ベースラインでは約 47 MiB/s ですが、手書きの状態機械では約 380 MiB/s に達します。さらに NEON SIMD インストリクションを用いた winnow-combinator 実装では 462 MiB/s を記録しました。
ここで winnow を直接の Iterator に置き換え、最初のバイト dispatch を O(1) で行うための 256 バイト分のクラスルックアップテーブルを追加し、NEON インストリクションから SWAR(SIMD Within A Register)へ切り替えると、スループットは 830 MiB/s まで向上します。SWAR は 8 バイトを u64 として読み込み、分岐のない算術演算でそのすべてが文字かどうかを同時にチェックします。これにはアーキテクチャ固有のインストリクションは不要です。
最終段階では、デュアルカーソルによる ILP(命令レベル並列性)の活用を行い、1,049 MiB/s を達成しました。ここで得られた洞察は、約 840 MiB/s でボトルネックになっていたのがスループットではなくレイテンシだったという点です。各トークンの終了位置は直前のトークンに依存するため、約 25〜27 サイクルの連続処理チェーンとなっていました。安全な分割点から独立した 2 つのカーソルを走らせることで、アウト・オブ・オーダー実行エンジンが両方のストリームをアイドル状態の実行ポートに割り込むことが可能になります。
この結果、プリートークナイザー単体でも、winnow+NEON ベースラインに対して 2.27 倍、正規表現実装に対しては 22.3 倍の性能向上となりました。
(2) Pretoken キャッシュ:一度見た単語のエンコード済みトークンは、再計算せずにキャッシュから参照します。著者(Marcel)は、これが実務では難しいと指摘しています。キャッシュが急速に肥大化することや、事前トークンの分布がロングテールになることが理由です。さらに、Python との相互作用を最小限に抑え、スレッド間も可能な限り独立して動作するように設計されています。
最適化ログには、何が失敗したかについて異例ほど正直な記述があります。#[cold] と #[inline(never)] を使ったホット/コールド分割は、インラインバリアが LLVM による ASCII と Unicode のループ統合最適化を阻害したため、580 MiB/s に後退し、結局取り消されました。SWAR による遷移カウントを用いた2パス分類バッファはアルゴリズム上は正しいものの、追加のメモリアクセスが分岐節約を上回ったため、354 MiB/s という速度に留まりました。プロファイル指向最適化(PGO)には目に見える効果はありませんでした。内側ループがすでに分岐なしであり、単語境界における分岐もデータ依存であるためです。
ベンチマーク手法に関する注記
比較は厳密には同等条件ではありません。Gigatoken は分割されていないファイル全体をエンコードし、独自のドキュメント境界を検出して自動的に並列化します。一方、HuggingFace(encode_batch_fast)は最初の 100 MB を対象に評価され、tiktoken(encode_ordinary_batch)は最初の 1 GB を対象に評価されます。これらは両方とも pre-split 済みです。ベースラインではキャッシュを省略しているため、スループットは一定のままです。測定値は、並列化を有効にした新鮮なプロセスで3回交互に実施したラウンドのうち最良の結果を報告しています。
語彙の種類によっても制約が生じます。SentencePiece トークナイザーは部分的にしか最適化されていません。EPYC 上では、Gemma 1 が 2.51 GB/s(7.3 倍の高速化)、Gemma 3 が 3.43 GB/s(9.6 倍)、CodeLlama が 3.47 GB/s(10.0 倍)で処理します。これらの数値は確かに大幅な改善ですが、 headline で紹介された BPE の性能にはまだ一桁低い水準です。
KrabArena での独立した再現実験でも結果が確認されました。4 コア vCPU の Intel Xeon VM(2.20 GHz)上で、174 MB の OpenWebText スライスを用いたテストでは、Gigatoken 0.9.0 が中央値で 277.8 MB/s を達成しました。これは tiktoken 0.13.0(10.62 MB/s)を 26.2 倍、tokenizers 0.23.1(3.33 MB/s)を 83.4 倍上回る結果です。すべての試行で 35,356 ドキュメントの検証に成功し、性能向上はコア数に応じてスケーリングすることが確認されました。
要点まとめ
- Gigatoken は 144 コア EPYC 上で GPT-2 を処理する際、24.53 GB/s に達し、HuggingFace トークナイザーより 989 倍、tiktoken より 681 倍高速です。
- この速度向上は x86 と ARM の両アーキテクチャ、そして 23 のトークナイザーファミリー全体で確認されており、特定のチューニング設定に依存しません。
- 性能の源泉は、手書きの SWAR プリトークナイザーとプリトークンキャッシュによるものであり、BPE マージループ自体を高速化したものではありません。
- SentencePiece 語彙では 7〜22 倍の高速化が得られますが、1,000 倍には届かず、WordPiece はサポートされていません。
- 互換性モードでは HuggingFace と完全な出力整合性を保ちつつ、約 200〜300 倍の速度向上を実現します(最大速度ではありません)。
詳細は GitHub リポジトリとリリーススレッドをご覧ください。本研究のすべての功績は、このプロジェクトの著者に帰属します。
本記事「Meet Gigatoken: A Rust BPE Tokenizer that Encodes Text at 24.53 GB/s, up to 989x Faster than HuggingFace Tokenizers」は、MarkTechPost に掲載されたものです。
原文を表示
Tokenization is the one part of the language modeling stack that almost nobody profiles. Gigatoken, released by Marcel Rød (a PhD student from Stanford) under an MIT license, argues that this was a mistake. The library encodes text at gigabytes per second on a single machine, against baselines that are already multithreaded Rust.
The GPT-2 tokenizer benchmarking yields remarkable results: evaluated on the 11.9 GB owt_train.txt corpus using a 144-core AMD EPYC 9565 dual-socket setup, Gigatoken processes data at a staggering 24.53 GB/s. In comparison, OpenAI’s tiktoken achieves 36.0 MB/s, while HuggingFace tokenizers registers at 24.8 MB/s on the identical hardware configuration. These marks demonstrate performance advantages of 681x and 989x, respectively.
On an Apple M4 Max with 16 cores, the same GPT-2 workload runs at 8.79 GB/s, or 1,268x HuggingFace tokenizers and 140x tiktoken. On a consumer AMD Ryzen 7 9800X3D, it runs at 6.27 GB/s, or 106x and 68x. The speedup is not an artifact of one CPU or one vocabulary.
What is Gigatoken
Gigatoken is a byte-pair encoding (BPE) tokenizer written in Rust with Python bindings. It ships on PyPI as gigatoken (version 0.9.0, released 21 July 2026) and installs with pip install gigatoken. The repository is 66.2% Rust and 33.3% Python. It supports 23 distinct tokenizer families in the published benchmarks, covering GPT-2, GPT-OSS, Llama 3 through 4, Qwen 2 through 3.6, DeepSeek V3/R1/V4, GLM 4 and 5, Kimi K2, Nemotron 3, Phi-4, OLMo 2/3, ModernBERT, Gemma and Mistral.
There are two ways to use it. Compatibility mode wraps an existing HuggingFace or tiktoken tokenizer and preserves exact output parity, at a real cost to throughput. The author (Marcel) states on Hacker News that compatibility mode delivers roughly 200–300x depending on usage, because it still pays Python overhead for list creation and string-to-bytes conversion. The native Gigatoken API lets Rust read files directly and is where the published numbers come from.
The interactive benchmark explorer
Every number below is drawn from the repository’s benchmarks section and the pretokenizer optimization log. Switch CPUs, walk the optimization history, or estimate how long your own corpus would take.
(function(){var f=document.getElementById("gigatoken-explorer-frame");if(!f)return;
window.addEventListener("message",function(e){
if(e&&e.data&&typeof e.data.gigatokenHeight==="number"){f.style.height=e.data.gigatokenHeight+"px";}
});})();
How it gets there
The gains do not come from a better BPE merge loop. They come from two places that most tokenizers treat as solved.
(1) Pretokenization: Most implementations delegate this to a regex engine. Gigatoken hand-writes it. The optimization log tracks single-threaded GPT-2 pretokenizer throughput on 100 MB of OpenWebText, and the progression is instructive:
A fancy-regex baseline runs at ~47 MiB/s. A hand-rolled state machine hits ~380 MiB/s. A winnow-combinator implementation with NEON SIMD intrinsics reaches 462 MiB/s.
Replacing winnow with a direct Iterator, adding a 256-byte class lookup table for O(1) first-byte dispatch, and switching from NEON intrinsics to SWAR (SIMD Within A Register) pushes it to 830 MiB/s. SWAR loads 8 bytes as a u64 and checks all 8 for the letter property with branchless arithmetic. It needs no architecture-specific intrinsics.
The final step is dual-cursor ILP exploitation, reaching 1,049 MiB/s. The insight is that the bottleneck at ~840 MiB/s was latency, not throughput. Each token’s end position depends on the previous one, a serial chain of roughly 25–27 cycles. Running two independent cursors from a safe split point lets the out-of-order engine interleave both streams across idle execution ports.
Net effect on the pretokenizer alone: 2.27x over the winnow + NEON baseline, and 22.3x over the regex implementation.
(2) Pretoken caching: If a word has been seen before, its encoded tokens are looked up rather than recomputed. The author (Marcel) notes this is hard in practice, because the cache grows quickly and pretoken distributions are long-tailed. On top of that, interactions with Python are minimized and threads are designed to interact minimally with each other.
The optimization log is unusually honest about what failed. A hot/cold split using #[cold] and #[inline(never)] regressed to 580 MiB/s and was reverted, because the inline barrier stopped LLVM from optimizing the combined ASCII and unicode loop. A two-pass classification buffer with SWAR transition counting was algorithmically correct but ran at 354 MiB/s, since the extra memory traffic beat the branch savings. Profile-guided optimization had no measurable effect, because the inner loop is already branchless and the word-boundary branch is data-dependent.
Benchmark Methodology Notes
The comparison is not strictly apples-to-apples. Gigatoken encodes entire un-split files, finding its own document boundaries and parallelizing automatically. In contrast, HuggingFace (encode_batch_fast) is evaluated on the first 100 MB and tiktoken (encode_ordinary_batch) on the first 1 GB, both pre-split on <|endoftext|>. Because the baselines omit caching, their throughput remains uniform. Measurements report the best of three interleaved rounds using fresh processes with parallelism enabled.
Vocabulary types also introduce constraints; SentencePiece tokenizers are only partially optimized. On EPYC, Gemma 1 processes at 2.51 GB/s (7.3x speedup), Gemma 3 at 3.43 GB/s (9.6x), and CodeLlama at 3.47 GB/s (10.0x). Although substantial, these gains are an order of magnitude lower than the headline BPE performance.
An independent reproduction on KrabArena verified the results. On a 4-vCPU Intel Xeon VM (2.20 GHz) with a 174 MB OpenWebText slice, Gigatoken 0.9.0 achieved a median of 277.8 MB/s, outperforming tiktoken 0.13.0 (10.62 MB/s) by 26.2x and tokenizers 0.23.1 (3.33 MB/s) by 83.4x. All trials successfully validated 35,356 documents, confirming the performance trend scales with core count.
Key Takeaways
Gigatoken hits 24.53 GB/s on GPT-2 on a 144-core EPYC, 989x HuggingFace tokenizers and 681x tiktoken.
The speedup holds across x86 and ARM, and across 23 tokenizer families, not one tuned configuration.
Gains come from a hand-written SWAR pretokenizer and pretoken caching, not a faster BPE merge loop.
SentencePiece vocabularies see 7–22x, not 1,000x, and WordPiece is unsupported.
Compatibility mode preserves exact HuggingFace output parity at roughly 200–300x instead of the full speedup.
Check out the GitHub repo and the release thread. All credit for this research goes to the author of this project.
The post Meet Gigatoken: A Rust BPE Tokenizer that Encodes Text at 24.53 GB/s, up to 989x Faster than HuggingFace Tokenizers appeared first on MarkTechPost.
関連記事
今日のまとめ
AI日報で今日の重要ニュースをまとめ読み