Prompt Processing Versus Token Output in Language Models

APIFreeNVIDIA · Updated 2026-11-22 · 9 min read

Fast reading beside slow handwriting, a metaphor for prefill and decode
Reading a prompt happens in parallel; writing the answer happens one token at a time.

People who move from one inference engine to another, or who upgrade to a multi-GPU box, often notice a striking pattern. Their tools report prompt processing in the thousands of tokens per second, while generation sits around one or two hundred. A frequent question follows: why is reading so much faster than writing, and why does one engine seem dramatically better at it?

This article explains the two phases of running a language model, prefill and decode, in plain terms. You will learn what each phase does, which hardware resource limits it, why some engines are especially quick at prefill, and how caching the processed prompt changes the experience for coding agents and chat apps.

No maths beyond simple ratios is needed. The goal is to help you read benchmark numbers correctly and tune your setup for the work you actually do.

Frequently asked questions

What is prefill?

Prefill is the phase where the model reads your entire prompt, including system message, history and documents, and builds the internal state it needs before writing the first token. All prompt tokens are known in advance, so they can be processed together in large parallel batches.

What is decode?

Decode is the phase where the model produces the answer one token at a time. Each new token depends on the previous one, so the model cannot compute them all at once. Every step needs to read the model weights from memory again.

Why is decode limited by memory bandwidth?

For a single request, each decode step does relatively little arithmetic but must stream most of the model's weights through the GPU. The speed at which memory can deliver those weights caps how many tokens per second you get.

Why is prefill limited by compute instead?

Because many tokens are processed together, each weight read from memory is used for many calculations. That keeps the tensor cores busy, so the limit becomes raw compute rather than memory speed.

What is time to first token?

It is the delay between sending a request and seeing the first token of the answer. It is dominated by prefill, so long prompts and slow prompt processing make it grow. Queueing behind other requests also adds to it.

How does prefix caching differ from a normal KV cache?

Every request builds a KV cache during prefill. Prefix caching keeps that cache after the request ends and reuses it when a later request starts with the same text, so the shared part does not need to be processed again.

Which matters more for a coding agent?

Often prefill. Agents send long contexts with files, tool definitions and history, then receive relatively short replies. Fast prefill and good prefix caching can matter more than raw generation speed for that pattern.

Two phases inside every request

When you send a prompt to a model, the engine does two distinct jobs. First it processes the prompt, computing attention keys and values for every token and storing them in the KV cache. Then it enters a loop: predict the next token, append it, update the cache, repeat until the answer is finished.

These phases look similar from the outside, since both run the same neural network, but they stress hardware in opposite ways. Understanding that difference explains most of the numbers you see in benchmarks.

Prefill works in parallel

All prompt tokens are known before processing starts, so the GPU can treat them as a large matrix and multiply them by the weights in one go. That is exactly the type of work tensor cores are built for.

Decode works in sequence

The next token is unknown until the previous one is chosen. With a single request, each step processes just one token, so the GPU spends most of its time waiting for weights to arrive from memory rather than computing.

Why the speed gap is so large

Think of the model weights as a huge book the GPU must read through for every step. During decode with one user, it reads the whole book to write a single word. During prefill, it reads the book once and uses it to process hundreds or thousands of words at the same time.

That is why it is normal to see prompt processing reported at many times the generation speed. The exact ratio depends on GPU compute, memory bandwidth, model size and engine, but a large gap is expected rather than a sign that something is wrong.

Bandwidth sets a decode ceiling

A rough upper bound for single-stream decode is memory bandwidth divided by the bytes read per token. Quantization reduces bytes per token, which is why smaller formats generate faster. Mixture-of-experts models read only the active experts, which also helps, as explained in the article on active parameters.

Compute sets a prefill ceiling

Prefill speed scales with tensor core throughput and how well the engine keeps it busy. Newer GPUs and multi-GPU setups with tensor parallelism can raise prefill speed far more than they raise single-stream decode.

Wide conveyor beside a narrow chute
Prefill moves many tokens per weight read; decode moves one.

Why some engines prefill much faster

Users who switch engines sometimes see prompt processing jump by a large factor on the same hardware. Several engine features explain that. Optimised attention kernels avoid wasted memory traffic. Large prefill batches keep tensor cores saturated. Tensor parallelism across GPUs splits each layer so all cards compute at once instead of waiting in turn.

Engines built for serving, such as vLLM, put a lot of engineering into these paths, because time to first token is critical for many users at once. Tools focused on running anywhere may make different trade-offs, favouring broad hardware support and flexible quantization. The comparison of vLLM, llama.cpp and Ollama covers those trade-offs.

Layer split versus tensor split

When a model is split by layers across GPUs, each card processes its layers while the others wait, so adding cards adds capacity more than speed. Splitting tensors lets every card work on every layer simultaneously, which speeds up prefill noticeably when interconnects are fast.

Chunked prefill

Some engines break a long prompt into chunks and interleave them with decode steps of other requests. That keeps other users' answers flowing instead of freezing while one large prompt is processed.

Batching changes decode as well

Decode is bandwidth-bound only when few requests run at once. If the engine processes many users together, each weight read serves several sequences, and total throughput rises. This is the idea behind continuous batching: new requests join the running batch as soon as there is room, rather than waiting for a whole batch to finish.

For a single user, batching offers little. For a server shared by a team or used by an agent that fires several tool calls in parallel, it can multiply total tokens per second while each individual stream stays roughly as fast as before.

Speculative and multi-token decoding

Some setups use a small draft model or extra prediction heads to propose several tokens at once, then verify them in a single pass. When guesses are accepted often, decode speed improves noticeably. Gains depend heavily on the task and model.

Several GPUs linked inside a server chassis
Splitting each layer across GPUs speeds up prompt processing when links are fast.

Prefix caching and why agents love it

Agents and chat apps often resend almost the same prompt again and again: an identical system message, the same tool schemas, the conversation so far. Without caching, the engine repeats prefill on that entire prefix for every turn.

Prefix caching stores the KV cache of earlier requests and reuses it when a new prompt begins with the same tokens. Only the new part needs processing. For long agent sessions, time to first token can drop from seconds to a fraction of a second.

Keep the prefix stable

Caching only works on an exact token match from the start. Put fixed content, such as instructions and tool definitions, at the beginning, and avoid inserting timestamps or random IDs near the top of the prompt.

Cache memory competes with users

Cached prefixes occupy KV cache memory. The engine evicts old entries when space runs out, so a server with many users or long contexts may hit the cache less often. Offloading cache to system memory is one remedy, discussed in the KV cache offloading article.

Reading benchmark numbers correctly

When someone posts a pair of numbers such as prompt processing and token generation, ask what produced them. A prefill number measured with a very long prompt and a high batch size tells you little about a short chat. A generation number from a single stream tells you little about a busy server.

Useful benchmark notes include prompt length, output length, concurrency, quantization, engine version and GPU count. Without them, two numbers from different people are rarely comparable.

Measure your own pattern

A coding assistant, a chatbot and a batch summariser stress the phases differently. Benchmark with prompts and outputs that look like your real use rather than the defaults of a benchmark tool.

  • Time to first token: how long you wait before anything appears.
  • Prefill rate: prompt tokens processed per second.
  • Decode rate per stream: tokens per second one user sees.
  • Total throughput: tokens per second across all concurrent users.
Pre-prepared ingredients stored for reuse in a kitchen
Prefix caching reuses work already done for an identical start of the prompt.

Measuring the phases from a client

You do not need engine internals to estimate the two phases. With streaming, the time until the first chunk arrives approximates prefill plus queueing, and the rate after that approximates decode. The script below works against any OpenAI-compatible endpoint, including your own server or the free API on this site.

The hosted example uses free-ai, an independent model of about 35B parameters that is not affiliated with NVIDIA in any way, behind https://api.apifreenvidia.com/v1. Network latency and other users' traffic affect hosted numbers, so treat them as a rough picture rather than a hardware benchmark.

A practical example makes the difference concrete. Imagine a coding tool that sends twenty thousand tokens of files and instructions and receives a three-hundred-token reply. Even if decode runs at a modest speed, the reply itself takes only a few seconds; it is the wait before the first token that users notice. Halving prefill time therefore improves the experience far more than doubling decode speed. For a story-writing tool with a short prompt and a long answer, the opposite holds, and decode speed is what people feel.

Chunks are not always tokens

Most servers send roughly one token per streamed chunk, but some group several. For exact token counts, compare with the usage numbers a non-streamed request returns.

import time
from openai import OpenAI

client = OpenAI(base_url="https://api.apifreenvidia.com/v1", api_key="none")
prompt = "Explain the water cycle. " * 200  # a long prompt to make prefill visible

t0 = time.time()
first = None
chunks = 0
stream = client.chat.completions.create(
    model="free-ai",
    messages=[{"role": "user", "content": prompt + "\nSummarise in 300 words."}],
    max_tokens=500,
    stream=True,
)
for part in stream:
    if part.choices and part.choices[0].delta.content:
        if first is None:
            first = time.time()
        chunks += 1
end = time.time()
print(f"time to first token: {first - t0:.2f} s")
print(f"streamed chunks per second after that: {chunks / (end - first):.1f}")

Tuning for the work you do

If your work is long-context reading with short answers, such as agents, retrieval or document questions, prioritise prefill: engines with fast attention kernels, tensor parallelism and prefix caching. If your work is long-form writing for one user, prioritise memory bandwidth and efficient quantization.

And if you mostly need quick, occasional answers, the phases matter less than simple reliability. In that case a hosted model can be enough while you decide what hardware to build. Large commercial services still lead clearly on very long contexts with fast first tokens, because they run on data-centre hardware that home setups cannot match.

One setting that helps everywhere

Do not ask for more context than you use. Shorter prompts make prefill faster, free KV cache memory and often improve answer focus as well.

Stopwatch and notes for measuring response timing
Time to first token and streaming rate give a rough picture of both phases.
Try the free API

Send a prompt from the chat box on the home page: no key, no account and no card, just a quick look at how free-ai answers.

Read also