AI Wiki中文/EN

Compute-optimal training: spend the budget on size or tokens?

计算最优训练

Derive a constrained model/data allocation, then test memory caps, data caps and a separate inference budget.

On this pageIntuitionMathematics & methodImplementationLimitationsExercisesResearch connections

A larger model can be the wrong purchase

Suppose your training budget is fixed. You can train a small model on many tokens, or a larger model on fewer. The larger model has more room to represent patterns, but less training to learn them. The best choice cannot be read from parameter count alone.

In this chapter’s authored numerical example, a budget of 60,000 cost units gives an optimum near 44.44 model-size units and 225 data units. Restrict model size to 20 and the best allocation changes to 20 and 500. Restrict training data to 100 units instead, and it changes to 100 and 100. These are continuous teaching quantities, not a recommendation to train a particular real model.

Scaling laws explains how a loss surface is fitted. Here we take a specified surface as an assumption and optimize resource allocation on it. Hoffmann and colleagues use this distinction when comparing training-curve envelopes, fixed-compute experiments and a parametric allocation rule. A mathematically correct optimum is useful only if the assumed loss and cost models describe the intended runs.

A fixed-budget loss valley changes when size caps or inference costs are included.
A fixed-budget loss valley changes when size caps or inference costs are included.

Balance the marginal value of model size and data

Let NN count model parameters, DD count training tokens processed, and C0C_0 be a training compute budget. For the dense-transformer approximation C≈6NDC\approx6ND, the allocation problem is

min⁡N,D L(N,D)subject to6ND≤C0, N>0, D>0.\min_{N,D}\ L(N,D)\quad\text{subject to}\quad6ND\le C_0,\ N>0,\ D>0.

The factor 6 summarizes an approximate forward-plus-backward cost under a particular counting convention. Kaplan’s analysis, Table 1 and the following discussion, neglects context-dependent terms when they are relatively small and uses non-embedding parameter counts. It is not a universal FLOP formula for every architecture, sequence length or training implementation. Measured wall-clock time also depends on hardware utilization and communication.

Assume a fitted surface with positive coefficients and exponents:

L(N,D)=E+AN−α+BD−β,A,B,α,β>0.L(N,D)=E+AN^{-\alpha}+BD^{-\beta},\qquad A,B,\alpha,\beta>0.

EE is a floor, while the other terms describe residual losses associated with finite model size and finite training amount. This is an empirical modeling assumption, not a decomposition you can infer for every model without measurements. Since increasing either resource lowers this surface, an unconstrained optimum uses the budget. Write S=C0/6S=C_0/6, substitute D=S/ND=S/N, and obtain

L(N,S/N)=E+AN−α+BS−βNβ.L(N,S/N)=E+AN^{-\alpha}+B S^{-\beta}N^{\beta}.

As NN grows, the first residual falls and the second rises. Differentiating with respect to log⁡N\log N makes the balance especially clear:

∂L∂log⁡N=−αAN−α+βBS−βNβ=0.\frac{\partial L}{\partial\log N}=-\alpha AN^{-\alpha}+\beta B S^{-\beta}N^{\beta}=0.

Thus the weighted residual terms, not necessarily the unweighted terms, are equal at the interior optimum. Solving for the sizes gives

N∗=(αAβB) ⁣1/(α+β)Sβ/(α+β),D∗=SN∗.N^*=\left(\frac{\alpha A}{\beta B}\right)^{\!1/(\alpha+\beta)}S^{\beta/(\alpha+\beta)},\qquad D^*=\frac{S}{N^*}.

The second derivative with respect to log⁡N\log N is positive: it is the sum of the two positive residual terms multiplied by squared exponents. The stationary point is therefore the unique unconstrained minimum of this specified surface. The budget exponents follow directly:

N∗∝C0β/(α+β),D∗∝C0α/(α+β).N^*\propto C_0^{\beta/(\alpha+\beta)},\qquad D^*\propto C_0^{\alpha/(\alpha+\beta)}.

Equal growth exponents arise when α=β\alpha=\beta; they are not built into every possible fitted surface. Hoffmann’s equation 4 gives this allocation form. The paper’s three estimation approaches give similar but nonidentical scaling exponents, so “grow both equally” is an approximate conclusion within the studied setup, not an exact law of all training.

Extra constraints can put the solution on a boundary. The program requires N,D≥1N,D\ge1 in its teaching units. With upper caps Nmax⁡,Dmax⁡N_{\max},D_{\max}, the full-budget interval is max⁡(1,S/Dmax⁡)≤N≤min⁡(Nmax⁡,S)\max(1,S/D_{\max})\le N\le\min(N_{\max},S). If the caps permit using the full budget, clip N∗N^* to this interval. If Nmax⁡Dmax⁡<SN_{\max}D_{\max}<S, both caps bind and some budget remains unused. Spending it cannot improve the declared objective without changing a constraint.

Training compute is also different from lifetime compute. For an illustrative inference demand of II generated-token units, add a simplified dense forward cost:

Clife=6ND+2NI,D=Clife−2NI6N.C_{\mathrm{life}}=6ND+2NI,\qquad D=\frac{C_{\mathrm{life}}-2NI}{6N}.

This extension is our teaching model, not a claim to reproduce a paper’s serving-cost optimizer. A larger NN now consumes more of the budget each time it is used. Cache memory, prompt processing, growing-context attention and hardware throughput are absent, so a deployment decision requires a richer cost model.

Check the analytic answer against a search

Run the complete standard-library program with Python 3.12. It defines E=1E=1, A=4A=4, B=9B=9, and both exponents as 0.5. The model/data coordinates are continuous, scaled teaching units; the program defines their cost as 6ND6ND. No language model is trained and no real hardware budget is measured.

"""Original continuous compute-allocation examples in declared teaching units."""
import json
import math

E, A, B, ALPHA, BETA = 1.0, 4.0, 9.0, .5, .5


def loss(n, d):
    if not math.isfinite(n) or not math.isfinite(d) or min(n, d) <= 0:
        raise ValueError("Positive finite model and data sizes required")
    return E + A / n ** ALPHA + B / d ** BETA


def training_optimum(budget, nmax=math.inf, dmax=math.inf):
    if not math.isfinite(budget) or budget < 6 or nmax < 1 or dmax < 1:
        raise ValueError("Need budget >= 6 and size caps >= 1")
    if math.isnan(nmax) or math.isnan(dmax):
        raise ValueError("Caps cannot be NaN")
    product = budget / 6
    if nmax * dmax <= product:
        n, d = nmax, dmax
    else:
        n0 = ((ALPHA*A)/(BETA*B)) ** (1/(ALPHA+BETA)) * product ** (BETA/(ALPHA+BETA))
        lower, upper = max(1., product/dmax), min(nmax, product)
        n = min(max(n0, lower), upper)
        d = product / n
    return dict(n=n, d=d, loss=loss(n,d), used=6*n*d, unspent=max(0.,budget-6*n*d))


def golden_minimum(fn, left, right, iterations=120):
    if left > right:
        raise ValueError("Reversed interval")
    ratio = (math.sqrt(5)-1)/2
    x, y = right-ratio*(right-left), left+ratio*(right-left)
    fx, fy = fn(x), fn(y)
    for _ in range(iterations):
        if fx < fy:
            right, y, fy = y, x, fx
            x = right-ratio*(right-left); fx = fn(x)
        else:
            left, x, fx = x, y, fy
            y = left+ratio*(right-left); fy = fn(y)
    return min([left,right,x,y], key=fn)


def lifetime_optimum(budget, inference_tokens):
    if not math.isfinite(inference_tokens) or inference_tokens < 0:
        raise ValueError("Inference demand must be finite and nonnegative")
    if not math.isfinite(budget) or budget < 6 + 2*inference_tokens:
        raise ValueError("Cannot afford N >= 1 and D >= 1")
    upper = budget / (6 + 2*inference_tokens)
    def data(n): return (budget - 2*n*inference_tokens)/(6*n)
    log_n = golden_minimum(lambda z:loss(math.exp(z),data(math.exp(z))),0.,math.log(upper))
    n = math.exp(log_n);d=data(n)
    return dict(n=n,d=d,loss=loss(n,d),training=6*n*d,inference=2*n*inference_tokens)


def demo():
    budget=60000.
    sizes=[10.,20.,40.,80.,160.]
    return dict(units='N and D are continuous teaching units; cost is defined as 6ND.',
                budget=budget,curve=[dict(n=n,d=budget/(6*n),loss=loss(n,budget/(6*n))) for n in sizes],
                unconstrained=training_optimum(budget),memory_cap=training_optimum(budget,nmax=20),
                data_cap=training_optimum(budget,dmax=100),both_caps=training_optimum(budget,20,100),
                fourfold_budget=training_optimum(4*budget),
                lifetime={str(i):lifetime_optimum(budget,i) for i in [0,100,500]})


if __name__=='__main__':
    print(json.dumps(demo(),indent=2))

At budget 60,000, the analytic optimum is N=400/9N=400/9, D=225D=225, and loss 2.2. The two residual terms are each 0.6 because the exponents are equal. A fourfold budget doubles both sizes and gives loss about 1.848528; the excess over the floor falls by 1/21/\sqrt2, not by one half.

The model cap of 20 yields loss about 2.296919. The training-token cap of 100 yields loss 2.3. Applying both caps yields loss about 2.794427, uses only 12,000 units and leaves 48,000 unspent. A tiny floating-point remainder at an uncapped optimum is roundoff, not a meaningful unused training allowance.

The lifetime calculation minimizes over log⁡N\log N with a bounded golden-section search. At inference demand 500 and total budget 60,000, it chooses about 22.212919 model units and 283.521811 training units, with loss 2.383208. Training uses about 37,787.081411 cost units and inference 22,212.918589. The smaller model allows more training tokens, but its final loss is higher than the training-only optimum because part of the total budget must serve inference.

The closed form requires constant arithmetic work. The bounded search uses 120 scalar iterations and constant storage; it is not a search over trained neural networks. Tests independently inspect dense grids, finite-difference derivatives, cost conservation, caps and the equal-exponent hand calculation.

A token cap is not automatically a unique-data cap

DD counts tokens processed. If a corpus has 100 units of unique text and you may repeat it, that fact alone does not impose D≤100D\le100. The example’s data cap is an explicit restriction on processed tokens—for instance, a single-pass policy. Repeated exposure can change the loss surface and overfitting behavior; do not keep the same data term without checking it.

Similarly, a parameter cap is only a simplified stand-in for memory constraints. Training memory includes optimizer states, activations and other buffers, not just weights. Discrete model shapes, batch sizes and accelerator counts can leave the continuous optimum unavailable. Enumerate feasible configurations near the predicted optimum and measure them.

The fitted coefficients depend on data, tokenizer, optimization schedule and evaluation. Kaplan and Hoffmann study different protocols; their numbers should not be mixed into a single surface without justification. Hold out some scales when fitting, test the predicted allocation at more than one budget, and include the cost of those pilot runs in an operational plan.

Change a constraint, then predict the direction

  1. For the teaching surface and budget 60,000, why is N=400/9,D=225N=400/9,D=225 stationary?

Answer: Their product is 10,000, satisfying 6ND=60,0006ND=60,000. The residuals are 4/400/9=0.64/\sqrt{400/9}=0.6 and 9/225=0.69/\sqrt{225}=0.6. Equal exponents make their log-size derivatives cancel, and positive curvature establishes a minimum.

  1. With both caps N≤20,D≤100N\le20,D\le100, should the program force all 60,000 units to be spent?

Answer: No. The largest feasible product is 2,000, costing 12,000. Both resources already reach their permitted maxima. Spending the remaining 48,000 would require a different task or relaxed constraint; it cannot be represented by the declared feasible set.

  1. If the training budget grows fourfold and both exponents equal 0.5, do the optimal sizes grow fourfold?

Answer: Each grows twofold, because each budget exponent is one half. Their product grows fourfold. Each residual term falls by 1/21/\sqrt2, while the fixed floor remains.

  1. Can a training-only optimum be advertised as the cheapest model for a heavily used service?

Answer: Not without a serving model. Repeated inference, prompt lengths, memory and hardware constraints change the objective. The illustrative 2NI2NI term already shifts the optimum toward a smaller model; real measurements are needed to quantify the deployment trade-off.

Optimization is conditional on the measured surface

Hoffmann et al., sections 3.3–3.4 and equation 4, support the parametric allocation derivation and comparison of estimation approaches. Kaplan et al., Table 1 and the surrounding training-cost discussion, provide the dense compute approximation and its counting conditions. The algebra and constrained toy examples here are independently checked; neither source’s large-model training is reproduced. Continue to data mixtures when the next question is which tokens the allocated training budget should buy.

Make a prediction, then check

At fixed training budget, why can a larger model have higher loss?

Choose one answer

Learning objectives

  • Derive the optimal allocation under a stated dense-training cost model.
  • Check boundary optima when model or data size is capped.
  • Explain why counting inference demand changes the optimization problem.

Prerequisites & connections

Explore related knowledge →

References

  1. Training Compute-Optimal Large Language Models — arXiv v1
    Jordan Hoffmann; Sebastian Borgeaud; Arthur Mensch; Elena Buchatskaya; Trevor Cai; Eliza Rutherford; Diego de Las Casas; Lisa Anne Hendricks; Johannes Welbl; Aidan Clark; Tom Hennigan; Eric Noland; Katie Millican; George van den Driessche; Bogdan Damoc; Aurelia Guy; Simon Osindero; Karen Simonyan; Erich Elsen; Jack W. Rae; Oriol Vinyals; Laurent Sifre · 2022
  2. Scaling Laws for Neural Language Models — arXiv v1
    Jared Kaplan; Sam McCandlish; Tom Henighan; Tom B. Brown; Benjamin Chess; Rewon Child; Scott Gray; Alec Radford; Jeffrey Wu; Dario Amodei · 2020

Version1 · Editorial status: Recorded technical checks completed

View technical check record (AI)

Codex · 2026-09-20 · Single AI author reused Kaplan v1 Table1/compute conditions and read Hoffmann v1 PDF7/equation4/section3.4. Seven paired equations and four explained exercises. Original analytic allocation, log-size finite differences, dense-grid oracle, model/token caps and separate lifetime-cost search. Continuous teaching units; token caps do not automatically bound unique data. No hardware or large-model replication.

  • Single AI author reused Kaplan v1 Table1/compute conditions and read Hoffmann v1 PDF7/equation4/section3.4. Seven paired equations and four explained exercises. Original analytic allocation, log-size finite differences, dense-grid oracle, model/token caps and separate lifetime-cost search. Continuous teaching units; token caps do not automatically bound unique data. No hardware or large-model replication.
  • Four computed SVG variants per topic;9 numeric/geometry tests and18 responsive cases passed. Six final Chinese-mobile/English-desktop screenshots actually inspected. Full article acceptance recorded separately.

Source locations checked:

Related topics

No matches. Try a synonym or acronym.

0 results shown

Wrap the whole query in double quotes for a phrase match.