Skip to content
AgenticAIWiki
  1. Learn
  2. Part 1
  3. 9. Machine learning basics for LLM builders
  4. 9.4

Lesson 9.4 · 4 of 5 · 6 min read · Reviewed 24 Nov 2026

Training compute vs inference compute

By the end, you can

  • Estimate training and inference compute with the 6ND and 2N rules of thumb.
  • Explain why serving a popular model can outweigh the cost of training it.

Every model has two compute bills. Training is paid once (or once per fine-tuneFine-tuning: Continuing to train a model on your own examples to change its behaviour or specialise it.) to find the weights. Inference is paid every time someone uses the model. As a builder you almost always pay only the second, but knowing the shape of both explains a lot about pricing, model sizes and why fine-tuning is a project rather than a setting.

Two rules of thumb

For a dense transformerTransformer: The neural network architecture behind modern LLMs, built from stacked attention and feed-forward layers. with N parameters:

Phase Work per token Why
Training about 6N FLOPs Forward pass (2N) plus backward pass (about 4N)
Inference about 2N FLOPs Forward pass only: one multiply and one add per weight

So training a model on D tokensToken: The unit a model reads and writes: a word, part of a word, a space or a symbol, mapped to an integer id. costs about 6ND FLOPs. These are approximations from the scaling-law literature; they ignore attentionAttention: The mechanism that lets each token weigh every other token in the context when building its representation.’s extra cost on long contexts, but they are close enough to reason with.

A worked example

An illustrative model with 1 billion parameters, trained on 20 billion tokens (about 20 tokens per parameter, the “compute-optimal” ratio the Chinchilla paper found):

Training:  6 x 1e9 x 2e10 = 1.2e20 FLOPs
Inference: 2 x 1e9        = 2e9 FLOPs per token
Break-even: 1.2e20 / 2e9  = 6e10 tokens

Once the model has generated or read about 60 billion tokens, three times its training data, inference has used as much compute as training did. A popular service can pass that in weeks. This is one reason labs often train smaller models on far more tokens than the compute-optimal ratio: a smaller model costs more to train well, but it is cheaper on every one of the trillions of tokens it will serve.

Memory is different too

Training Inference
Holds Weights, gradients, optimiser state, saved activations Weights, plus the KV cache for each request (lesson 10.5)
Rough bytes per parameter 16 or more with Adam in mixed precision 2 at 16-bit, about 0.5 at 4-bit
Hardware Many accelerators working together for days or months One or a few accelerators, or a laptop for small models

An 8-billion-parameter model fits for inference in about 16 GB at 16-bit, and much less once quantisedQuantization: Storing model weights with fewer bits, such as 4 or 8 instead of 16, to cut memory and speed up inference. (chapter 30). Training the same model needs well over 100 GB before you count activations.

Inside inference: prefill and decode

Inference has two phases. PrefillPrefilling: Writing the first part of the assistant’s reply yourself so the model continues from there. reads your prompt: all its tokens go through the model in parallel, which keeps the hardware busy. Decode writes the answer one token at a time; each step reads every weight from memory to produce a single token, so it is limited by memory bandwidth more than raw compute. That is why output tokensOutput tokens: The tokens the model generates in its reply, including any tool calls and thinking. are slower and usually priced higher than input tokensInput tokens: The tokens you send in a request: system prompt, tool definitions, conversation history and attached content. (chapter 3).

What this means for you

  • Price per token tracks inference compute. Bigger models cost more per token because 2N is bigger.
  • Fine-tuning is training. Even parameter-efficient methods (chapter 29) need gradients and a training loop, so budget it as a project.
  • Long outputs cost more than long inputs of the same length, because decode is the slow phase.

Common mistakes

  • Comparing training FLOPs with a per-request bill. Compare like with like: total inference over the model’s life against one training run.
  • Assuming a model that trains on a cluster needs a cluster to run. Inference needs far less memory and compute per step.

Key points

  • Training a dense model costs roughly 6 x parameters x training tokens in floating-point operations (FLOPs): a forward and a backward pass for every token.
  • Inference costs roughly 2 x parameters FLOPs per token, because it runs only the forward pass.
  • Training is a large one-off bill; inference is a bill that grows with every user, so over a model's life it can be the bigger one.
  • Training also needs far more memory per parameter: gradients and optimiser state sit next to the weights.
Hands-on labRuns in the Playground

Estimate training versus serving compute

Use the 6ND and 2N rules of thumb to find when serving a model overtakes the cost of training it.

You will have: A table of training FLOPs, FLOPs per token and break-even days for three illustrative models.

Steps

  1. Fill in training_flops (6 x N x D) and inference_flops (2 x N x tokens).
  2. Run it and read the break-even column for each model.
  3. Check the claim that break-even is always 3 x the training tokens.
  4. Change the medium model's daily traffic and see how the break-even moves.
  5. Note the memory line: why does training need about 8 times the memory of 16-bit inference?

Done when

  • The medium model breaks even after 120 days.
  • Break-even prints as 3 x training tokens.
  • You can explain why N cancels out of the break-even in tokens.

Open in the Playground No API key needed.

Starter code (Python)
# Rules of thumb for a dense transformer with N parameters:
#   training  ~ 6 * N * D FLOPs (D = training tokens)
#   inference ~ 2 * N FLOPs per token
def training_flops(n_params, train_tokens):
    # TODO: forward plus backward pass for every training token: 6 * N * D
    return 1.0

def inference_flops(n_params, tokens):
    # TODO: forward pass only: 2 * N per token
    return 1.0

def break_even_days(n_params, train_tokens, tokens_per_day):
    return training_flops(n_params, train_tokens) / inference_flops(n_params, tokens_per_day)

# Illustrative models and traffic, not real products.
MODELS = [
    ("small", 1e9, 20e9, 5e9),
    ("medium", 8e9, 2e12, 50e9),
    ("large", 70e9, 15e12, 100e9),
]
print(f"{'model':8}{'train FLOPs':>14}{'FLOPs/token':>14}{'break-even':>14}")
for name, n, d, per_day in MODELS:
    days = break_even_days(n, d, per_day)
    print(f"{name:8}{training_flops(n, d):>14.1e}{inference_flops(n, 1):>14.1e}{days:>10.0f} days")

# The break-even point in tokens is always 3 x the training tokens, whatever N is.
n, d = 8e9, 2e12
tokens = training_flops(n, d) / inference_flops(n, 1)
print(f"Break-even tokens for medium: {tokens / d:.0f} x training tokens")

# Memory: training holds ~16 bytes per parameter (weights, gradients, Adam state); 16-bit inference holds 2.
print(f"Medium model memory: training ~{n * 16 / 1e9:.0f} GB, inference weights ~{n * 2 / 1e9:.0f} GB")
Show a solution
# Rules of thumb for a dense transformer with N parameters:
#   training  ~ 6 * N * D FLOPs (D = training tokens)
#   inference ~ 2 * N FLOPs per token
def training_flops(n_params, train_tokens):
    return 6 * n_params * train_tokens

def inference_flops(n_params, tokens):
    return 2 * n_params * tokens

def break_even_days(n_params, train_tokens, tokens_per_day):
    return training_flops(n_params, train_tokens) / inference_flops(n_params, tokens_per_day)

# Illustrative models and traffic, not real products.
MODELS = [
    ("small", 1e9, 20e9, 5e9),
    ("medium", 8e9, 2e12, 50e9),
    ("large", 70e9, 15e12, 100e9),
]
print(f"{'model':8}{'train FLOPs':>14}{'FLOPs/token':>14}{'break-even':>14}")
for name, n, d, per_day in MODELS:
    days = break_even_days(n, d, per_day)
    print(f"{name:8}{training_flops(n, d):>14.1e}{inference_flops(n, 1):>14.1e}{days:>10.0f} days")

# The break-even point in tokens is always 3 x the training tokens, whatever N is.
n, d = 8e9, 2e12
tokens = training_flops(n, d) / inference_flops(n, 1)
print(f"Break-even tokens for medium: {tokens / d:.0f} x training tokens")

# Memory: training holds ~16 bytes per parameter (weights, gradients, Adam state); 16-bit inference holds 2.
print(f"Medium model memory: training ~{n * 16 / 1e9:.0f} GB, inference weights ~{n * 2 / 1e9:.0f} GB")
Quick checkA team trains a model once and then serves it to millions of users for two years. Which statement about compute is most accurate?
How sure are you?
Pick an answer and how sure you are