34 comments

  • maxdo19 hours ago
    Interesting :<p>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.<p>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.<p>Finally, interactions with Python are minimized, and threads have minimal interactions with each other.
  • cschmidt11 hours ago
    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.<p>And screw all the 0.1% haters on here, this is great stuff.
    • marcelroed9 hours ago
      Thanks for the kind words, Craig! I&#x27;m planning to do a technical writeup+paper and a presentation video on the project in the near future. Will make sure to share it with the Discord!
    • cs70210 hours ago
      That is my reaction too. It looks like great work!<p>Valuable not only for inference, but for training too (think proprietary datasets).<p>I would add, a single individual did this.<p>One person can make a difference :-)
    • victor1069 hours ago
      &gt; tokenization discord<p>How can I join this? Sounds interesting
      • cschmidt1 hour ago
        Send me an email (my address is in my profile)
      • glenngillen9 hours ago
        also subscribing to this!
        • cschmidt1 hour ago
          Send me an email (my address is in my profile)
    • gghfez8 hours ago
      &gt;the tokenization discord<p>Could I join this?
      • cschmidt1 hour ago
        Send me an email (my address is in my profile)
    • asdf8899010 hours ago
      [flagged]
      • cschmidt10 hours ago
        I’m not sure why you think this is ai slop. I work on tokenization research full time. My name is Craig Schmidt and I have a number of papers in the field. This researcher has done some very impressive work and I’m trying to defend him from the HN dismissive hoards.<p>There is a serious research community on tokenization, and we are quite interested in this work.
        • asdf8899010 hours ago
          Which part of “doesn’t seem to be aislop signs” made you think I believe your comment was aislop?<p>As I said, It just might be the low information density approach to talking recently that seems off to me.<p>To explain a bit more, I kept reading and waiting for the penny drop but nothing.<p>“I cloned your repo” — okay then what happened? Nothing? I put my shoes on this morning.<p>“I know the tokrniziation community wants to absord tje lessons” okay? Tell me the point please! I know the AI community wants to understand the universe.<p>“These are useful ideas”. Yes.<p>Of course, you could argue that my comment falls in the same category in the sense that I am not actually contributing to the topic at hand but I am peeved with all low the information noise.
  • XCSme4 hours ago
    Congrats, I love performance optimizations!<p>Hardware nowadays is so powerful, but our code so inefficient... I think most libraries&#x2F;apps could easily be 10x-100x faster if we really try to optimize them.<p>The good thing is, that now with AI, we&#x27;ll probably have the time to implement those optimizations rather quickly.
    • lionkor4 hours ago
      The issue is really with testing! You can do such optimizations but you have to be sure that the result is the same in ALL your use cases, so you need very good test coverage and quite good tests as well.<p>LLMs can help with the amount of test, and somewhat with the quality, but that&#x27;s not quite enough for doing heavy optimizations in existing, deployed products, in a normal sprint somewhere.
      • XCSme3 hours ago
        I think sometimes optimizations are more about using the right data structure&#x2F;ideas&#x2F;libraries.<p>In my case, I recently optimized for <a href="https:&#x2F;&#x2F;uxwizz.com" rel="nofollow">https:&#x2F;&#x2F;uxwizz.com</a> the session playback: before, it was saving the entire recording in one row, with updates, and loading it client-side in one chunk. I asked thr AI to, instead, store the recorded chunks in separate rows in db, and when replaying, to stream those chunks as needed. It implemented it perfectly, and everything is much snappier and lighter now.<p>So, the idea was &quot;store in chunks and stream the chunks&quot;, and the LLM does it. Yes, there were a few bugs, but those systems genetally either work or don&#x27;t. So testing for a 30 minutes after was enough, and now the system is live, and a client actually told me in person yesterday he loved the playback improvements.<p>I said in another comment somewhere, now knowing how to code isn&#x27;t important, what&#x27;s important is that you know what to ask, and what to look for when testing.
    • embedding-shape4 hours ago
      &gt; The good thing is, that now with AI, we&#x27;ll probably have the time to implement those optimizations rather quickly.<p>Haha, yeah, product&#x2F;executives will surely <i>now</i> see the benefits of optimizations instead of piling new features on top of new features with no cohesive idea about the design or architecture :)
      • XCSme3 hours ago
        In my experience, when adding new features with LLMs, most of those optimizations come automatically.<p>Good models now already follow best practices when implementing, better than junior devs.<p>I wrote a bit about this, I call it &quot;AI slap&quot;, lol:<p><a href="https:&#x2F;&#x2F;x.com&#x2F;XCSme&#x2F;status&#x2F;2079115230567686263?s=20" rel="nofollow">https:&#x2F;&#x2F;x.com&#x2F;XCSme&#x2F;status&#x2F;2079115230567686263?s=20</a>
        • embedding-shape3 hours ago
          &gt; most of those optimizations come automatically<p>We&#x27;re clearly thinking of very different &quot;optimizations&quot; here I think :) Do you have any concrete examples of this sort of optimizations you&#x27;d get automatically? In my experience, you get what you prompt for, if I don&#x27;t include to think about performance, they won&#x27;t think about performance, not sure what model would automatically consider things like that. Most of the time I use whatever SOTA OpenAI has on maximum reasoning level, fwiw.
          • XCSme1 hour ago
            Not only performance optimizations, but also UI&#x2F;UX.<p>If you ask to implement a custom dropdown that does something, it often comes with good spacing, aria-accessible tags, keyboard accessibility, etc. A junior dev wouldn&#x27;t think of all of those.<p>Also, it will probably choose the right HTML elements to use for it (i.e. maybe the modern native popover functionality instead of implementing it with custom JS, which would indeed be more efficient and less code).<p>I am not saying it would add caching by default (even though, it might suggest that), but it&#x27;s more likely to choose whatever the best options are and to use them as they should, including going around knowing limitations and gotchas.
  • ubedan7 hours ago
    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.<p>Have you considered publishing a rust crate as well? (If not, I volunteer.)
    • o_m2 hours ago
      According to Jevons paradox this will likely lead to more electricity used and more CO2 being released to the atmosphere, because it makes it more profitable to build another data center.
    • bob10296 hours ago
      &gt; I hope this code get popular, as it will save tons of electricity, money, CO2, etc.<p>I don&#x27;t think tokenization has ever been a meaningful bottleneck. JSON being fast falls into the same bucket much of the time. We spend way more energy on I&#x2F;O and storage than we do on serialization and tokenization.<p>If you are concerned with economics and the environment, request batching would make a bigger impact. The most expensive part of this whole thing is GPU underutilization. You can save 50% with OAI right now if you can figure out how to make your workload fit the batch pattern. Do your users always need answers <i>right now</i> or can we afford to wait a few days in some cases? Tool calling doesn&#x27;t &quot;time out&quot;. Wall clock does not exist in the LLM. It took me a while to get used to this.
    • a_c3 hours ago
      Is there any write up regarding the SimdJson Algo? Definitely love to read more of it!
  • onlyrealcuzzo18 hours ago
    This is awesome, but tokenization is typically &lt;0.1% of total inference time.<p>Presumably there&#x27;s a host of applications that just need to tokenize, though, and this would be great for those!
    • marcelroed13 hours ago
      Author here: Actually, depending on the nature of the inference you&#x27;re doing it can be quite significant. Here are some numbers for time-to-first-token (time to process the entire input and produce the first token of output) for an 8B Qwen3 model running on a single B200. Obviously these numbers are more significant with smaller models and on faster GPUs. Credit to fastokens [0] for the benchmark.<p><pre><code> sglang_speed [huggingface]: mean=10.31ms median=6.48ms p99=45.98ms rps=96.8 sglang_speed [gigatoken]: mean=10.13ms median=6.54ms p99=45.16ms rps=98.4 input_len= 2048: TTFT mean 30.74 -&gt; 29.05 ms (+5.5% reduction) | median 31.00 -&gt; 28.80 (+7.1%) | p99 33.02 -&gt; 32.02 (+3.0%) input_len= 8192: TTFT mean 105.20 -&gt; 96.36 ms (+8.4% reduction) | median 103.87 -&gt; 95.49 (+8.1%) | p99 126.88 -&gt; 113.84 (+10.3%) input_len= 32768: TTFT mean 687.05 -&gt; 633.66 ms (+7.8% reduction) | median 708.14 -&gt; 657.35 (+7.2%) | p99 728.95 -&gt; 678.79 (+6.9%) </code></pre> These are preliminary numbers, so I will need to do some more testing before including this in the README.<p>[0] <a href="https:&#x2F;&#x2F;github.com&#x2F;crusoecloud&#x2F;fastokens" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;crusoecloud&#x2F;fastokens</a>
    • scottcha17 hours ago
      I run an AI platform and we need to tokenize fast and early to make a lot of decisions on the subsequent steps (things like routing, rate limiting and such). Its really important to do this efficiently even though its not a large % of total end to end time for the request.
      • jaggederest16 hours ago
        To concur it&#x27;s &quot;latency critical&quot;, not &quot;performance critical&quot;, people often confuse those two - optimize it all, but especially the chained critical path latency!
        • dataflow12 hours ago
          Latency isn&#x27;t performance? Maybe you mean &quot;not throughput-critical&quot;?
          • jaggederest10 hours ago
            Just to clarify, latency is one form of performance, and a separate thing to optimize from total resource usage in more classic &quot;performance critical&quot; situations. That performance might be energy, space, or other dimensions besides latency. It might also be something like reliability, accuracy, precision, or even the very human factors like simplicity, modifiability, and visibility.<p>Heck, even latency alone you can just reduce the standard deviation and get smoother flows. Little&#x27;s law is a great callout here too, one of my favorite computer science principles.
          • rockwotj11 hours ago
            but according to Little’s law, if you improve latency, you also improve throughput, right?<p>If I have the same number of CPU cores and they all can do their work in half the time they can double the number of requests now
            • scheme27111 hours ago
              I don&#x27;t think that&#x27;s accurate. If tokenization takes say 10ms and the rest of the inference steps take 50 ms then, improving tokenization will improve the time to first token but won&#x27;t affect throughput much. After the first token, the inference steps effectively hide the tokenization time.
            • ludston4 hours ago
              It depends on whether or not latency is the constraint of throughput in your circumstances.
      • flockonus13 hours ago
        Same here, as we&#x27;re sitting in the middle between requests and what budget constraints are allowed given a particular token allowance there can be 10 ~ 100 milliseconds improvement in the UX (TTFT) given such massive tokenization speed up.
      • Xalutiono3 hours ago
        Whats the prefered LLM runtime to use? vLLM?<p>Tips &amp; Tricks on parameters&#x2F;settings?<p>What happens at peak? Do people have to wait now? Increase of latency?
      • quietfox14 hours ago
        ‘I run an AI platform’ I have so many genuine questions I don’t even know where to start.
        • NuclearPM14 hours ago
          Pick one. I would like to hear it.
    • pipsterwo17 hours ago
      1&#x2F;1000 of inference compute is a non-trivial workload at scale. Gartner estimates ~$28B in inference spend for 2026 making this a $28 million dollar per year workload (edit: based on the assumption above)<p>Source: <a href="https:&#x2F;&#x2F;www.gartner.com&#x2F;en&#x2F;newsroom&#x2F;press-releases&#x2F;2026-07-20-gartner-forecasts-worldwide-ai-platforms-and-models-market-to-grow-63-percent-in-2026" rel="nofollow">https:&#x2F;&#x2F;www.gartner.com&#x2F;en&#x2F;newsroom&#x2F;press-releases&#x2F;2026-07-2...</a>
      • boroboro417 hours ago
        The issue is it’s cpu compute which is underutilized in gpu clusters anyway, so practically it’s not really 1&#x2F;1000.
        • pipsterwo17 hours ago
          Totally, edited my comment to specify &quot;based on the assumption above.&quot; The main takeaway I was going for was 0.1% is not a small number in this context
    • noahbp16 hours ago
      Time to first token, especially for smaller models, can be sharply reduced.<p>Latency can be just as important as overall throughput, especially for inference providers like Groq and Cerebras.
      • fastball16 hours ago
        Tokenization is &lt;0.1% of the inference time for the first token in the same way it is &lt;0.1% for the last.
        • marcelroed16 hours ago
          Time to first token refers to the time until the model outputs one token, which includes the time to process the entire prompt (doing prefill). The GPU time per token is much lower when doing prefill, so the significance of tokenization is higher.
          • dingdingdang14 hours ago
            Have you done preliminary numbers on replacing tokenizer on, say, llama-server?
            • marcelroed13 hours ago
              Added numbers here: <a href="https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=49015014">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=49015014</a>
            • marcelroed13 hours ago
              Running the numbers now
    • treyd7 hours ago
      My understanding is that tokenization is largely serial, so for a large initial prompt it can make up a large chunk of input processing time since after handing it off to the model inference it&#x27;s (able to be) fully parallel across all tokens.
    • GenerocUsername17 hours ago
      Always good to make it 0.001%
    • brcmthrowaway17 hours ago
      [dead]
  • apollopower15 hours ago
    Cool stuff. From my understanding, this is less valuable at inference time and more useful when running offline pre-training data prep.<p>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.
  • zX41ZdbW12 hours ago
    This is exactly what we need! Will try: <a href="https:&#x2F;&#x2F;github.com&#x2F;ClickHouse&#x2F;ClickHouse&#x2F;issues&#x2F;108247" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;ClickHouse&#x2F;ClickHouse&#x2F;issues&#x2F;108247</a><p>It will be nicer if the README focuses more on per-core performance.<p>About the actual algorithm - will something like matching in a perfect hash table help?
  • luciana1u16 hours ago
    engineering effort to make something 1000x faster that accounts for 0.1% of total runtime is the most software developer thing imaginable
    • minimaxir14 hours ago
      I initially had a Rust-based word cloud generator that generates word clouds in high resolution in ~100 milliseconds whereas it would take other generators a couple seconds to do the same thing. Does the world need a super-fast word cloud generator? No. Do I <i>want</i> a super-fast word cloud generator? Yes.<p>I later found enough optimizations to reduce the generation speed all the way down to ~16ms. Do I need a word cloud generator that fast? No. But if I have a word cloud generator it&#x27;s going to be as fast as possible dammit.
    • piker16 hours ago
      &quot;The pursuit of excellence does not need justification.&quot;<p><a href="https:&#x2F;&#x2F;x.com&#x2F;mitchellh&#x2F;status&#x2F;2074225453217505494" rel="nofollow">https:&#x2F;&#x2F;x.com&#x2F;mitchellh&#x2F;status&#x2F;2074225453217505494</a>
    • michaelmior16 hours ago
      This depends on what your workflow is. There are use cases for tokenization that don&#x27;t always involve immediately feeding the text into a model.
    • hansvm12 hours ago
      1000x improvements unlock qualitatively new capabilities, even when only applied to subcomponents. Moreover, the fact that it&#x27;s only 0.1% of the runtime is usually [0] an artifact of the entire project being treated that way -- why write this the right way when it won&#x27;t move the needle on the composite project?<p>[0] Yes, for LLMs we&#x27;re closer to the bound than 1000x. Even there though, basic pytorch operations are often 2x slower than simple rewrites, better scheduling algorithms have a history of closer to 5x-10x gains, and all of that supposes you don&#x27;t have further architectural improvements over time. Moreover, who&#x27;s to say that legitimately fast tokenization doesn&#x27;t unlock additional capabilities elsewhere which people have ignored because it was never close to viable?
    • Xalutiono3 hours ago
      AI now consumes TWh. This is more energy than a lot of countries on the whole planet.<p>If this increases efficiency, it has real impact. 0.1% is A LOT at scale.
    • brookst13 hours ago
      If you&#x27;re tokenizing to run a tiny SLM for routing purposes, it can be way more than 0.1%.<p>This is the &quot;GPU driver optimizations don&#x27;t matter because PC&#x27;s sit idle at the desktop most of the time&quot; mindset.
    • yrds9612 hours ago
      This can make a huge difference for local models on modest hardware
    • alansaber16 hours ago
      It&#x27;s pretty funny but then again, why not if it&#x27;s as trivial to simplify as it appears
      • Cthulhu_3 hours ago
        I don&#x27;t think this was particularly trivial, but I do think that thanks to AI assisted coding there&#x27;s more capacity for making improvements that &quot;don&#x27;t seem worth it&quot; at first or when you look at it as a percentage of total.<p>But look at e.g. Biome; optimizing the formatter didn&#x27;t seem worth it for a long time because it only took &lt;1s to format most files. But it&#x27;s &lt;1s times millions of files, billions of times a day when you add up every developer that used Prettier for their code formatting - it adds up.<p>And I&#x27;m convinced Biome triggered or was part of a bigger effort to convert JS based tools to native code. This saved time and energy, which in turn allows for faster and &#x2F; or more feedback loops, which in turn allows faster turnaround cycles for software development (bet it human or LLM assisted), etc. It&#x27;s a compound effect.<p>I don&#x27;t know enough about tokenization or whatever to judge this one, but if it&#x27;s 1000x as fast as it used to be, there will be less need to try and avoid or minimize tokenization which may lead to new applications.
    • NuclearPM14 hours ago
      1000x faster on 0.1% of runtime = 0.1% saved. Amdahl remains undefeated.<p>Globally that’s ~50 GWh&#x2F;yr, or ~5.7 MW continuous:<p>• 4,700 American homes<p>• a week of British tea
    • antonvs7 hours ago
      Except, their benchmarking shows this can speed up time to first token by up to 10%.
  • 0xnyn18 hours ago
    I had to stare at that chart for a minute just to let the numbers sink in. It&#x27;s genuinely mind-bending, incredible ship OP
  • Antibabelic6 hours ago
    &quot;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&#x27;s Git history).&quot;<p>So much for &quot;human programming is obsolete&quot;.
    • porridgeraisin2 hours ago
      For context:<p>In the final stages of the project, AI was used to assist:<p>Implementing the user-facing API Widening of compatibility, for instance generalizing and porting the pretokenizer implementations to support more tokenizers, less interesting features like padding&#x2F;truncation&#x2F;unicode normalization Porting SIMD strategies between AVX512&#x2F;AVX2&#x2F;NEON Final profiling stages and the last ~4x worth of performance from eliminating branching and improving the pretoken cache hierarchy Refactoring and code reuse
    • Cthulhu_3 hours ago
      Nobody except people trying to sell AI are claiming human programming is obsolete though.
  • swiftcoder17 hours ago
    So the question becomes, how many other parts of the inference pipeline have left 1000x optimization opportunities lying on the table?
    • fastball16 hours ago
      The problem with the rest of inference is that changes are not trivially correct or incorrect, as they are with the tokenization layer.
      • michaelmior13 hours ago
        Some changes certainly can be. If the model produces the exact same output for a fixed seed across a variety of inputs after a code change, I think it&#x27;s reasonable to expect that the change is correct. There are also mathematical transformations that can be applied in some cases that are provably correct. (Not suggesting there&#x27;s necessarily anything of this nature that will lead to 1,000x improvement though.)
      • janwas7 hours ago
        hm, maybe not so trivially correct here. Do I understand correctly that incorrect results can happen as a result of a 42-bit hash collision? That could happen after less than one MB of input, given the simple one-mul hash.<p>BTW throughput is measured for a 12 GiB file. Would be interesting to see the throughput for something more like 32 KiB, with cold start (token cache not yet populated).
      • nixon_why6915 hours ago
        Eh, linear algebra changes are still easy to measure correctness, it&#x27;s just that you&#x27;re competing with 50 years of research for most of them, less low hanging fruit.
    • ProofHouse16 hours ago
      the answer is many! This would take hours to write. Full teams and research on nearly every part. So many &#x27;unlocks&#x27; coming.
    • parineum16 hours ago
      I&#x27;m sure there&#x27;s been a lot more effort put into the other, more consequential, portions of inference time.
  • fwip19 hours ago
    What sort of setups do people have that are bounded by the speed of the tokenizer?
    • marcelroed18 hours ago
      Author here! In my case it&#x27;s mostly pretraining experiments, where you might want to change your data mixture&#x2F;filtering&#x2F;processing of training data, and splits are usually done at a token-level instead of a text level. In this case we usually run for days on a huge number of CPUs to finish tokenizing something like DCLM.<p>From what I can tell it&#x27;s also useful for inference when considering time-to-first-token (TTFT) as reported by fastokens.[0]<p>I&#x27;m not sure about the proprietary inference engines, but in the open source ones tokenization is done before looking up if a text sequence is present in the KV-cache. If you have a long prefix that&#x27;s been seen before (say a system prompt), the time for tokenizing that will be a large part of your TTFT. The tokenizer cache should be warmed up in this case, so the throughput for Gigatoken would be significantly higher than reported in the repo.<p>[0] <a href="https:&#x2F;&#x2F;github.com&#x2F;crusoecloud&#x2F;fastokens" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;crusoecloud&#x2F;fastokens</a>
      • wren699116 hours ago
        &gt; I&#x27;m not sure about the proprietary inference engines, but in the open source ones tokenization is done before looking up if a text sequence is present in the KV-cache<p>Is this necessary? Tokenisation is deterministic, so for a hit&#x2F;miss check you can lookup on (a hash of) the source text instead of the tokens. You only need the tokens once you&#x27;re seeking for the exact token index having determined there is a hit. That means tokenisation can proceed in parallel with your cache query, and since these caches are distributed in production systems I imagine the query itself could be slow.<p>I&#x27;m not trying to undermine the utility, and this is obviously excellent work. Being able to tokenise faster on the client also seems useful (precise token counts for context pruning heuristics, instead of `chars &#x2F; 4`), and on a phone your work translates directly to energy savings. I&#x27;m just curious about the cache lookup point.
        • marcelroed15 hours ago
          It&#x27;s usually not as binary as &quot;hit&quot; or &quot;miss&quot; with a prefix cache, and you need to know the token boundaries to know where the cache hit ends.<p>The current structures used for KV-caching in vLLM and SGLang work by chunking the KV-cache tokens into prefix trees, and you need to hash chunks of tokens in order to look up in these, meaning you need to be able to slice up your tokens by token count.<p>Again I have no idea what proprietary engines are doing, but this is why open source stuff needs to tokenize before cache lookup at least.
          • wren699113 hours ago
            &gt; and you need to hash chunks of tokens in order to look up in these, meaning you need to be able to slice up your tokens by token count.<p>The hash just has to uniquely identify the contents. I still don&#x27;t see what stops you from walking the chunk tree by chunks of characters instead of chunks of tokens, then lazily finding the token boundary once you&#x27;ve found the longest common <i>chunk</i> prefix and also (in parallel) tokenized the input.
      • fwip18 hours ago
        Very cool, thanks.
      • lostmsu18 hours ago
        Can&#x27;t you tokenize in preloading on demand?
        • marcelroed18 hours ago
          You can, but this usually results in sequences with padding&#x2F;truncation, since you won&#x27;t know how many tokens your inputs map to before you actually tokenize them. This also makes shuffling difficult.<p>In practice every training project I&#x27;ve worked on does tokenization in a separate data processing phase.
    • andersa18 hours ago
      Wait, since when does it matter whether something being hyper-optimized is useful? The computer going brrrr on an interesting problem is in itself the goal!
      • fwip18 hours ago
        That&#x27;s fair, I just figure there are useful scenarios as well. Apologies if I came off as dismissive!
        • ac2u18 hours ago
          It didn’t come off as dismissive to me. I was curious as well as to where such optimizing helps and knew that the answers to your question would help me discover use cases I didn’t think of
    • janalsncm18 hours ago
      If you are training an LLM, you need to tokenize the text before it’s trained on. A lot of time this can be done in parallel with the GPU though.<p>I have spent way too much time waiting 10-15 minutes tokenizing my training dataset only for the run to crash over some minor bug after that. (If I was smarter, I’d test on a smaller batch first.)
      • antonvs7 hours ago
        &gt; … only for the run to crash over some minor bug after that<p>Ah, Python.
        • janalsncm4 hours ago
          An example would be setting batch size too high causing OOM which isn’t really a python problem.
    • SnowflakeOnIce14 hours ago
      I worked on a system a couple years ago with a BERT-based model (64M parameters) used for classification. The rest of the system could process data at gigabytes per second, and so here tokenization at a measly few megabytes per second really slowed things down. The model inference <i>was</i> more expensive than tokenization, but tokenization was still &gt;10% of total runtime.
    • rhdunn18 hours ago
      It can be useful for checking input token usage before sending it to the model, e.g. preventing calls above a given token bound or grouping requests into batches.<p>It can also be used by the LLMs to provide the input and output token counts on the different APIs, though I&#x27;m not sure if this is how llama.cpp or other OpenAI-like APIs calculate the input&#x2F;output tokens of a request.
      • charcircuit18 hours ago
        But are those bounded on the speed of tokenization?
    • avereveard18 hours ago
      I&#x27;ve data where i cannot store metadata that i need to search semantically so i embed it on the fly at every search with static embedding and tokenizing was more than 99% of the cpu time. Granted that was due the naive implementation of the default tokenizer which was o^2 with document length and just switching to a proper scanner solved most of it without going to simd and whatnot, but still.
    • imperio5918 hours ago
      Pre-training data is pre-tokenized ahead of time before being used to not waste any GPU compute.<p>A massive speedup like this is a nice efficiency savings on some of these data pipelines for sure.
  • chocrates16 hours ago
    Practically I would need to wait for hugging face models to adopt this? My harness tokenizer is just an estimate since the model tokenizes on my api calls?
  • hansvm11 hours ago
    For the lazy among us (not me of course), is there a small number of core techniques which enabled this for even a single architecture and single CPU core?
  • mcpindex-ai10 hours ago
    Tokenization is one of the most under appreciated and under optimized part of the agentic stack- not sure if this is truly production grade, and applicable across all hardware+stack combo but this for sure can help inspire a lot of that work. Good work!
  • sashank_150918 hours ago
    This is really cool, great work!
  • nxpnsv12 hours ago
    Surely it should be kilotoken
  • phplovesong7 hours ago
    Is tokenizing really the bottleneck? If we go from 20ms to 15ms does it really matter?
    • gnabgib7 hours ago
      You sound like someone who used to write fastruby
      • phplovesong7 hours ago
        Never heard of fast ruby. My point is tokenizing is rarely a bottleneck, as 99% of time is spent in inference.<p>So you speed up 1% of the pipeline by some factor, and the end result is unobservable for a human.
        • antonvs6 hours ago
          Time to first token is observable by a human, and they’re reporting up to 10% reduction there.<p>Plus, inference is not the only place tokenization happens. This can make a big difference during development of ML models.
  • anonymousmoos17 hours ago
    Quality software here.
  • dmezzetti18 hours ago
    Very interesting project! Are there benchmarks for the &quot;compatibility mode&quot; or are all the numbers for the Gigatoken API?
    • marcelroed18 hours ago
      Numbers are for the Gigatoken API, but compatibility mode just means eating a bunch of Python overhead (creating lists, reading strings to bytes). You can expect a modest ~200-300x speedup with compatibility mode depending on how you use it.
      • robotresearcher15 hours ago
        &gt; a modest ~200-300x speedup with compatibility mode<p>marcelroed is modest, this speedup is not. Good work.
    • marcelroed18 hours ago
      I can add some benchmarks for compatibility mode in the future. I have a little more juice to squeeze out of the Python interop though, so not quite ready for it yet.
  • zerolines18 hours ago
    wow, best release all week.
  • semiinfinitely18 hours ago
    quite excellent software
  • tim_tihub37 minutes ago
    [dead]
  • fenestella2 hours ago
    [flagged]
  • Timmyzzz4 hours ago
    [flagged]
  • wacjiomv7 hours ago
    [dead]
  • saschag6 hours ago
    [flagged]
  • histiq2 hours ago
    [dead]
  • luck771015 hours ago
    [dead]
  • kiaansaraiya13 hours ago
    [dead]
  • sghn6 hours ago
    [flagged]
  • wacjiomv7 hours ago
    [flagged]
    • marcelroed7 hours ago
      The output tokens are identical in either case, but there are quite a few additional settings and formats that huggingface compat mode can generate. In general it also requires inputting Python lists of Python strings.<p>The Gigatoken API instead prefers input bytes or paths to iterate, and returns an Awkward array by default. Again, no difference in correctness.
  • vmware50817 hours ago
    We should just rewrite everything in Rust, especially bloated Python code, and the world would be a better place. ;) Disclosure: I&#x27;m a Rust advocate!
    • minimaxir16 hours ago
      Both the example libraries compared (tokenizers and tiktoken) are Rust-based with Python bindings. There&#x27;s just a few levers in Rust that can speed it up <i>even more</i> particularly with LLM assistance as the AI Use Discloure here notes:<p>&gt; Final profiling stages and the last ~4x worth of performance from eliminating branching and improving the pretoken cache hierarchy
    • SOLAR_FIELDS17 hours ago
      1 year ago everyone would have called you insane for suggesting this. Now we all shrug and say yeah maybe we can do this and it’s actually a good idea?
    • weberer16 hours ago
      We should rewrite all Rust code in Python. Not for any technical reason. I&#x27;m just sick of the Rust cult at this point.