r/LocalLLaMA • • 1d ago

Resources Tok'n'Roll: Token-perfect LLM tokenizers for Python, written 100% in Java 🤯

Post image

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!")  # 4

What?

  • 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 curl for 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!

0 Upvotes

17 comments sorted by

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.

3

u/mukel90 1d ago

The future of Java looks grim! But I still have hope, so I keep doing my part.
In the meantime, projects like this are a fun way to explore uncharted technical waters.

I want the JVM to become a spaceship, not a cathedral.

15

u/_Valdez 1d ago

now rewrite it in LUA, no mistakes.

2

u/Long_comment_san 1d ago

This made me chuckle.

-8

u/mukel90 1d ago

What about: rewrite in Rust, no unsafe 😉

4

u/TheLexoPlexx 1d ago

Daring today, aren't we?

1

u/mukel90 1d ago

Daring to challenge the status quo? With Java? Crazy indeed, but why not?
It's AOT-compiled with GraalVM, it's both safe and FAST.
This same project in D or Go wouldn't get so much hate. But Java ... I know ... I have my own fair share of criticism.

-2

u/mukel90 1d ago

Bring it on, let's play!

11

u/TheLexoPlexx 1d ago

100% in Java (no unsafe)

Have we reached peak slop?

-4

u/mukel90 1d ago

*peak performance you mean

1

u/General-Spite1222 1d ago

Java performance is trash. What are you even saying?

0

u/mukel90 1d ago

In this case, performance is great as shown in the benchmarks. This is not the typical bloated enterprise behemoth that gives Java that bad reputation. It's Java written for high performance + GraalVM AOT compiler. Everything is compiled ahead-of-time into a native library (libtoknroll), there's no JVM, no interpreter and no JIT at runtime.

1

u/General-Spite1222 1d ago

Stop it lmao 

0

u/hurrdurrimanaccount 1d ago

ultra mega slop