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.
compute-optimal-trainingA 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.
Balance the marginal value of model size and data
Let count model parameters, count training tokens processed, and be a training compute budget. For the dense-transformer approximation , the allocation problem is
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:
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 , substitute , and obtain
As grows, the first residual falls and the second rises. Differentiating with respect to makes the balance especially clear:
Thus the weighted residual terms, not necessarily the unweighted terms, are equal at the interior optimum. Solving for the sizes gives
The second derivative with respect to 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:
Equal growth exponents arise when ; 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 in its teaching units. With upper caps , the full-budget interval is . If the caps permit using the full budget, clip to this interval. If , 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 generated-token units, add a simplified dense forward cost:
This extension is our teaching model, not a claim to reproduce a paper’s serving-cost optimizer. A larger 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 , , , and both exponents as 0.5. The model/data coordinates are continuous, scaled teaching units; the program defines their cost as . 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 , , 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 , 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 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
counts tokens processed. If a corpus has 100 units of unique text and you may repeat it, that fact alone does not impose . 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
- For the teaching surface and budget 60,000, why is stationary?
Answer: Their product is 10,000, satisfying . The residuals are and . Equal exponents make their log-size derivatives cancel, and positive curvature establishes a minimum.
- With both caps , 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.
- 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 , while the fixed floor remains.
- 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 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?
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
- 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 - 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:
- Training Compute-Optimal Large Language Models — arXiv v1 · Original Source object preserved; additionally viewed PDF7/equation4 and section3.4 this batch. Existing PDF6 fitted surface and Kaplan cost scope reused. New constrained/lifetime examples are original, not paper replication.
- Scaling Laws for Neural Language Models — arXiv v1 · Viewed PDF pages 3, 7 and 8: Figure 1, Table 1, sections 2.2–2.3 and 3.1–3.2. Empirical conditional curves, non-embedding counts and training setup; no LLM experiment reproduced.
Related topics