Checking how many agents are working

How this works
Kontakt
← Blog
Two dark steel conveyor belts side by side, one wide and loaded with many glowing olive boxes, one narrow carrying a single box, with the AMARBARO mark above.
✎Blogbeitrag

Prefill and decode: the two speeds of a chat model

The short version

A chat model reads the prompt in one wide pass and writes the answer one token at a time, so the two phases run at different speeds and the long prompt is what delays the first word.

What this is about

A chat model does two different jobs. First it reads everything you sent. Then it writes the answer, one small piece at a time. The first job is called prefill. The second is called decode.

They run at very different speeds. That is why a short question starts answering at once, while a huge pasted document makes you wait before the first word appears.

Why it matters

When someone quotes "tokens per second" for a model, they usually mean decode, the writing speed. But what you feel as waiting often comes from prefill. If you paste a long file, the model must read all of it before it can write a single word.

Knowing the two phases helps you choose. A model with fast decode but slow prefill is pleasant for short chats and tiring for long documents. A setup tuned for big prompts may not be the one with the fastest typing.

How it works

Think of reading a letter and then writing a reply.

Prefill is reading. All the words of the letter are already in front of you. You can take in many words at once. A graphics card likes this. It can process a whole chunk of the prompt in one go, with all its workers busy. Every token of the prompt is known, so none of them waits for another.

Decode is writing. You cannot write word ten before word nine. Each new token depends on the one before it. So the model writes one token, then loops back for the next. For each token, the card has to bring the model's whole table of weights past its workers. The sums are small. The waiting for weights is large.

So prefill uses the card's strength, which is doing lots at once. Decode fights the card's weakness, which is the wait on memory.

A real example from our engine

We had a model that is a mixture of experts, which we cover in another article. Reading its prompt one token at a time, by running the writing path over and over, ran at about 67 tokens per second, whatever the prompt length. That is slow for reading, because it throws away what the card is good at.

On 19 September 2026 we landed a version that reads the prompt in chunks. On the same prompts and the same card, at three prompt lengths, it ran at:

prompt length one token at a time in chunks gain
1k tokens about 67 per second 524 to 531 7.9 times
8k tokens about 67 per second 428 to 432 6.4 times
32k tokens about 67 per second 246 to 247 3.7 times

Notice that the speed falls as the prompt grows. At 32k, the model has to compare each new token with many earlier ones, and that work grows with length. At that speed, a 32k prompt takes about 133 seconds to read. For that long a prompt, the time to first word is minutes, not instants.

The chunked version gave the same answers as the slow one on all 23 test prompts. That was the rule: a faster path is only allowed if it computes the same thing. Two faster variants we tried failed that check, because they added numbers in a different order, and adding numbers in a different order can change the last digit of the result, and once in a while the chosen token. We kept them off.

On a different model pack, our engine read a 16,384-token prompt in 4.54 seconds against 5.66 seconds for llama.cpp. And across 8k to 32k context, its reading speed stayed within about 1.3 times of llama.cpp's. Those are one-card numbers.

The writing side

Decode is the number most people quote. Our plain greedy decode of a 9B model with 4-bit weights ran at 130.7 tokens per second, against 110.0 for llama.cpp on the same twenty prompts. A big part of the gain was running the whole step as one launch instead of about thirty small ones, which helped when the job is mostly waiting.

What this means for you

  • Short prompt, long answer: decode speed dominates. Pick the model with the best writing speed.
  • Long prompt, short answer: prefill speed dominates. Your wait is the reading.
  • Same document, many questions: keep the start of the prompt unchanged so the engine can reuse its reading. See the article on the prompt cache.
  • Always ask which number was quoted. "Fast" can mean either one.

What our numbers do not show

The chunked reading result is for one model type and one card. We did not run the speed test on a model that holds all its weights on the card at long contexts, because it did not fit. Also, we kept the chunked mode as an option and not the default, because a full set of gates, including a 100,000-token test, had not all passed yet: the test only reached 75,052 tokens in our run.

Words you may not know

  • Prefill: reading the prompt, many tokens at once.
  • Decode: writing the answer, one token at a time.
  • Time to first token: the wait before the first piece of the answer appears.
  • Chunk: a block of prompt tokens handled together.
  • Context: the text the model has in front of it.
  • Mixture of experts: a model made of many specialist parts, a few of which run per token.
  • Identity check: a test that a faster version gives exactly the same tokens.

Try it

  • See the decode and prefill rows, with limits, on the mojo-baro project page.
  • When you test any local model, time two things separately. Send a very short question, then a long pasted text with a short question, and note how long the first word takes in each case.
  • Prefill as a Batch, the full chunked-reading story with its predictions and its failures.
  • Beating llama.cpp at Decode, Without Speculating, the writing-speed story.

Kommentare

Noch keine Kommentare.

Anmelden um zu kommentieren.