r/graalvm • u/mukel90 • 9d ago
Tok'n'Roll: Token-perfect tokenizers for Python but 100% written in Java 🤯
https://pypi.org/project/toknroll/Tok'n'Roll is the (LLM) tokenization substrate of Quixotic AI and can be installed as follows:
pip install toknrollBut, why is a Python wheel being posted in r/java r/graalvm?
What if I told you that Tok'n'Roll is written 100% in safe Java e.g. no Unsafe.
Tok'n'Roll outperforms the industry standards: both Tiktoken and Hugging Face tokenizers (1.0rc5), which are Python wrappers over Rust codebases.
But why? The Rust codebases are riddled with unsafe usages ... not so safe after all. The Java implementation is quite nice IMHO, it just proves that Java can be extremely performant. Why wrap Rust when you can wrap Java.
This is one-of-a-kind project, inspired by u/OddEstimate1627 (Florian is that you?) work on StaticFX.
The whole Java-to-Python approach is quite interesting, the Python wheel is just ~5.6MB, supports Linux, Windows and macOS.
Benchmarks:

PS: I'm the author, everything is open source, Apache 2.0.
Note: I managed to get ~1.6K views until the r/java mods took the post down ... r/graalvm is a better fit since this use case is only possible thanks to GraalVM.
Python+Java outperforms Python+Rust while being safer ... compiled as native library, wrapped for Python, only possible with GraalVM.
2
u/OddEstimate1627 9d ago
Yes, that's me. Awesome! Are you using annotation-based bindings like hebi-charts or did you do it differently?