Sizing Is a Budget Allocation Problem
Loss falls as a power law in parameters, data, and compute, so the real question is never "how big should the model be?" in isolation. It is how you split a fixed FLOP budget among parameters and tokens, and how much inference cost your deployment can absorb once the model ships.
- Choose parameter count and token count jointly from a compute budget instead of copying a competitor's size
- Estimate GPU memory and serving cost before you commit to a training run
- Recognize when a mixture-of-experts architecture beats a dense model for your traffic
Model Sizing: Scaling Laws, Chinchilla, and Deployment
What You'll Learn
- 1Read a scaling-law curve and predict relative loss for competing configurations
- 2Apply the Chinchilla compute-optimal ratio and explain when deliberate over-training is rational
- 3Convert a parameter count into training and inference memory estimates
- 4Use a FLOP budget to search for the best parameter-token split in code
Most Teams Size Models Backwards
The typical decision process goes like this: a team reads that "7B is the sweet spot," picks 7B, trains for whatever token count the data budget allows, and only then discovers that serving the model requires two GPUs instead of one. That sequence inverts the causal order. The quantity you actually control is the deployment envelope: the p95 latency your product tolerates, the tokens per second a user-facing feature needs, the GPU-hours you can pay for, and the quality bar measured on your own evaluation set.
Work forward from that envelope. A support-ticket summarizer that must run on a single A10G (24 GB) in under two seconds per request cannot host a 13B dense model in fp16, because weights alone would occupy most of the card before you count the KV cache for concurrent requests. The same product might fit a 7B model at 8-bit precision with room for batching. Sizing forward turns model selection into an engineering calculation; sizing backward from trend names turns it into folklore.
There is a second trap: treating parameter count as the only lever. Two models with identical parameter counts can differ by an order of magnitude in training cost if one saw twenty tokens per parameter and the other saw two hundred. Deployment cost, training cost, and quality form a three-way trade-off, and scaling laws are the map that connects them.
The Power Law Behind Every Sizing Decision
Empirical research since 2020 has established that language-model loss improves as a smooth power law in three resources: model parameters N, training tokens D, and training compute C. The widely used functional form is:
L(N, D) = E + A / N^alpha + B / D^beta
Here E is the irreducible loss of the data distribution itself, A and B are fitted constants, and alpha and beta are exponents typically measured between roughly 0.05 and 0.35 depending on the study and the regime. Two properties of this equation drive every practical decision. First, the decreases are multiplicative in effect but diminishing in absolute terms: going from one million to ten million parameters helps far more than going from one hundred million to one billion. Second, the two terms are additive, which means a huge model starved of data sits on the data term, and a tiny model trained forever sits on the parameter term. Either way you waste compute.
Training FLOPs are well approximated by the simple relation C โ 6ND โ six multiply-accumulates per parameter per token. That formula is the constraint that couples your choices. If your budget is fixed at 1e23 FLOPs, every parameter you add forces tokens you must remove.
| Configuration | Parameters | Tokens | Ratio (D/N) | Relative train FLOPs | Serving note |
|---|---|---|---|---|---|
| Under-trained giant | 280B | 300B | ~1.1 | 5.0e23 | Very expensive per request |
| Chinchilla-style | 70B | 1.4T | 20 | 5.9e23 | Strong quality, heavy serving |
| Over-trained small | 7B | 1T | ~143 | 4.2e23 | Cheap per request |
| Under-trained small | 7B | 20B | ~3 | 8.4e22 | Fast but weak quality |
The table makes the trade concrete. At similar training cost, the 70B and 7B rows reach very different quality, but the 7B row is roughly ten times cheaper to serve โ and serving cost dominates total cost of ownership for any product with sustained traffic.
Chinchilla's Twenty-Token Rule โ and Why Labs Break It
DeepMind's 2022 Chinchilla work showed that many large models of the era were under-trained. Holding compute fixed, quality was maximized when parameters and tokens scaled together at roughly twenty training tokens per parameter. Chinchilla at 70B parameters trained on 1.4 trillion tokens outperformed the 280B Gopher model trained on only 300 billion, at a fraction of the inference cost. The result reset internal roadmaps across the industry.
Yet the frontier immediately pivoted to deliberately over-trained small models. Llama-class models took a 7B backbone to a trillion tokens โ a ratio above one hundred โ because inference economics reward small models disproportionately. If a model answers a million requests a day for three years, cutting serving cost by 4ร outweighs spending 2ร more on a one-time training run. Chinchilla optimality assumes training cost is what you minimize; production optimizes lifetime cost, which is training plus amortized serving.
Treat twenty tokens per parameter as the compute-optimal anchor point, then shift rightward along the token axis when you expect heavy, long-lived inference, and shift leftward when you are compute-bound on training and the model will be used briefly.
Searching for the Optimal Split in Code
The following calculator turns a FLOP budget into a recommended configuration by evaluating candidate parameter counts, deriving the token count each implies, and scoring them with a scaling-law proxy:
from dataclasses import dataclass
@dataclass
class SizingConfig:
params: int
tokens: int
flops: float
est_loss: float
class SizingCalculator:
def __init__(self, alpha=0.34, beta=0.28):
self.alpha = alpha
self.beta = beta
def training_flops(self, params: int, tokens: int) -> float:
return 6.0 * params * tokens
def estimate_loss(self, params: int, tokens: int) -> float:
return 1.0 / (params ** self.alpha) + 1.0 / (tokens ** self.beta)
def optimal_tokens(self, params: int) -> int:
return int(params * 20)
def best_config(self, budget_flops: float,
candidates=None) -> SizingConfig:
if candidates is None:
candidates = [10 ** e for e in range(8, 12)]
best = None
for n in candidates:
d = int(budget_flops / (6.0 * n))
if d <= 0:
continue
loss = self.estimate_loss(n, d)
if best is None or loss < best.est_loss:
best = SizingConfig(n, d, budget_flops, loss)
return best
if __name__ == "__main__":
calc = SizingCalculator()
cfg = calc.best_config(1e23)
print(f"params={cfg.params / 1e9:.1f}B tokens={cfg.tokens / 1e9:.1f}B "
f"loss={cfg.est_loss:.4f}")
Run it with a few candidate grids โ dense powers of ten, then finer sweeps around the winner โ and you get a defensible starting point before any hardware is rented. The absolute loss values are proxies, but the ranking between configurations is what guides the decision.
Converting Parameters Into Memory Before You Train
Parameter count only becomes concrete when you translate it into bytes. During inference, a dense model needs roughly two bytes per parameter in fp16, so a 7B model needs about 14 GB for weights alone. Autoregressive serving adds a KV cache that grows linearly with sequence length, batch size, layer count, and head dimension; a rough form is two times layers times heads times head dimension times sequence length times batch size times bytes per entry. Long-context chat workloads routinely let the cache rival or exceed the weights.
Training is heavier. Mixed-precision training with Adam keeps fp16 or bf16 compute copies plus fp32 master weights and two fp32 optimizer moments โ about sixteen bytes per parameter in practice, before gradients and activations. A 7B model therefore consumes over 100 GB of state, which is why even gradient checkpointing and gradient accumulation cannot rescue a single-GPU training plan at that scale.
BYTES = {"fp32": 4, "fp16": 2, "bf16": 2, "int8": 1, "int4": 0.5}
def inference_memory_gb(params: int, precision: str = "fp16",
layers: int = 32, heads: int = 32,
head_dim: int = 128, seq_len: int = 4096,
batch: int = 4) -> float:
weight_bytes = params * BYTES[precision]
kv_bytes = 2 * layers * heads * head_dim * seq_len * batch * BYTES[precision]
return (weight_bytes + kv_bytes) / 1024 ** 3
def training_memory_gb(params: int) -> float:
return params * 16 / 1024 ** 3
print(round(inference_memory_gb(7_000_000_000), 1)) # weights + KV cache
print(round(training_memory_gb(7_000_000_000), 1)) # Adam mixed precision
These estimates are deliberately conservative. Quantization, paged attention, and multi-GPU weight sharding each change the numbers, but the order of magnitude you compute here is what decides whether a deployment plan is feasible before you discover otherwise in production.
Mixture-of-Experts: More Parameters Without More FLOPs
Mixture-of-experts architectures break the tight coupling between capacity and per-token compute. An MoE layer contains many expert sub-networks, but each token is routed to only the top one or two. Total parameter count โ and therefore memory and training-data capacity โ scales with the number of experts, while active FLOPs per token stay roughly constant. A model can carry 400B+ parameters of knowledge while activating a fraction of them per forward pass.
The costs are real. Memory still scales with total parameters, so serving hardware must hold every expert. Training requires load-balancing losses so routers do not collapse onto a few favorites, and multi-GPU layouts pay all-to-all communication for routed tokens. MoE is the right lever when you need knowledge capacity more than dense reasoning depth โ and when your serving stack can absorb the memory bill.
Common Mistakes
Picking a model size because a blog post called it the sweet spot
Fix: Derive size from your latency, memory, and FLOP budget, then validate on your own eval set
Optimizing training cost while ignoring serving cost
Fix: Multiply per-request cost by expected lifetime traffic; serving usually dominates
Counting weights but forgetting the KV cache
Fix: Size GPUs for weights plus KV cache at your real concurrency and context length
Treating Chinchilla's 20 tokens per parameter as a hard law
Fix: Use it as an anchor, then over-train small models when inference volume is high
Best Practices
- Write the deployment envelope first โ latency, throughput, GPU budget โ and let it constrain N and D
- Estimate training FLOPs with 6ND and memory with a sixteen-bytes-per-parameter rule before committing budget
- Benchmark a mid-size candidate on your own evaluation data before scaling the recipe up
- Re-run the sizing calculation whenever quantization or MoE routing changes your serving stack
Interview Questions
Q1: What does Chinchilla optimality mean, and when would you violate it?
Chinchilla found that for a fixed training compute budget, quality is maximized when parameters and tokens scale together at about twenty tokens per parameter. You would violate it when inference cost dominates lifetime cost: over-training a smaller model on more tokens gives similar quality at much lower serving cost, which is the strategy behind the Llama family.
Q2: How do you estimate whether a 13B model fits on one A10G for inference?
Multiply parameters by bytes per element for the target precision to get weight memory, then add the KV cache for the expected batch size and sequence length. 13B in fp16 is about 26 GB of weights alone, which already exceeds a 24 GB card, so you would need 8-bit quantization or weight sharding to fit.
Q3: Why does mixture-of-experts reduce cost per token despite having more parameters?
Only the top-r experts process each token, so active parameters and FLOPs per token stay nearly constant while total stored knowledge grows with expert count. Memory and communication costs still scale, which is the main deployment trade-off.
Key Takeaways
- Loss improves as a power law in parameters, data, and compute โ sizing is a three-way budget split
- Training FLOPs are approximately 6 times parameters times tokens
- Chinchilla suggests about twenty tokens per parameter for compute-optimal training; production systems often over-train smaller models to cut serving cost
- Memory estimates โ roughly two bytes per parameter for fp16 inference and sixteen for mixed-precision Adam training โ feasibility-check a plan before hardware is rented
- Mixture-of-experts adds capacity without proportional FLOPs but still costs memory and communication