Thank you for your interest in contributing! TinyBPE is an ultra-fast BPE tokenizer with a pure-C core.
git clone https://github.com/neluca/tinybpe.git
cd tinybpe
pip install -e ".[dev]"This installs TinyBPE in editable mode with all development dependencies.
pytest --cov=tinybpe --cov-report=term-missing tests/All tests must pass and coverage should stay above 90%.
We use ruff for linting and formatting, and mypy for type checking:
# Format
ruff format tinybpe/ tests/ scripts/
# Lint
ruff check tinybpe/ tests/ scripts/
# Type check
mypy tinybpe/ --strict- Line length: 120
- Quote style: double quotes
- Strict mypy checking on the
tinybpe/package - Python 3.9+ compatibility required
- An
.editorconfigis provided for consistent editor settings (indentation, line endings, charset).
tinybpe/ # Python package
__init__.py # Public API exports
tokenizer.py # Tokenizer class
trainer.py # Trainer class
_model_io.py # .tbm / .vocab file I/O
_registry.py # Built-in model catalog
src/ # C source code
bpe_module.c # CPython extension
bpe_tokenizer.c # BPE encode/decode engine
bpe_trainer.c # BPE training engine
_tree_core.c # AVL tree
models/ # Pre-built .tbm model files
scripts/ # Conversion utilities
tests/ # Test suite
- Convert the tokenizer to
.tbmformat using a conversion script (or write a new one inscripts/). - Place the
.tbmfile inmodels/. - Add an entry to
_MODEL_REGISTRYintinybpe/_registry.pywith the correct metadata (vocab size, regex pattern, special tokens). - Add a test in
tests/test_model_registry.pythat loads the model viaTokenizer.from_pretrained()and verifies roundtrip correctness.
- Fork the repository and create a feature branch.
- Make your changes, including tests.
- Run
ruff format,ruff check, andmypy --stricton changed files. - Run the full test suite with
pytest tests/. - Submit a PR against the
mainbranch with a clear description.
Releases are automated via GitHub Actions. When a new GitHub Release is created with a version tag (e.g., v1.1.0), the CI pipeline builds wheels for all platforms and publishes to PyPI.
Manual release steps:
# Update version in tinybpe/_version.py
# Update CHANGELOG.md
git tag vX.Y.Z
git push --tags
# Create a GitHub Release from the tagPlease see CODE_OF_CONDUCT.md.