Foundation Models: Training Data, Scaling, Post-Training and Sampling

How foundation models are made and why they behave as they do: training data and its biases, model size, parameters, tokens and FLOPs, scaling laws and compute-optimal training, supervised fine-tuning, preference fine-tuning (RLHF, DPO), sampling strategies, test-time compute, structured outputs, and the probabilistic roots of inconsistency and hallucination.

On this page

Simple definition#

A foundation model is the product of three choices: what data it learned from, how big it is and how long it was trained, and how it was post-trained to behave like an assistant. A fourth choice — how you sample from it — is yours, at inference time.

Each choice leaves fingerprints that architects must design around: language gaps, knowledge cutoffs, cost, sycophancy, inconsistency and hallucination.

From raw data to the answer your user sees
flowchart LR
    D["Training data<br/>web, code, books,<br/>domain corpora"] --> PT["Pre-training<br/>self-supervised<br/>next-token prediction"]
    PT --> SFT["Supervised fine-tuning<br/>demonstrations of<br/>good responses"]
    SFT --> PF["Preference fine-tuning<br/>RLHF / DPO /<br/>RL on verifiable tasks"]
    PF --> M["Released model"]
    M --> S["Sampling<br/>temperature, top-p,<br/>test-time compute,<br/>structured output"]
    S --> O["Output"]

Training data: the model is what it ate#

A model can only be good at what is well represented in its training data.

Data property Consequence you will see
Web-heavy (Common Crawl and similar) Strong on general English; inherits web biases, misinformation and low-quality text unless filtered
English-dominant Lower quality, higher cost and higher latency in under-represented languages — the same sentence can need several times more tokens
Little domain-specific data Weak on specialised fields (law, medicine, your internal jargon) whose data is not public
Fixed snapshot A knowledge cutoff; nothing after it exists for the model
Unknown composition You often cannot prove what is in it — a governance and copyright question

Domain-specific models exist because general data does not cover some domains — biomedicine, finance, code, chemistry. Today a strong general model plus retrieval often beats a smaller domain model, but evaluate both on your task.

Model size, compute and scaling#

Three numbers describe a model’s scale:

Number Meaning Rough intuition
Parameters Learnable weights Capacity to store patterns; drives memory and serving cost
Training tokens How much text it learned from How much it has seen
Training FLOPs Total compute spent Roughly 6 × parameters × tokens for a dense transformer

Sparse models complicate the picture. A mixture-of-experts (MoE) model has many parameters but activates only a few “experts” per token, so it can be large in knowledge but cheap per token. For serving, the active parameter count drives compute while the total drives memory.

Scaling laws and compute-optimal training#

Scaling laws describe how loss falls predictably as you add parameters, data and compute. The DeepMind Chinchilla study (2022) found that, for a fixed compute budget, a model should be trained on roughly 20 tokens per parameter to be compute-optimal — many earlier models were too big for the data they saw.

Production models deliberately break this rule: they are trained on far more tokens than “optimal” because a smaller model trained longer is cheaper to serve, and serving cost dominates over the model’s lifetime.

Scaling bottlenecks#

Two limits are visible on the horizon:

  • Data — high-quality public text is finite, and more of the web is now AI-generated, which risks training models on their own outputs.
  • Electricity and compute — data centre capacity grows more slowly than demand.

Both push the industry towards synthetic data, better data curation, and spending more compute at inference time instead of training time (see test-time compute).

Post-training: from text predictor to assistant#

A pre-trained model completes text; it does not follow instructions. Post-training turns it into an assistant in two broad steps.

Supervised fine-tuning (SFT)#

The model is trained on demonstration data: prompts paired with high-quality responses written or curated by people. It learns the format of helpful conversation — answer the question, follow the instruction, refuse harmful requests. Demonstration data is expensive because good responses take skilled people time.

Preference fine-tuning#

People find it easier to compare two responses than to write a perfect one. Preference fine-tuning exploits that.

Method How it works Notes
RLHF Train a reward model on human comparisons (“A is better than B”), then optimise the model with reinforcement learning to score highly Powerful, complex, can be unstable
DPO Optimise directly on preference pairs without a separate reward model Simpler and cheaper; widely used for open models
RL on verifiable rewards Reward the model when an answer can be checked (math, code that passes tests) The basis of modern reasoning models

Post-training explains several behaviours you will meet:

  • Sycophancy — models trained to please raters can agree too easily.
  • Over-refusal — safety tuning can make models refuse benign requests.
  • Verbosity — raters often prefer longer answers, so models learn to be long.

Sampling: how an output is chosen#

The model produces a probability for every possible next token; sampling picks one. (The mechanics are introduced in how LLMs work.)

Control Effect Typical use
Temperature Scales the distribution: low → focused and repeatable; high → diverse and creative 0–0.3 for extraction and classification; 0.7–1.0 for drafting
Top-k Sample only from the k most likely tokens Cuts off unlikely tokens
Top-p (nucleus) Sample from the smallest set whose probability sums to p Adapts the candidate set to the model’s confidence
Stopping conditions Max tokens, stop sequences Bounds cost and latency
Log probabilities The probability of each generated token Confidence signals, classification scores, evaluation

Test-time compute#

Instead of taking the first sample, spend more compute at inference to get a better answer:

  • Best-of-N — generate several candidates and pick the best with a scorer, verifier or AI judge.
  • Self-consistency / majority vote — generate several answers and take the most common one.
  • Reasoning (“thinking”) tokens — the model writes intermediate steps before answering; trained with RL to reason longer on harder problems.

Research shows that, for some tasks, spending more compute at inference can rival a much larger model — at the price of latency and tokens. Use it where accuracy is worth more than speed.

Structured outputs#

Production systems often need JSON, SQL or a fixed label set. Options, from weakest to strongest guarantee:

Approach Guarantee
Ask for the format in the prompt, with examples None; works most of the time
Post-process — parse, repair common errors, retry Practical; adds a retry loop
Constrained decoding — only allow tokens that fit a grammar or JSON Schema Valid syntax guaranteed (content can still be wrong)
Fine-tune on the format Higher reliability for a narrow, high-volume format

Most providers now offer schema-constrained output natively. See prompt engineering: structured output.

The probabilistic nature of AI#

Because outputs are sampled, two behaviours are built in:

Inconsistency. The same input can give different outputs, and slightly different inputs can give very different outputs. Mitigations: low temperature, fixed seeds where supported, caching identical requests, consistent prompts, and evaluation that measures variance — not one lucky run.

Hallucination. The model produces fluent, plausible content that is not grounded in fact. Two complementary explanations:

  • The model cannot distinguish what it knows from what it generates; once it writes a wrong token, it continues plausibly from there (self-delusion / snowballing).
  • Fine-tuning can teach a model to produce answers that go beyond its actual knowledge, so it learns to “sound like it knows”.

Mitigations are architectural: retrieval grounding, citations, asking the model to say “I don’t know”, factual-consistency checks and human review for high-stakes outputs.

Common mistakes#

Review questions#

What do scaling laws tell us, and why do production models break the Chinchilla ratio? Loss falls predictably with more parameters, data and compute; Chinchilla found about 20 training tokens per parameter is compute-optimal for training. Production models are trained on far more tokens so that a smaller model reaches the same quality — it is cheaper to serve over its lifetime.

What is the difference between SFT and preference fine-tuning? SFT trains on demonstrations of good responses; preference fine-tuning trains on comparisons between responses, through a reward model and RL (RLHF) or directly (DPO). SFT teaches the format; preferences refine quality and safety.

What is test-time compute? Spending more inference compute per request to improve the answer — best-of-N with a verifier, majority voting, or reasoning tokens — trading latency and cost for accuracy.

Why do models hallucinate, and how do you reduce it? They generate plausible tokens without a reliable sense of what they know, and errors snowball once generated. Reduce it by grounding in retrieved sources, requiring citations, allowing “I don’t know”, checking factual consistency and keeping humans on high-stakes outputs.

When would you use constrained decoding? When downstream code must parse the output — JSON, SQL, enumerations. It guarantees syntactic validity; you still validate the content.

Summary#

  • Training data sets the model’s strengths, gaps, biases and cutoff; language coverage affects quality and cost.
  • Scale (parameters, tokens, compute) drives capability and cost; serve the smallest model that is good enough.
  • Post-training (SFT, RLHF, DPO, RL on verifiable rewards) creates assistant behaviour — and sycophancy, verbosity and refusals.
  • Sampling, test-time compute and structured output are inference-time levers you control.
  • Inconsistency and hallucination are inherent; handle them in the architecture.

References#