RustBPE is a Python library that provides a fast Byte Pair Encoding (BPE) tokenizer implemented in Rust, with Python bindings. It is designed primarily for training GPT-style BPE tokenizers and offers features like parallel processing, GPT-4 style regex pre-tokenization, and direct export to the tiktoken format for efficient inference. Currently at version 0.1.0, it is an initial release, suggesting active and potentially rapid development.
pip install rustbpeVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to initialize the `rustbpe.Tokenizer`, train it on a small dataset, and then use it to encode and decode text, including batch operations. It also shows the (optional) export capability to the tiktoken format.
Understand that rustbpe provides the 'missing tiktoken training code' and plan your workflow accordingly, potentially using tiktoken for production inference.
Pin your dependency to a specific minor version (`rustbpe==0.1.*`) in production environments and review release notes for breaking changes when updating.
Review the tokenizer's pre-tokenization regex if exact compatibility with non-GPT-4 style models is critical. The library's source code indicates the specific pattern used.
While functional, be aware that future performance or maintainability improvements might arise from Rust-specific code optimizations. Report any observed inefficiencies or bugs on the GitHub issues page.
Run `pip install rustbpe` to install the package.
Ensure `vocab_size` is passed as a keyword argument, e.g., `tokenizer.train_from_iterator(data_iterator, vocab_size=32768)`.
Install Rust by following instructions on `rustup.rs` (e.g., `curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh`) and then retry `pip install rustbpe`. Ensure `maturin` is also installed if building directly from the git repository.