Back
advanced

Transformer internals

What are model scaling laws?

Use scaling laws as measured planning tools and distinguish training-optimal choices from the cost of serving a model.

Lesson 4 of 67About 30 min with practice

A fixed training budget buys either more parameters or more training tokens. Which trade should you make? The budget arithmetic can identify possible runs, but only evidence about learning can rank them.

Before you begin: You understand parameters, training tokens, validation loss, and scientific notation.

Scaling laws are empirical relationships between resources and measured outcomes. Researchers fit them to experiments, then use them to estimate promising configurations. They are useful because large training runs are expensive. They are limited because a fitted relationship is not a law of nature.

Model size, training tokens, and compute

Let N be the number of model parameters, D the number of training tokens processed, and C the training computation. For a rough estimate of a conventional dense transformer, people often use C ≈ 6ND floating-point operations.

The factor six is an approximation to forward and backward computation. Attention at long context, embedding details, architecture, recomputation, and other operations can change the estimate. It is not a hardware invoice. Actual time depends on utilization and communication, and actual cost depends on the hardware contract.

python
# Runnable: Python 3, standard library.
budget = 6e20
for parameters in [1e9, 2e9, 5e9]:
    tokens = budget / (6 * parameters)
    print(f'{parameters / 1e9:.0f}B parameters: '
          f'{tokens / 1e9:.0f}B tokens')

The output is approximately 100, 50, and 20 billion tokens. All three choices use the same simplified budget. Nothing in this calculation tells you their validation losses yet.

The tradeoff between model size and data

A fixed compute budget creates a tradeoff between model size and training exposure. The simple calculation below makes that constraint visible before discussing any fitted scaling law. If the model doubles while compute stays fixed, the available token budget falls under this approximation.

A scaling law then adds an empirical prediction about loss within a measured regime. It does not remove the budget constraint or guarantee downstream usefulness. The challenge asks you to separate the arithmetic of an allocation from the evidence needed to choose a good allocation.

Example

A dense training budget is approximated by C = 6ND.

What changes

Double parameter count N while holding compute C fixed.

Result

The token budget D halves under the approximation.

This is a resource relationship, not a universal optimum or a prediction of answer quality.

Include the training token count

The calculation above produces three feasible configurations. Make a table with parameters, tokens, and held-out loss. Leave the loss column blank until it is measured or estimated by a disclosed fitted model. This empty column is the central uncertainty, not a gap to fill with an attractive number.

Suppose the middle configuration has the lowest measured loss on your pilot runs. Is it enough to declare the same ratio optimal at a hundred times the budget?

Locate the extrapolation

No. You have evidence for one tested region. Larger scale can change the useful training horizon, data repetition, optimization behavior, and system efficiency. Fit on controlled runs, inspect uncertainty, and reserve an additional configuration to test the prediction. A smooth curve does not remove the need for that check.

Keep training-optimal and serving-optimal decisions in separate columns as well. They can favor different configurations without either calculation being inconsistent.

How to read a scaling relationship

A useful conceptual form is an irreducible loss term plus a model-size term and a data-size term. Each reducible term shrinks with a fitted power of its resource. The coefficients and exponents depend on the experimental setup. Copying constants from a paper into a different tokenizer, dataset, or training recipe can produce precise-looking nonsense.

The 2020 scaling-law study helped establish predictable trends in language-model loss. The 2022 Chinchilla study revisited compute allocation and found that, in its setting, scaling model size and training data together made better use of computation than some earlier large-model recipes.

“About twenty training tokens per parameter” is a historical rule of thumb associated with that work. It is not a required ratio for every model or a stopping rule for production training.

Training cost and inference cost

Suppose a model will serve millions of requests. Training a smaller model on more data can cost extra up front but reduce repeated inference expense. That choice may be sensible even when it is not optimal for minimizing loss at a fixed training compute budget.

The data itself also matters. Repeating the same tokens is not equivalent to collecting equally useful new examples. Leakage into evaluation data can make scaling appear more successful than it is. Lower average next-token loss does not guarantee better factual answers, safer tool actions, or better performance in an underrepresented language.

Plan a training budget

Run smaller controlled experiments using the intended data mixture and tokenizer. Reserve evaluation data before tuning. Fit the relationship, inspect residual errors, and test a configuration outside the fitting set before relying on a larger extrapolation. Report uncertainty and assumptions alongside the proposed budget.

Exercise: two models have equal validation loss, but one is half the size. Which should you ship?

Compare your reasoning

Measure task quality, latency, memory, throughput, and operational requirements. The smaller model is a promising serving candidate, but an aggregate loss tie does not establish equal behavior on your users' tasks.

Practice with feedback

Try the idea

Spend a fixed compute budget twice

Use the rough dense-training relation C = 6ND in consistent relative units. N is model size; D is training-token budget. Here D = C / (6N).

Bar length shows magnitude; the printed sign shows direction. The scale adjusts to the largest magnitude in this view.

Compute stays 300; model size changes from 5 to 10.

At fixed C, doubling N halves D. The figure exposes a budget constraint, not an optimal allocation. A fitted loss model, data quality and operational goals would be needed to compare the resulting trained models.

What this experiment assumes. A teaching approximation for dense-model training. It excludes architecture-specific work and does not predict downstream accuracy or recommend a universal token-to-parameter ratio. Notes and recorded results here last until you leave this page.

Lesson challenge

Allocate a fixed training budget

You have a fixed compute budget C. A colleague proposes spending it all on the largest model that fits, trained on whatever data is left.

Keep parameters, data, and compute separate and make a defensible plan.

Check your understanding

Question 1 of 3
For a transformer, what is the standard approximation relating compute, parameters, and tokens?
Score: 0/0

Your task

Convert a budget into allocations and add the column the naive plan is missing.

These notes stay on this page. Download them before leaving. Code in this field is not executed.

What to include

  • The parameters-tokens tradeoff is computed from the budget, not assumed
  • Tokens-per-parameter ratios are shown
  • Inference cost over the deployment lifetime is included
  • The recommendation names the assumption that drives it
Compare with a worked answer

Here is one way to answer. Check how it uses the information in the task.

C = 1e21          # training FLOPs
SERVE_TOKENS = 5e12   # expected tokens served over the model's life

print(f"{'N':>10} {'D tokens':>12} {'D/N':>7} {'serve FLOPs':>12} {'total':>12}")
for N in (3e8, 1e9, 3e9, 7e9, 2e10):
    D = C / (6 * N)
    serve = 2 * N * SERVE_TOKENS       # ~2 FLOPs per parameter per token
    print(f'{N:10.0e} {D:12.2e} {D/N:7.0f} {serve:12.2e} {C+serve:12.2e}')

#          N     D tokens     D/N  serve FLOPs        total
#      3e+08     5.56e+11    1852     3.00e+21     4.00e+21
#      1e+09     1.67e+11     167     1.00e+22     1.10e+22
#      3e+09     5.56e+10      19     3.00e+22     3.10e+22
#      7e+09     2.38e+10       3     7.00e+22     7.10e+22
#      2e+10     8.33e+09       0     2.00e+23     2.00e+23
#
# Two readings. On training loss alone, compute-optimal for this budget sits
# near D/N around 20, so about 3e9 parameters on 5.6e10 tokens. But at 5e12
# served tokens, inference dominates training by an order of magnitude, and
# the 3e8 model's total is eight times cheaper than the 3e9 model's.
#
# Recommendation: train around 1e9 parameters and spend the remaining budget
# on more tokens rather than more parameters, accepting slightly higher
# training loss for much lower lifetime cost.
# What would change it: if served volume were 5e10 tokens rather than 5e12,
# inference stops dominating and the compute-optimal 3e9 model wins. The
# serving estimate is the assumption doing the real work here, so it is the
# number I would verify first.

When you are signed in, opening the challenge carries your edited working notes into its draft in this browser. The challenge has its own completion record. Practising here does not award points or mark it complete.

Next, read the original scaling paper as evidence: what was measured, what was inferred, and what later work changed.

Sources

Compare Scaling Laws for Neural Language Models with Training Compute-Optimal Large Language Models. Their empirical findings inform this lesson; the budget calculation is an illustrative estimate, not a reproduction of either paper.

Practise this lesson

Allocate a fixed training budget

Keep parameters, data, and compute separate and make a defensible plan.

About 12 min70 points3 checks and one applied task
Loading your lesson progress...