A blazing-fast BPE tokenizer for Qwen models, built with Rust and the rust-gems BPE crate. Achieves 6x faster tokenization by default and 12x faster with parallelization compared to HuggingFace tokenizers.
pip install bpe-qwen
Use bpe-qwen as a drop-in replacement for HuggingFace tokenizers:
# Patch transformers to use bpe-qwen for Qwen models
from bpe_qwen import AutoLinearTokenizer
# This automatically uses bpe-qwen under the hood
tokenizer = AutoLinearTokenizer.from_pretrained("Qwen/Qwen2.5-Coder-7B-Instruct")
# Use it exactly like a HuggingFace tokenizer
outputs = tokenizer(
"Hello, world!",
return_tensors="pt",
padding=True,
truncation=True
)
print(outputs["input_ids"])
# Batch processing with native HuggingFace API
batch = tokenizer(
["Text 1", "Text 2", "Text 3"],
padding=True,
return_attention_mask=True
)
Performance comparison with HuggingFace tokenizers on WikiText dataset (2,891 texts, 1.3M characters):
| Tokenizer | Speed | Speedup vs HF |
|---|---|---|
| bpe-qwen | 6.40M tokens/sec | 6.28x |
| HuggingFace | 1.02M tokens/sec | 1.00x |
| Tokenizer | Speed | Speedup vs HF | Parallel Benefit |
|---|---|---|---|
| bpe-qwen | 33.08M tokens/sec | 12.52x | 5.17x vs sequential |
| HuggingFace | 2.64M tokens/sec | 1.00x | 2.59x vs sequential |
✅ Token consistency verified: All methods produce identical 298,938 tokens
# Install Rust toolchain
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
# Clone and build
git clone https://github.com/sweepai/bpe-qwen.git
cd bpe-qwen
maturin develop --release
# Run tests
python test_simple.py
python benchmark.py
This entire project was written by Sweep AI, an AI plugin for JetBrains IDEs
133 commits
Python
68.6%
Rust
30.8%
A blazing-fast BPE tokenizer for Qwen models, built with Rust and the rust-gems BPE crate. Achieves 6x faster tokenization by default and 12x faster with parallelization compared to HuggingFace tokenizers.
pip install bpe-qwen
Use bpe-qwen as a drop-in replacement for HuggingFace tokenizers:
# Patch transformers to use bpe-qwen for Qwen models
from bpe_qwen import AutoLinearTokenizer
# This automatically uses bpe-qwen under the hood
tokenizer = AutoLinearTokenizer.from_pretrained("Qwen/Qwen2.5-Coder-7B-Instruct")
# Use it exactly like a HuggingFace tokenizer
outputs = tokenizer(
"Hello, world!",
return_tensors="pt",
padding=True,
truncation=True
)
print(outputs["input_ids"])
# Batch processing with native HuggingFace API
batch = tokenizer(
["Text 1", "Text 2", "Text 3"],
padding=True,
return_attention_mask=True
)
Performance comparison with HuggingFace tokenizers on WikiText dataset (2,891 texts, 1.3M characters):
| Tokenizer | Speed | Speedup vs HF |
|---|---|---|
| bpe-qwen | 6.40M tokens/sec | 6.28x |
| HuggingFace | 1.02M tokens/sec | 1.00x |
| Tokenizer | Speed | Speedup vs HF | Parallel Benefit |
|---|---|---|---|
| bpe-qwen | 33.08M tokens/sec | 12.52x | 5.17x vs sequential |
| HuggingFace | 2.64M tokens/sec | 1.00x | 2.59x vs sequential |
✅ Token consistency verified: All methods produce identical 298,938 tokens
# Install Rust toolchain
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
# Clone and build
git clone https://github.com/sweepai/bpe-qwen.git
cd bpe-qwen
maturin develop --release
# Run tests
python test_simple.py
python benchmark.py
This entire project was written by Sweep AI, an AI plugin for JetBrains IDEs
133 commits
Python
68.6%
Rust
30.8%