AcademyAcademy
DocsLearnGitHub

Course

AI & LLM Foundations

Loading progress...

  1. 1

    The Idea Behind AI Models

    5 min read

  2. 2

    Agents, Tools and MCP

    2 min read

  3. 3

    Benchmark Methodology

    1 min read

  4. 4

    Technical Correction Register

    3 min read

  5. 5

    AI Network Infrastructure

    4 min read

  6. 6

    Mechanistic Interpretability

    3 min read

  7. 7

    Hardware Economics and Inference

    6 min read

  8. 8

    KV Cache, SSM State, and Context Engineering

    5 min read

  9. 9

    Quantization, Optimization, and Model Metadata

    4 min read

  10. 10

    Self-Attention, Multi-Head Attention, and Cross-Attention

    5 min read

  11. 11

    Source Audit

    2 min read

Publications
  • All publications
  • Publication 01Why a Bigger GPU Doesn't Always Mean Faster AI Inference
  • Publication 02Why Your AI Takes Time to Think Before It Starts Speaking
  • Publication 03The KV Cache: The Memory Behind Every Token
  • Publication 04Multi-Head Attention, Grouped-Query Attention and Multi-Query Attention
← Source publicationsRelated curated lesson →

Source publication. Illustration placeholders and evidence labels are preserved as supplied.

Why Your AI Takes Time to Think Before It Starts Speaking

Understanding Prefill, Decode, and the Two Different Workloads Behind LLM Inference.

When you send a prompt to an AI model, the model does not immediately begin writing its answer. It first has to process what you sent. Only after that can it start generating a response.

These are two distinct phases of inference:

  1. Prefill — the model processes the input prompt.
  2. Decode — the model generates the response, one token at a time.

That distinction matters because the two phases put different demands on the hardware. A model can process a prompt quickly but generate its answer relatively slowly. It can also have a noticeable delay before the first token appears, followed by fast generation.

So, when we ask how fast an AI model is, what exactly are we measuring?

The answer depends on which part of inference we are talking about.

The speed of an LLM response is not one performance number. Understanding how quickly it processes your prompt and how quickly it generates your answer requires looking at two different phases of inference.

Comparison of prefill and decode, including KV-cache use, parallelism and typical bottlenecks

AI-generated comparison supplied with the notes. It illustrates typical workloads: prefill can be chunked, and latency also includes other system overhead.

1. Prefill: Processing the prompt

Imagine handing someone a document and asking them to read it before answering a question.

Before they can respond, they need to take in the information. The longer the document, the more information they have to process.

That is broadly what happens during prefill.

The model receives the input prompt, converts it into tokens, and processes those tokens through its layers. This includes the attention and other computations needed to build the internal representations used to produce the next token.

An important detail is that the model can process many prompt positions in parallel. Causal attention still ensures that a token can only use information from positions that are allowed to precede it; parallel processing does not mean that the model ignores the order of the sequence.

During prefill, the model also builds the initial key-value (KV) cache. This cache stores attention information from the processed prompt so that the model does not have to recompute the entire prompt history for every generated token.

Once prefill has progressed far enough to produce the first output token, the system can begin the decode phase.

Why prefill can be fast

Prefill processes a group of input tokens together. This creates substantial parallel work for the GPU.

For sufficiently large prompts, the model performs large matrix operations across many token positions. GPUs are designed to execute this kind of parallel computation efficiently.

This is why prefill is often described as compute-intensive.

That does not mean prefill is always fast. A very long prompt, a large model, limited compute capacity, or inefficient execution can still make it take considerable time. But the important distinction is that prompt positions can be processed together rather than waiting for each prompt token to be generated one after another.

2. Decode: Generating the response

Now imagine that the person has finished reading the document and is ready to answer.

They do not produce the entire answer in one operation. They formulate the response progressively, word by word.

An LLM does something similar, except its basic units are tokens, not necessarily whole words.

During decode, the model generates a token, adds it to the sequence, and uses the updated sequence to generate the next token. This continues until the model reaches a stopping condition or the generation limit.

Unlike prefill, ordinary autoregressive generation is sequential: the next token depends on the tokens generated before it.

The KV cache makes this process more efficient. The model can reuse attention information from the prompt and earlier generated tokens instead of recomputing the full history from scratch on every step.

However, the cache does not make each decode step free. For every new token, the model still has to execute its layers, use the model's weights, and attend to the relevant cached history. The cache is also extended as new tokens are generated.

AI-assisted diagram: prefill produces the first output token; subsequent decode steps process the preceding output and extend the cache.

Why decode can be slower

At low batch sizes, decode is often memory-bandwidth-bound.

A useful way to think about this is that the GPU may have to move a large amount of model-weight data through memory to generate each new token. If the model is large relative to the amount of work being performed for that token, moving the data can become a major part of the time required.

This is different from prefill, where many prompt positions provide more parallel computation and can make better use of the GPU's compute capacity.

Decode also has a sequential dependency: the model needs the current token before it can determine the next one. It cannot simply generate the entire response in parallel in the same way it processes prompt positions during prefill.

The result is that a model may process a prompt at a high token rate but generate its response at a much lower token rate.

This is a common pattern, not a universal law. Model architecture, context length, hardware, batch size, quantization, runtime implementation, and scheduling all affect the result. Larger batches, for example, can improve weight reuse and hardware utilization, changing the balance between compute and memory traffic.

3. The two phases, side by side

PrefillDecode
Main jobProcess the input promptGenerate the response
Token positionsProcesses many prompt positions togetherNormally generates one new token per sequence step
ParallelismHigh parallelism across prompt positions, subject to causal attentionSequential dependency between generated tokens
KV cacheBuilds the initial cacheReuses and extends the cache
Common bottleneckOften compute-intensiveOften memory-bandwidth-bound at low batch sizes
User-visible effectStrongly influences time to first tokenStrongly influences the delay between generated tokens

The table describes common inference behaviour, not fixed rules for every model or deployment.

4. The performance metrics that explain what you experience

A single tokens-per-second figure cannot fully describe an LLM's responsiveness. It is important to know what was measured and which phase the measurement represents.

Time to First Token (TTFT)

Time to First Token, or TTFT, measures how long a user waits before the first generated token becomes available.

A simplified view is:

[ TTFT \approx T_{queue} + T_{prefill} + T_{overhead} ]

The exact measurement boundary depends on the serving system. Some systems include queueing, network, or other overhead; others measure a narrower interval.

A long TTFT can make a model feel slow even if it generates the rest of its answer quickly.

Inter-Token Latency (ITL)

Inter-Token Latency, or ITL, describes the time between generated tokens. It helps explain how quickly the answer appears after generation has started.

For a consistently measured single stream, decode throughput and average inter-token latency are approximately related by:

[ Decode\ TPS \approx \frac{1}{Average\ ITL\ (seconds)} ]

For example, an average interval of 0.05 seconds corresponds to roughly 20 tokens per second.

This is a simplified relationship. The precise result depends on whether the metric includes the first token, how timing is aggregated, and whether the system is serving one sequence or multiple sequences.

Prompt processing throughput

Prompt processing throughput is usually expressed in tokens per second. It describes how quickly the system evaluates prompt tokens during prefill.

When comparing results, check whether the reported token count includes all prompt tokens or only tokens that were newly evaluated. Prefix or prompt caching can mean that some prompt tokens are reused rather than processed again.

Decode throughput

Decode throughput is also expressed in tokens per second, but it describes generated output tokens.

This is the number people often quote when they say a model generates at a particular speed. It should not be confused with prompt processing throughput.

Request throughput

Request throughput describes how many requests a serving system completes over a period of time. It becomes especially important when multiple users or sequences are being served together.

A system that generates one response quickly is not necessarily the system that serves the largest number of requests efficiently. Batch size and scheduling can change aggregate throughput without producing the same improvement in the latency experienced by each individual user.

5. What the measurements from our experiments show

The experiments provide useful examples, but they do not all support the same kind of claim. The distinction between an actual request record, a qualification summary, and a test fixture matters.

A Gemma 4 request: a concrete example

One supplied per-request record from a Gemma 4 E4B qualification run reports:

MeasurementReported value
Prompt tokens evaluated (prompt_n)56
Cached tokens (cache_n)6
Prompt evaluation time55.633 ms
Prompt processing rate1,006.60 tokens/s
Generated tokens (predicted_n)512
Generation time6,838.459 ms
Generation rate74.72 tokens/s
End-to-end request latency7.3563 s

What this example illustrates: in this particular request, the reported prompt processing rate was much higher than the reported generation rate. The request spent considerably more time generating 512 output tokens than processing the short prompt.

This is an individual response record, not a general benchmark of Gemma 4. The prompt was short, the request had only six cached tokens, and the result should not be used to predict performance for other prompt lengths, models, hardware configurations, or serving conditions.

It is useful because it makes the difference between the two phases visible in one request.

<small>Evidence classification: REPORTED — values from one supplied Gemma 4 E4B per-request record. The interpretation is limited to that request.</small>

What the Qwen qualification results can—and cannot—tell us

The supplied Qwen qualification summaries report aggregate workload results for a Qwen3.8-27B GGUF configuration using Q8_0 KV cache and an 8,192-token context setting.

Two summaries were provided:

Qualification summaryCompleted / totalPrompt tokensCompletion tokensP50 latencyP95 latencyQualification score
Initial qualification6 / 1097,2979,5346.644 s35.109 s0.7733
Phase 2.5 qualification9 / 15145,42513,1906.712 s36.402 s0.7778

These are qualification summaries, not per-request prefill and decode measurements. They tell us about the workload totals, completion counts, latency distribution, and qualification score. They do not provide enough information to calculate a defensible Qwen prefill rate or decode rate.

There is also a telemetry unit test containing example values such as 2,500 prompt tokens, 2,145 cached tokens, a prompt evaluation time of 1,478 ms, and a predicted generation rate of 20.44 tokens per second.

That test is useful for checking whether the application extracts and calculates telemetry as intended. But its response dictionary is constructed test data. It is not evidence that a real Qwen request produced those measurements.

A few calculations can still help explain the fixture:

  • 2,500 total prompt tokens minus 2,145 cached tokens leaves 355 tokens.
  • 355 tokens divided by 1.478 seconds is approximately 240.2 tokens per second, close to the fixture's reported 240 tokens per second.
  • 150 generated tokens divided by 20.44 tokens per second is approximately 7.34 seconds.
  • Dividing 2,145 cached tokens by 240 tokens per second gives 8.94 seconds. This is an estimated amount of evaluation time avoided under that assumed rate, not an independently measured time saving.

These calculations help interpret the test fixture. They do not turn it into a benchmark.

<small>Evidence classification: qualification figures are REPORTED summaries; arithmetic above is CALCULATED from the supplied fixture; actual per-request Qwen prefill/decode performance remains UNKNOWN from the evidence available for this article.</small>

6. Why one tokens-per-second number is not enough

Suppose two models both advertise 50 tokens per second.

That number alone does not tell you:

  • How long either model takes to process a long prompt.
  • How long you wait before the first token appears.
  • Whether the 50 tokens per second refers to prompt processing or output generation.
  • Whether the figure was measured with one request or a batch of requests.
  • Whether prompt caching was enabled.
  • Whether the number is an individual-request result or an aggregate serving result.

For an interactive assistant, both the initial wait and the pace of generation matter.

A model with a high prompt processing rate but a low decode rate may begin responding quickly and then generate slowly. Another model may have a slower prefill phase but generate output at a higher rate once it starts.

Neither model can be judged properly from a single throughput number.

Batching adds another layer. When a server processes multiple sequences together, it can often use the GPU more efficiently and improve overall throughput. But aggregate throughput and the experience of one user are different measurements. A throughput improvement does not automatically mean every individual request has lower latency.

7. The practical takeaway

When evaluating an LLM deployment, measure the two phases separately.

At minimum, record:

  1. TTFT — how long the user waits for the first token.
  2. Prompt processing throughput — how quickly input tokens are evaluated.
  3. Decode throughput — how quickly output tokens are generated.
  4. Inter-token latency — how long the user waits between generated tokens.
  5. Request throughput — how many requests the serving system completes over time.

Also record the conditions behind the measurements: model and revision, quantization, hardware, context length, batch size, cache state, and runtime configuration. Without that context, two throughput figures may not be comparable.

The key idea is simple:

Prefill determines how quickly the model gets through your prompt. Decode determines how quickly it writes its answer.

They are connected, but they are not the same workload. Understanding that difference makes performance reports more meaningful—and helps explain why an AI can appear ready to answer quickly yet still take time to finish speaking.


Evidence and terminology notes

  • Prefill and decode are used here in their conventional LLM inference sense: prompt evaluation followed by autoregressive output generation.
  • The Gemma example is one supplied per-request record. It is illustrative, not a model-wide performance claim.
  • The Qwen qualification figures are supplied aggregate summaries. They do not establish per-request prefill or decode throughput.
  • The Qwen telemetry unit-test values are constructed fixture data. They establish expected extraction behaviour only, not a real benchmark result.
  • The calculations derived from the fixture are labelled as calculations and should not be presented as independently measured performance.
  • No hardware attribution from the separate eu-north-1 runtime log has been applied to the us-east-1 Qwen qualification campaign.