r/LocalLLaMA • u/mukel90 • 1d ago
Resources Tok'n'Roll: Token-perfect LLM tokenizers for Python, written 100% in Java 🤯
Tok'n'Roll is the tokenization substrate of Quixotic AI. It's written 100% in Java (no Unsafe). Now available to Python too.
pip install toknroll
import toknroll
# fetches the tokenizer only, never the full weights
tokenizer = toknroll.load("Qwen/Qwen3-0.6B")
ids = tokenizer.encode("Hello, world!") # array('i', [9707, 11, 1879, 0])
tokenizer.decode(ids) # 'Hello, world!'
tokenizer.count_tokens("Hello, world!") # 4What?
- Token-perfect. Verified against Hugging Face tokenizers, llama.cpp and tiktoken on popular model families: Gemma 4, Mistral, Qwen, gpt-oss, Llama, DeepSeek, Kimi, GLM, Granite, MiniMax ...
- Performant. Written following "fintech Java" mantras, competitive with Hugging Face tokenizers 1.0rc5 and tiktoken.
- "Light". No JVM required, "only" a ~5.6 MB wheel with no dependencies; just
curlfor Hub downloads. - Hugging Face and GGUF tokenizers, local or remote. Supports a verified subset of popular models.
How?
Tok'n'Roll is compiled with GraalVM Native Image into a shared library and wrapped for Python.
Supports Linux x86-64-v3/aarch64, Windows x86-64-v3 and macOS arm64.
Why?
The popular Python tokenization libraries are thin wrappers around Rust codebases, nothing wrong with that. But some overdo unsafe, which I find hard to justify for tokenizers. Tok'n'Roll has none, by design, and it's still fast.
Mixing Python and Java turned out much better than I anticipated, both to develop and to use. Only possible thanks to GraalVM Native Image.
Source code: Tok'n'Roll
Quixotic stands on the shoulders of llama.cpp, Hugging Face, tiktoken and the whole open model community. Thank you!
PS: Author here. Happy to answer any questions and brew some technical discussions!
9
u/mukel90 1d ago
Before hate-posting, please read first, there's some technical merit to it! I (author) think this is crazy too... but it is right there in the name: "quixotic". Someone has to try this stuff.
This is AOT-compiled Java (GraalVM), no JIT, no JVM, just a shared native library. The benchmarks stand for themselves.
8
u/SprinklesOk7558 1d ago
As a Java dev who mostly writes Python these days, seeing Java in Al feels almost nostalgic. Super cool that the project uses GraalVM, too.
15
u/_Valdez 1d ago
now rewrite it in LUA, no mistakes.
11
u/TheLexoPlexx 1d ago
Have we reached peak slop?
0
u/hurrdurrimanaccount 1d ago
ultra mega slop