Concepts / How Foundation Models Generate Output

How Foundation Models Generate Output

Autoregressive models generate tokens sequentially, so output time accumulates with the number of tokens.

  • Programming

Why Chatbot Answers Arrive in Pieces

Think about the last time you waited for a chatbot to finish an answer. The first words may have appeared quickly, and then the rest trickled in while you watched. That pacing is not a cosmetic choice. It reflects how many modern foundation models produce their output, and it is the starting point for one of the central difficulties in deploying them.

The question this article answers is simple to state: if a model generates its output in pieces, what does that do to the time a user spends waiting, and what can engineers do about it? To answer it, we first need to look closely at the mechanism that produces the output.

Generating One Token at a Time

The word sequentially is the key to this whole topic. Generation is not a single operation that returns a whole answer at once. The model produces one token, then another, and the sequence of those steps is what determines how long the full output takes. Many foundation models work this way, and the source identifies this step-by-step production as one of the challenges with them.

Models of this kind are called autoregressive. Each new token is produced by its own step, and each step is part of a loop. The diagram below shows the shape of that loop. It is a picture of the process rather than of any particular model's internals, so the boxes describe what happens in general, not how one specific system is built.

Tokens so farGenerate next tokenone step per tokenAppend token tooutputOutput finished?Full outputfeeds intoemit one tokencheckno, repeatyes
How does each new token depend on the tokens generated before it, and what does that loop look like step by step?

Read the loop from top to bottom. The model looks at what it has produced so far, generates the next token, adds that token to the output, and checks whether the output is finished. If it is not finished, the loop runs again. Each pass through the loop is one step, and the total number of steps is the number of tokens in the answer. This is why the cost of one step matters so much: it is multiplied by every token the model emits.

Estimating Total Generation Time

The source gives a simple way to reason about the cost of generation. Suppose a model takes a fixed amount of time to generate one token. Because the tokens are produced one after another, the total time grows with the number of tokens. The source's own example is a model that takes 10 ms per token: a 100-token output takes about one second, and longer outputs take even longer.

The source expresses this as an approximation. Let T be the total generation time, n the number of tokens, and t the time needed to generate one token. Then:

Formula

The approximation ignores overhead that falls outside the per-token work, so it is an estimate rather than an exact prediction. It still captures the central point. When each token costs a fixed amount of time, the total wait is proportional to the output length. Doubling the number of tokens roughly doubles the wait.

Token 1: 10 msToken 2: 20 msToken 50: 500 msToken 100: about 1 snext tokenmore tokensmore tokens
If each token takes a fixed time, how does total output time build up as the number of tokens grows?

The timeline shows the build-up. Each token adds the same 10 ms to the running total, so the elapsed time climbs steadily rather than jumping at once. By the hundredth token, the running total has reached about one second.

Working Out a Wait Time

Worked example

How long does a 250-token answer take?

A model takes 10 ms to generate one token. Estimate the total generation time for an answer of 250 tokens, using the approximation T is approximately n times t.

  1. 1
    Identify the values

    The per-token time is t = 10 ms and the number of tokens is n = 250.

  2. 2
    Apply the approximation

    Substitute into T is approximately n times t, giving T is approximately 250 times 10 ms.

  3. 3
    Compute the product

    250 times 10 ms is 2500 ms.

  4. 4
    Convert to seconds

    Since 1000 ms equals 1 second, 2500 ms is about 2.5 seconds.

Result

The answer takes about 2.5 seconds to generate. Compared with the 100-token case of about one second, the 2.5-times-longer output takes about 2.5 times as long.

Notice what the worked example does not need. It does not need to know anything about the internal design of the model. Once the per-token time is known, the estimate follows directly from the number of tokens. That is what makes the approximation useful for planning: an engineer can estimate how a change in output length will change the wait.

Latency as an Application Problem

Latency is the delay in generating output. The source notes that users are notoriously impatient, and it sets a benchmark: about 100 ms of latency is expected for a typical internet application. Getting AI applications down to that level is described as a huge challenge.

The diagram below traces the request path from the user's side. The user waits at the point where the model is producing tokens, and the application passes those tokens along as they are generated.

UserApplicationFoundation model1. send prompt2. forward prompt3. tokens one at a time4. text appears gradually
Where does the user wait in the request path between sending a prompt and receiving the full response?

Read the sequence in order. The user sends a prompt, the application forwards it, and the model returns tokens one at a time. The wait the user feels is shaped by the model's per-token steps: the longer the output, the longer the model keeps producing tokens. This is why the trickling pace you noticed in a chatbot is connected to the time the model needs to finish.

Inference Optimization as the Response

Inference refers to the work of running a trained model to produce output. Inference optimization is the discipline of making that work faster and cheaper. The source frames it as always important in machine learning engineering, because users never say no to faster models and companies always benefit from cheaper inference.

As foundation models push inference cost and latency higher, inference optimization has become even more important, and it is now an active subfield in both industry and academia. The two ideas connect directly. Autoregressive generation is one of the reasons latency is hard to reduce, and inference optimization is the work devoted to reducing it. The challenge described in this article is the problem that motivates that work.

The source does not describe specific optimization techniques, so this article does not claim how any particular method works. What you can take away is the logic of the link: since total time accumulates with the number of tokens and the per-token cost, any progress on making generation faster or cheaper is directly relevant to the wait a user experiences.

Mistakes When Reasoning About Generation Time

  • Common mistake

    Assuming a longer answer takes only slightly longer

    What it looks like

    Believing that a 200-token answer takes barely more time than a 100-token answer.

    Why it fails

    Each token adds its own step, and with a fixed per-token time the total grows in proportion to the number of tokens.

    Do this instead

    Use T is approximately n times t. At 10 ms per token, 100 tokens take about 1 second and 200 tokens take about 2 seconds.

  • Common mistake

    Treating the 100 ms benchmark as the time to generate a whole answer

    What it looks like

    Thinking that because 100 ms is the latency expected for a typical internet application, a full chatbot reply should finish within 100 ms.

    Why it fails

    The source uses 100 ms as the expected latency benchmark for typical internet applications, and it describes reaching that level as a huge challenge for AI applications. It is not a claim about how long a full generated answer takes.

    Do this instead

    Compare the 100 ms benchmark against the total time a multi-token answer needs, which the per-token estimate helps you calculate.

  • Common mistake

    Thinking the approximation is an exact prediction

    Why it fails

    The source states the approximation ignores overhead outside the per-token work.

    Do this instead

    Treat T is approximately n times t as an estimate for planning, not a precise measurement.

Predicting the Wait for Your Own Output

EASY

A model takes 10 ms to generate one token. Before calculating, predict roughly how long a 500-token answer will take. Then use T is approximately n times t to find the exact estimate. Finally, explain in one sentence why the wait is not affected by how the tokens are spread across different parts of the answer.

Hints
  • Identify n and t first.
  • Multiply the number of tokens by the time per token, then convert milliseconds to seconds.
  • Think about whether the approximation treats each token's step as the same cost.

What do you think happens?

What total time does a 500-token answer take at 10 ms per token?

Reveal answer
Answer:

About 5 seconds, since 500 times 10 ms is 5000 ms.

Doubling the 250-token answer from the worked example gives a 5-second estimate, matching the proportional growth described by the approximation.

Key Takeaways

  • Autoregressive models generate tokens sequentially, one step per token, so total output time accumulates with the number of tokens.
  • With a fixed per-token time t, the approximation T is approximately n times t estimates total generation time; at 10 ms per token, a 100-token output takes about one second.
  • Latency, the delay in generating output, is a serious challenge for AI applications, since users are impatient and about 100 ms is expected for a typical internet application.
  • Foundation models raise inference cost and latency, and inference optimization, the work of making models faster and cheaper, is the field devoted to addressing these challenges.

Related concepts

More concepts starting with H