Skip to content
AgenticAIWiki
  1. Learn
  2. Part 1
  3. 5. How models are trained
  4. 5.6

Lesson 5.6 · 6 of 7 · 6 min read · Reviewed 24 Nov 2026

Foundation models and pre-training at scale

By the end, you can

  • Explain what makes a pretrained model a foundation model.
  • Describe scaling laws and the trade between model size, data and compute in plain terms.
  • Choose an adaptation route for a new task: prompting, retrieval, fine-tuning or distillation.

Lesson 5.1 showed the objective: predict the next token. This lesson zooms out. Why does one model, trained once, end up powering chat, code, search and agentsAgent: A system where a model decides its own next steps, calling tools in a loop until the task is done.? And how do labs decide how big to make it and how much data to feed it?

What makes it a foundation model

The term foundation model describes a model trained on broad data at scale that many different tasks can then build on. Three things mark one out:

Trait What it means Counter-example
Broad data Web text, books, code, often images and audio A model trained only on your ticket labels
General objective Next-token prediction or similar, no single task in mind A spam filter trained to say yes or no
Adapted downstream Prompted, tuned or distilled into many products A model that only ever does the job it was trained for

The upside is reuse: one costly training run serves thousands of applications. The downside is that flaws are shared too. A bias or a gap in the base model shows up in everything built on it (5.7).

Scaling laws in plain terms

Researchers found that a model’s loss, its average surprise at the next tokenToken: The unit a model reads and writes: a word, part of a word, a space or a symbol, mapped to an integer id., falls smoothly as you add three things: parameters, training tokens and compute. Plot loss against any of them on log scales and you get something close to a straight line. That predictability lets a lab train small trial models, fit the curve, and forecast how a model 100 times larger will do before spending the budget.

Compute ties the other two together. A useful estimate is:

training compute (FLOPs) ~ 6 x parameters x training tokens

So for a fixed compute budget you choose where to spend it: a bigger model on less data, or a smaller model on more. Later work showed that many early large models were too big for their data. For the best loss per unit of compute, grow model size and data together. A common rule of thumb from that work is roughly 20 training tokens per parameter.

A worked example with illustrative numbers. Budget: 1e23 FLOPs.

Choice Parameters Tokens Tokens per parameter
Compute-optimal about 29B about 580B 20
Over-trained, smaller about 9B about 1.8T 200

The over-trained model scores slightly worse in training, but it is about three times cheaper to run for every token it ever serves. Many open families now train small models far past 20 tokens per parameter for exactly that reason (28.6).

Data mixture matters as much as volume

Labs don’t just pour in more text. They decide the mixture: how much web, code, maths, science, books and each language, and how hard to filter for quality and remove duplicates. More code tends to help reasoning and tool useTool use: Letting a model call functions you define, by returning a structured request your code executes.; more of one language improves that language. The mixture is one reason two models of the same size can differ sharply on your task.

Adaptation routes

You will almost never pretrain. You adapt a foundation model, cheapest route first:

  1. Prompting: instructions and examples in the context (Part 2).
  2. Retrieval: feed it your documents at query time (Part 4).
  3. Fine-tuningFine-tuning: Continuing to train a model on your own examples to change its behaviour or specialise it.: train on your examples to fix format or style (chapter 29).
  4. Distillation: have a large model teach a small one for a narrow, high-volume task (31.4).

Common mistakes

  • Reading scaling laws as “bigger is always better for me”. They predict training loss, not your evalEval: A repeatable test that measures how well an AI system performs on a set of cases with defined success criteria. score or your bill.
  • Ignoring inference cost. A model you serve millions of times should be judged on cost per request, not only on training efficiency.
  • Jumping to fine-tuning. Most tasks are solved by prompting and retrieval; measure first.

Key points

  • A foundation model is trained once on broad data at scale, then adapted to many tasks it was never built for.
  • Scaling laws say loss falls smoothly and predictably as you add parameters, data and compute together.
  • Compute is roughly 6 x parameters x training tokens. For a fixed budget, grow model size and data together; a common rule of thumb is about 20 tokens per parameter.
  • Most teams never pretrain. They adapt: prompt first, then retrieval, then fine-tuning or distillation when the eval says so.
Hands-on labRuns in the Playground

Split a compute budget between size and data

Use the rule compute ~ 6 x parameters x tokens to find the compute-optimal model size for a budget, and see what over-training a smaller model costs.

You will have: A script that sweeps tokens-per-parameter ratios for one budget, prints size, tokens and loss for each, and names the optimum and the trade-off of a 200:1 model.

Steps

  1. Run the starter: every row shows a 1.0B model, because split() ignores the budget.
  2. Fill in split(): with tokens = ratio x params and compute = 6 x params x tokens, solve for params.
  3. Find the row with the lowest loss and print its ratio and size.
  4. Compare the 200:1 row with the optimum: extra loss, and serving cost as the ratio of parameter counts.
  5. Change BUDGET to 1e21 and 1e24 and check whether the best ratio moves.

Done when

  • At 1e23 FLOPs the best ratio is 20 tokens per parameter, with about 28.9B parameters.
  • The 200:1 model loses only about 0.035 in loss but costs about a third as much per served token.
  • You can explain in one sentence why many small open models are trained far past 20:1.

Open in the Playground No API key needed.

Starter code (Python)
# Illustrative scaling-law curve, shaped like published fits (not real constants).
E, A, B, a = 1.7, 400.0, 400.0 * 20 ** 0.3, 0.3

def loss(params, tokens):
    return E + A / params ** a + B / tokens ** a

def split(budget, tokens_per_param):
    # TODO: compute ~ 6 x params x tokens, and tokens = ratio x params.
    # Solve for params, then return (params, tokens).
    params = 1e9
    return params, tokens_per_param * params

BUDGET = 1e23
rows = []
for r in [1, 2, 5, 10, 20, 40, 80, 160, 200]:
    n, d = split(BUDGET, r)
    rows.append((loss(n, d), r, n, d))
    print(f"ratio {r:>3}: {n/1e9:6.1f}B params, {d/1e9:7.0f}B tokens, loss {loss(n, d):.3f}")

# TODO: find the row with the lowest loss and print
#   "compute-optimal: <ratio> tokens per parameter, <params>B params"
# TODO: compare the 200:1 row with the best row: extra loss, and serving
#   cost as the ratio of their parameter counts.
Show a solution
# Illustrative scaling-law curve, shaped like published fits (not real constants).
E, A, B, a = 1.7, 400.0, 400.0 * 20 ** 0.3, 0.3

def loss(params, tokens):
    return E + A / params ** a + B / tokens ** a

def split(budget, tokens_per_param):
    # compute ~ 6 x params x tokens, and tokens = ratio x params
    params = (budget / (6 * tokens_per_param)) ** 0.5
    return params, tokens_per_param * params

BUDGET = 1e23
rows = []
for r in [1, 2, 5, 10, 20, 40, 80, 160, 200]:
    n, d = split(BUDGET, r)
    rows.append((loss(n, d), r, n, d))
    print(f"ratio {r:>3}: {n/1e9:6.1f}B params, {d/1e9:7.0f}B tokens, loss {loss(n, d):.3f}")

best = min(rows)
print(f"compute-optimal: {best[1]} tokens per parameter, {best[2]/1e9:.1f}B params")

small = [row for row in rows if row[1] == 200][0]
print(f"over-trained 200:1 model: loss +{small[0]-best[0]:.3f}, "
      f"serving cost {small[2]/best[2]:.2f}x of the optimal model")
Quick checkA team trained a model only on labelled support tickets to sort them into ten queues. A colleague calls it a foundation model. What is the best reason it isn't one?
How sure are you?
Pick an answer and how sure you are