GigaToken: A Drop-in Replacement for 1000x Faster Language Model Tokenization

GigaToken: ~1000x faster Language model tokenization

GigaToken: A Drop-in Replacement for 1000x Faster Language Model Tokenization

I built GigaToken to solve the bottleneck of slow text processing in language modeling. This Rust-based tool offers a drop-in replacement for HuggingFace Tokenizers and Tiktoken, delivering speeds up to 1000 times faster on modern CPUs. By optimizing pretokenization with SIMD and minimizing Python overhead, you can tokenize massive datasets like Common Crawl in hours instead of days while maintaining exact compatibility with existing workflows.

At the rates we see on the EPYC CPU, you could tokenize the entirety of Common Crawl in just under 6.5 hours!
  1. maxdo

    Interesting :

    Q: Did you just way over-optimize for a specific CPU and tokenizer? How is it so fast?

    No, I way over-optimized for every combination of these! The results are very consistent across CPUs (modern x86 and ARM), and across specific tokenizers.

    The major improvements are in optimizing heavily an implementation that usually is outsourced to a Regex engine (pretokenization) using SIMD, minimizing branching and other tricks, as well as heavily optimizing caching of pretoken mappings (if a word has been seen before, look it up its encoded tokens efficiently). Caching is a very hard problem in this domain since the cache grows very quickly, and pretoken distributions are very long-tailed.

    Finally, interactions with Python are minimized, and threads have minimal interactions with each other.

  2. cschmidt

    Can I say this seems to be fantastic work. I cloned your repo earlier today after seeing it on the tokenization discord. I know everyone in the tokenization community wants to absorb the lessons of how you got such a speedup. The caching and replacing the regex for pretokenization seem like generally useful ideas.

    And screw all the 0.1% haters on here, this is great stuff.

  3. XCSme

    Congrats, I love performance optimizations!

    Hardware nowadays is so powerful, but our code so inefficient... I think most libraries/apps could easily be 10x-100x faster if we really try to optimize them.

    The good thing is, that now with AI, we'll probably have the time to implement those optimizations rather quickly.

  4. ubedan

    Spectacular... Reminds me of the SimdJson algorithm in terms of jaw dropping nearly unbelievable speeds through creative programming. I hope this code get popular, as it will save tons of electricity, money, CO2, etc.

    Have you considered publishing a rust crate as well? (If not, I volunteer.)

  5. onlyrealcuzzo

    This is awesome, but tokenization is typically <0.1% of total inference time.

    Presumably there's a host of applications that just need to tokenize, though, and this would be great for those!

  6. apollopower

    Cool stuff. From my understanding, this is less valuable at inference time and more useful when running offline pre-training data prep.

    When tokenizing terabytes of text for your training corpus, the speedup here is probably doing real work in saving you time (and money?). You get a faster iteration cycle when figuring out and adjusting your datasets.

  7. luciana1u

    engineering effort to make something 1000x faster that accounts for 0.1% of total runtime is the most software developer thing imaginable

  8. Antibabelic

    "AI Use Disclosure: A majority of this code base was crafted by hand without any use of AI (which can be seen from the project's Git history)."

    So much for "human programming is obsolete".

More from this day

2026-07-22