Frontier Lab Engineer

One budget of 5.9 × 1023 FLOPs can train a 280B model on 350B tokens or a 70B model on 1.4T tokens. The smaller model reaches the lower loss. A frontier lab engineer makes that call with arithmetic, before the GPUs start.

Pick a plan and watch where it lands on the loss curve. Drag the MFU slider to see how many days it takes. Then we build each skill, piece by piece: compute, scaling laws, memory, parallelism, rooflines, reliability, experts, quantization and serving.

You need some Python and a rough idea of what a neural network is (weights, a loss, gradient steps). We build the rest from zero.

A Day in the Life guide to AI research infrastructure: the systems below the model. Loss values use the fitted law from Hoffmann et al., Training Compute-Optimal Large Language Models (2022). Hardware numbers are from NVIDIA's H100 page; run numbers are from the Llama 3 paper (2024).

Spend one budget three ways

40%

Compute C = 6ND = 5.88 × 1023 FLOPs for every plan (Chinchilla's 70B and 1.4T tokens). Loss is the paper's fit L = 1.69 + 406.4/N0.34 + 410.7/D0.28, in nats per token on its own data. Days assume 2,048 H100s at 989.5 dense BF16 TFLOPS each. The 32B plan is the fit's own minimum.

Chapter 0

What the Role Builds

Follow one big model from a compute budget to a served answer, and see where a cluster's hours go

Your lab has booked 2,048 GPUs for the next model. Before anyone presses start, someone must answer four questions:

  1. How big a model, and how many tokens?
  2. Does it fit, and how do we split it over the GPUs?
  3. What happens when a GPU dies?
  4. How do we serve it fast enough to use?

A frontier lab engineer builds and runs the systems that train, tune, test and serve the largest models. Most of the job is accounting: FLOPs, bytes, hours and error bars. Each skill below is one number you can compute and one failure you can catch.

SkillThe question it answersChapter
Compute budgetHow many FLOPs, and how many days?1
Scaling lawsWhich model size and token count give the lowest loss?2
MemoryDoes the training state fit on the GPUs?3
ParallelismHow do we split the work, and how much time sits idle?4
RooflinesIs this kernel limited by math or by memory?5
ReliabilityHow often do we save, given how often hardware fails?6
Mixture of expertsHow do we grow parameters without growing FLOPs?7
QuantizationHow few bits can each weight use?8
ServingHow many users fit on one server?9

One number sums up a training cluster: MFU (model FLOPs utilization). It is the useful model math done, as a share of what the GPUs could do at peak. The rest of the time leaks away in many small places.

Find where the hours go

The bar is 100% of GPU time. Teal is useful math at peak speed. Switch on each fix and watch teal grow.

Illustrative shares. The end state, 44%, sits in the range that the Llama 3 paper reports for its 405B run (38% to 43% BF16 MFU).

Failure: MFU falls from 41% to 30% overnight with no code change. Measure: profile one step on every node and compare step times. Fix: one slow GPU makes every other GPU wait at each gradient exchange. Drain that node and restart from the last checkpoint.

The road

  1. Budget the compute: 6ND FLOPs, and days at a real MFU.
  2. Spend it with a scaling law: the hero, rebuilt.
  3. Fit the model in memory: 16 bytes per parameter, then shard.
  4. Split the work: data, tensor and pipeline parallelism, and the bubble.
  5. Find the bottleneck: the roofline and arithmetic intensity.
  6. Keep a run alive: failures and the checkpoint interval.
  7. Grow the model with experts: active parameters set the FLOPs, all parameters the memory.
  8. Shrink the weights: fewer bits per weight, faster tokens.
  9. Serve it: the KV cache decides how many users fit.
  10. Field guide: numbers, checklist, code and links to the other skills.
A cluster's GPUs could do 100 units of math per hour at peak. The training run does 40 units of useful model math per hour. What is its MFU?

Chapter 1

Budget the Compute

Count the FLOPs of a training run from two numbers, then turn them into days on a real cluster

Meta trained Llama 3 405B on 15.6 trillion tokens. How much math is that, and how long did it take? You can answer both from the model size, the token count and the GPU spec.

A FLOP is one floating-point operation: one multiply or one add. In the forward pass, each weight does one multiply and one add for each token, so 2 FLOPs. The backward pass costs about twice the forward, so 4 more. That gives 6 FLOPs per parameter per token.

Call the number of parameters N. Call the number of training tokens D. Call the total training math C, for compute.

Say it aloud

C equals six times N times D.

C
C the total training compute, in FLOPs.
6
six FLOPs per parameter per token: 2 in the forward pass, 4 in the backward pass.
N
N the number of parameters. For a mixture of experts, count only the parameters each token uses (Chapter 7).
D
D the number of training tokens.
In plain words

Multiply the parameters N by the tokens D. Multiply by 6. That is the compute C.

With numbers

Llama 3 405B: C = 6 × 405 × 109 × 15.6 × 1012 = 3.79 × 1025 FLOPs. The paper reports 3.8 × 1025, so the rule holds.

Now the days. Divide the compute by the cluster's useful speed. That speed is the number of GPUs, times one GPU's peak FLOPs per second, times the MFU.

days = C / (GPUs × peak × MFU) / 86,400 = 3.8e25 / (16,384 × 989.5e12 × 0.41) / 86,400 = 66 days

NVIDIA lists the H100 at 1,979 BF16 TFLOPS "with sparsity". Dense training math gets half: 989.5 TFLOPS. Llama 3 reports 38% to 43% MFU on up to 16,384 H100s.

Price a training run in days

The faint bar is the time at 100% MFU. The solid bar is the real time. Move any slider, or load the Llama 3 preset.

405B
15.6T
16,384
41%

Peak is 989.5 dense BF16 TFLOPS per H100. The days count only math; restarts after failures add more (Chapter 6).

Failure: a plan for 400B parameters on 8T tokens over 2,048 H100s claims 2.72 hours. Measure: carry the units. 1.92 × 1025 FLOPs / (2,048 × 989 × 1012 FLOPs per second) = 9.5 million seconds, which is 110 days at peak. Fix: divide by MFU too: at 45% it is 244 days.

You train a 7B model on 2T tokens. About how much compute is that?

Chapter 2

Spend It with a Scaling Law

Predict the loss of a run you cannot afford to try, and pick the model size that makes it lowest

You have 5.88 × 1023 FLOPs. A 280B model gets 350B tokens from that budget. A 70B model gets 1.4T tokens. You cannot train both to find out. Which one?

A scaling law is a formula fitted to many small training runs that predicts the loss of a bigger one. Hoffmann et al. trained over 400 models and fitted one. Call the loss L, in nats per token. Call the best loss any model could reach on this data E. Two more terms shrink as the model size N and the tokens D grow.

Say it aloud

L of N and D equals E, plus A over N to the alpha, plus B over D to the beta.

L(N, D)
L of N and D the predicted loss after training N parameters on D tokens, in nats per token.
E
E the floor: the loss no model can beat on this data. Fitted value 1.69.
A
A how much a small model costs in loss. Fitted value 406.4.
Nα
N to the alpha the parameter count raised to alpha = 0.34. Bigger models shrink the second term.
B
B how much too little data costs in loss. Fitted value 410.7.
Dβ
D to the beta the token count raised to beta = 0.28. More data shrinks the third term.
In plain words

Start at the floor E. Add a penalty for a small model, A divided by N to the alpha. Add a penalty for little data, B divided by D to the beta. The sum is the loss L.

With numbers

280B on 350B tokens: L = 1.69 + 0.052 + 0.241 = 1.983. 70B on 1.4T tokens: L = 1.69 + 0.083 + 0.163 = 1.937. The smaller model wins by 0.046 nats per token.

Fix the budget and the two terms trade. Every N you pick sets D = C / (6N). Plot the loss against N and you get an IsoFLOP curve, a valley with one lowest point.

Walk the valley at fixed compute

Pink is your model size. Teal marks the bottom of the valley. Raise the budget and watch the bottom move right.

5.9e23
70B

The curve is the paper's fitted law (its third method). Its own minimum sits at more tokens per parameter than the paper's headline of about 20; the paper's three methods do not agree exactly.

Chinchilla, the 70B model, got 1.4T / 70B = 20 tokens per parameter. Labs often train past that point on purpose. Serving cost grows with N, so a smaller model on more tokens is cheaper to run for years. Llama 3 405B got 38.5 tokens per parameter.

Failure: the big run lands 0.05 nats above the forecast. Measure: refit the law without your largest small run, then predict that run. Fix: if the miss is large, fit on a wider range of sizes and report the forecast with a band.

At a fixed budget, you double N. What happens to D, and why can loss go up?

Chapter 3

Fit the Model in Memory

Count the bytes that training keeps for every parameter, then shard them until each GPU's share fits

You load a 70B model on one H100. The GPU has 80 GB of memory. The weights alone, at 2 bytes each, are 140 GB. Training needs far more than the weights.

Mixed-precision training with Adam keeps five things per parameter. The table counts the bytes, following the ZeRO paper.

WhatFormatBytes per parameter
Weights for the forward and backward passBF162
GradientsBF162
Master copy of the weightsFP324
Adam momentumFP324
Adam varianceFP324

That is 16 bytes per parameter. A 70B model needs 1,120 GB before any activations. So you shard: each GPU keeps one slice of the state. Full sharding is called ZeRO stage 3, or FSDP in PyTorch. Call the memory per GPU M and the number of GPUs that share the model G.

Say it aloud

M equals sixteen times N, over G.

M
M the training state on each GPU, in bytes, before activations.
16
sixteen bytes per parameter: 2 + 2 + 4 + 4 + 4 from the table.
N
N the number of parameters.
G
G the number of GPUs that split the state between them.
In plain words

Multiply the parameters N by 16 bytes. Divide by the GPUs G that share them. Compare M with the GPU's 80 GB, and leave room for activations.

With numbers

70B over G = 16: M = 16 × 70e9 / 16 = 70 GB. It fits, with 10 GB left for activations. Over G = 128: M = 8.75 GB.

Shard until it fits

Each bar is one GPU's memory. The red line is 80 GB. Pick what to shard and how many GPUs share it.

70B
16

Stage costs per parameter follow the ZeRO paper: none 16 bytes, optimizer 4 + 12/G, gradients too 2 + 14/G, weights too 16/G. Activations are left out and depend on batch and sequence length.

Activations are the layer outputs saved for the backward pass. Activation checkpointing saves only some of them and recomputes the rest. Recomputing every layer adds one forward pass: 8 FLOPs per parameter per token instead of 6.

Failure: the run is out of memory at step 1, but only on the longest sequences. Measure: log peak memory per step against sequence length. Fix: turn on activation checkpointing or cut the micro-batch.

A 7B model trains with Adam in mixed precision and no sharding. About how much memory does the training state need?

Chapter 4

Split the Work Across GPUs

Choose what each GPU holds, and count the time a pipeline leaves idle

Sharding fits the state. It does not make one step faster. To use 16,384 GPUs, you split the work itself, in several ways at once. Llama 3 405B combined four: tensor, context, pipeline and data parallelism.

KindEach GPU holdsWhat crosses the networkWhere it fits
Data parallel (with sharding)A slice of the batchGradients each step; weights too if shardedAcross nodes
Tensor parallelA slice of each weight matrixActivations in every layerInside one node, on the fast link
Pipeline parallelA block of whole layersActivations at stage bordersAcross nodes
Expert parallelSome experts of a mixture of expertsTokens sent to their expertsMoE models

A pipeline has a catch. Stage 2 cannot start until stage 1 hands it work. So you cut the batch into microbatches and stream them through. At the start and the end some stages still wait. That idle time is the bubble. Call the number of pipeline stages p and the number of microbatches m.

Say it aloud

The bubble equals p minus one, over m plus p minus one.

bubble
bubble the share of each stage's time spent idle, from 0 to 1.
p − 1
p minus one the number of slots it takes to fill the pipe, and again to drain it.
m
m the number of microbatches in one step.
p
p the number of pipeline stages, one block of layers each.
In plain words

Each stage works for m slots in the forward pass, but the pass lasts m + p − 1 slots. The idle part is p − 1 of them. The backward pass repeats the pattern, so the share is the same.

With numbers

p = 8 and m = 8: bubble = 7 / 15 = 47%. Raise m to 32: bubble = 7 / 39 = 18%.

Fill the pipeline

Each row is one stage. Teal is a forward pass, purple a backward pass, red an idle slot. Add microbatches and watch red shrink.

4
4

The GPipe schedule: all forwards, then all backwards, one slot each (a backward pass takes about two forward slots in real life). The bubble share does not depend on that ratio.

Failure: step time grows as you add nodes, though each GPU does less math. Measure: a profiler trace shows the gradient exchange after the backward pass, with compute stopped. Fix: start exchanging each layer's gradients while earlier layers still compute.

A pipeline has 4 stages and 12 microbatches. What share of time is the bubble?

Chapter 5

Find the Bottleneck with a Roofline

Divide an operation's math by the bytes it moves, and learn whether a faster chip would help

A teammate's kernel runs at 3 TFLOPS on an H100 that can do 989. Is the kernel broken? Not if it spends its time waiting for memory. A GPU has two limits: how fast it does math, and how fast it reads memory.

Arithmetic intensity is the FLOPs an operation does for each byte it moves to or from memory. Call it I. Call the peak math speed F and the memory bandwidth B. The best speed you can reach is P.

Say it aloud

P equals the minimum of F, and I times B.

P
P the highest speed this operation can reach, in FLOPs per second.
min
the minimum of take the smaller of the two. The tighter limit wins.
F
F peak math speed: 989.5 TFLOPS dense BF16 on an H100.
I
I arithmetic intensity: FLOPs per byte moved.
B
B memory bandwidth: 3.35 TB per second on an H100.
In plain words

Multiply the intensity I by the bandwidth B. That is how fast memory can feed the math. If it is below the peak F, memory is the limit. If not, math is.

With numbers

Send one token through an 8,192 × 8,192 weight matrix. It does 2 × 8,1922 FLOPs and reads 2 × 8,1922 bytes of weights, so I ≈ 1. Then P = min(989.5, 1 × 3.35) = 3.35 TFLOPS. The chip is 0.3% busy.

The two limits meet at the ridge point: F / B = 989.5 / 3.35 = 295 FLOPs per byte. Batch b tokens through the same matrix and the weights are read once for all of them, so I grows almost as fast as b.

Climb the roofline with batch size

The slanted line is the memory limit, the flat line the math limit. Drag the batch and watch the dot climb to the ridge.

1

An 8,192 × 8,192 BF16 weight matrix; bytes count the weights plus the input and output tokens. H100 numbers from NVIDIA's page (dense BF16 is half the sparse figure).

Attention has the same problem. A plain kernel writes the full score matrix, one number per pair of tokens, to memory and reads it back. FlashAttention computes it in tiles inside the chip's fast on-chip memory, so the matrix never goes to main memory.

Failure: a layer-norm kernel reaches 2% of peak FLOPS. Measure: its achieved bandwidth. If it moves 2.9 TB/s of a possible 3.35, it is near its true limit. Fix: fuse it with the next operation, so the data is read once for both.

An operation does 50 FLOPs per byte on an H100 (ridge 295). Which change helps it most?

Chapter 6

Keep a Run Alive

Turn a cluster's failure rate into the checkpoint interval that wastes the least time

In a 54-day stretch of Llama 3 pretraining, the job stopped 466 times. 419 stops came as a surprise. The team traced about 78% of those to hardware faults. GPUs were the largest single cause. That is 7.8 surprise stops a day, one every 3.1 hours.

When a GPU fails, the whole job stops and restarts from the last checkpoint, a saved copy of the full training state. Save often and you spend time writing. Save rarely and each failure throws away more work. Call the time to write one checkpoint δ and the mean time between failures of the whole job M. The best interval between saves is τ.

Say it aloud

Tau equals the square root of two times delta times M.

τ
tau the time between two checkpoints that wastes the least, in minutes.
√
the square root of the interval grows slowly: four times the failure gap only doubles it.
δ
delta the time to write one checkpoint, in minutes.
M
M the mean time between failures of the whole job, in minutes.
In plain words

Multiply the write time δ by the failure gap M, double it, and take the square root. Saving every τ minutes balances the two losses: δ / τ spent writing, and τ / (2M) redone after a crash.

With numbers

M = 3.1 hours = 185.6 minutes, and a made-up δ = 1 minute: τ = √(2 × 1 × 185.6) = 19.3 minutes. Waste = 1 / 19.3 + 19.3 / 371 = 5.2% + 5.2% = 10.4%.

Pick how often to save

The curve is total waste. Yellow is time spent writing, red is work redone after crashes. Drag your interval toward the bottom of the curve.

16,384
1 min
60 min

Failure gap scales from the Llama 3 rate (419 unexpected stops in 54 days on 16,384 GPUs), assuming failures grow with GPU count. Write times are illustrative. Restart time after each crash is left out.

The paper reports more than 90% effective training time despite those stops. Fast, frequent saves and automatic restarts made that possible.

Failure: after a restart, the loss jumps and takes hours to recover. Measure: compare the first batches after the restore with the batches the run saw before the crash. Fix: save the data loader's position and the random seeds in the checkpoint, not only the weights.

You double the GPUs, so failures come twice as often. By what factor should the checkpoint interval change?

Chapter 7

Grow the Model with Experts

Store many experts but run only a few per token, and count the compute and memory each costs

DeepSeek-V3 has 671B parameters. A dense model that size, on its 14.8T tokens, would need 6 × 671e9 × 14.8e12 = 6.0 × 1025 FLOPs. DeepSeek-V3 needed about 18 times less. Each token used only 37B of its parameters.

A mixture of experts (MoE) replaces each feed-forward block with many smaller blocks, the experts. A small router scores the experts for each token and sends the token to the top few. Every token uses the rest of the model (attention, embeddings): the shared part.

Call the shared parameters Ns and all expert parameters together Ne. Call the number of experts E and the experts each token uses k. The parameters one token touches are Nact.

Say it aloud

N-act equals N-s, plus k over E, times N-e.

Nact
N-act the active parameters: the ones one token uses. Compute follows this number, so C = 6 Nact D.
Ns
N-s the shared parameters every token uses.
k
k the experts the router picks for each token.
E
E the experts in each layer.
Ne
N-e the parameters of all experts together. Memory must hold all of them.
In plain words

Take the share of experts a token uses, k over E. Multiply it by the expert parameters N-e. Add the shared parameters N-s. That is N-act, which sets the FLOPs. The total, N-s + N-e, sets the memory.

With numbers

Mixtral has E = 8, k = 2, 47B parameters in total and 13B active. Solve the two: Ne = (47 − 13) × 4 / 3 = 45.3B, Ns = 1.7B. Check: 1.7 + (2 / 8) × 45.3 = 13.0B.

Route tokens to experts

Each column is an expert; its height is the tokens it got. Add experts and memory grows; compute per token stays. Switch off balancing and watch a few experts take the load.

2

Expert size from Mixtral (5.7B per expert slot, 1.7B shared), scaled to more experts for illustration. The page simulates the routing of 400 toy tokens; the unbalanced router favours a few experts.

The memory bill does not shrink. All 671B parameters of DeepSeek-V3 must sit in GPU memory, so experts are spread over GPUs: expert parallelism from Chapter 4. Each token then crosses the network to its experts and back.

Failure: MFU drops and a few GPUs run hot while others idle. Measure: count tokens per expert per step. Fix: the router has collapsed onto a few experts. Add a load-balancing loss, or a per-expert bias as DeepSeek-V3 does.

An MoE has 2B shared parameters, 64 experts holding 128B parameters in total, and k = 4. How many parameters does one token use?

Chapter 8

Shrink the Weights with Quantization

Store each weight in fewer bits, and see why that makes one user's answer arrive faster

One user chats with a 70B model. Each new token reads every weight once, and Chapter 5 showed that this is memory-bound. So the speed limit is the bytes of weights divided by the memory bandwidth. Fewer bytes per weight means more tokens per second.

Quantization stores each weight with fewer bits: 8 or 4 instead of 16. Call the parameters N, the bits per weight b, and the memory bandwidth of the GPUs that hold the model B. The top speed for one user is t.

Say it aloud

t is at most B, over N times b over eight.

t
t tokens per second for one user, at batch 1.
B
B memory bandwidth, in bytes per second: 3.35 TB/s per H100, added up over the GPUs that hold the model.
N
N the number of parameters.
b / 8
b over eight bytes per weight: 16 bits is 2 bytes, 4 bits is half a byte.
In plain words

Multiply the parameters N by the bytes per weight. That is the data each token must read. Divide the bandwidth B by it. You cannot make tokens faster than that.

With numbers

70B in BF16 is 140 GB, so it needs two H100s: t ≤ 6.7e12 / 140e9 = 48 tokens per second. In 4 bits it is 35 GB on one H100: t ≤ 3.35e12 / 35e9 = 96 tokens per second, on half the GPUs.

The price is precision. A 4-bit number has 16 levels. Quantization maps each weight to the nearest level on a grid between a group's smallest and largest value. One outlier stretches the grid, and every other weight in the group rounds worse.

Round the weights

Dots are 64 weights of one group; ticks are the levels. Lower the bits and watch the error grow. Add an outlier and see the grid stretch.

Toy weights from a seeded bell curve; the grid spans the group's minimum to maximum. Memory and speed use 70B parameters and the H100's 3.35 TB/s, at batch 1.

So real methods give each small group of weights, often 128, its own grid. They tune it on calibration data: sample inputs that show which weights matter (see Sparsity and Quantization).

Failure: a 4-bit model matches the original on average, but its maths scores fall hard. Measure: compare scores per task, not one average. Fix: the calibration set had no maths prompts. Add them, or keep the most sensitive layers in 8 bits.

A 13B model runs at batch 1 on one H100 (3.35 TB/s). What is its top speed in 8 bits?

Chapter 9

Serve It: the KV Cache

Count the memory each user's conversation holds, and see how many users fit on one server

Chapter 5 showed that one token at a time leaves an H100 0.3% busy. The fix is a big batch: many users' tokens through the same weights at once. What stops the batch from growing is memory, and the culprit is the KV cache.

To write each new token, attention looks back at every earlier token's keys and values. The server keeps them in memory for the whole conversation instead of recomputing them. Call the layers L, the key-value heads hkv and the size of each head dh. Call the tokens per conversation s, the conversations in the batch b and the bytes per number e.

Say it aloud

KV equals two, times L, times h-k-v, times d-h, times s, times b, times e.

KV
K-V the KV cache size, in bytes.
2
two one key and one value per head.
L
L the number of layers: 80 for Llama 3 70B.
hkv
h-k-v the key-value heads: 8 for Llama 3 70B, which shares them across 64 query heads.
dh
d-h the numbers per head: 8,192 / 64 = 128.
s
s the tokens in one conversation so far.
b
b the conversations served at once.
e
e bytes per number: 2 for BF16.
In plain words

For one token, multiply 2 by the layers L, the heads h-k-v, the head size d-h and the bytes e. Multiply by the tokens s and the conversations b.

With numbers

Llama 3 70B: 2 × 80 × 8 × 128 × 2 = 327,680 bytes per token. An 8,192-token conversation holds 2.7 GB. At 131,072 tokens it holds 42.9 GB.

Pack users onto one server

The bar is a server of four H100s, 320 GB. Pink is the weights, purple the KV cache. Grow the context and the batch until it overflows.

8,192
32

Llama 3 70B shape from the paper's Table 3 (80 layers, width 8,192, 64 heads, 8 KV heads). BF16 weights, 140 GB; framework overhead is left out.

Serving engines such as vLLM store the cache in small pages, so memory is not reserved for tokens a user never writes (serving engines). Shared key-value heads cut the cache 8 times against one head pair per query head.

Failure: throughput collapses when users paste long documents. Measure: log KV cache use and the running batch size per second. Fix: cap the context per user, page the cache, or store it in 8 bits.

A server has 180 GB free after the Llama 3 70B weights. How many 8,192-token conversations fit?

Chapter 10

Field Guide

Keep the terms, the numbers, the checklist and the code in one place

A frontier lab engineer turns a compute budget into a trained, tested and served model. Each skill on this page is one formula and one failure to watch for.

Terms and numbers

TermWhat it isWorked number here
Training computeC = 6NDLlama 3 405B: 3.8 × 1025 FLOPs
DaysC / (GPUs × peak × MFU)66 days on 16,384 H100s at 41%
Scaling lawE + A / Nα + B / Dβ70B on 1.4T: 1.937; 280B on 350B: 1.983
Training memory16 bytes per parameter, divided by G when sharded70B: 1,120 GB; over 16 GPUs, 70 GB
Pipeline bubble(p − 1) / (m + p − 1)p 8, m 32: 18%
Ridge pointPeak FLOPS / bandwidthH100: 295 FLOPs per byte
Checkpoint interval√(2 δ M)19.3 min for δ 1 min, M 3.1 h
Active parametersNs + (k / E) NeMixtral: 1.7 + 45.3 / 4 = 13B of 47B
Decode speed limitB / (N × b / 8)70B in 4 bits on one H100: 96 tokens/s
KV cache2 L hkv dh s b eLlama 3 70B: 327,680 bytes per token

Checklist before a big run

The core as code

pythonfrom math import sqrt

PEAK, BW = 989.5e12, 3.35e12              # H100 dense BF16 FLOP/s, HBM bytes/s

def train_days(N, D, gpus, mfu):
    return 6 * N * D / (gpus * PEAK * mfu) / 86400

def chinchilla_loss(N, D, E=1.69, A=406.4, B=410.7, a=0.34, b=0.28):
    return E + A / N**a + B / D**b

def bubble(p, m): return (p - 1) / (m + p - 1)
def attainable(intensity): return min(PEAK, intensity * BW)
def ckpt_interval(write_min, mtbf_min): return sqrt(2 * write_min * mtbf_min)
def active_params(shared, experts_total, k, E): return shared + k / E * experts_total
def decode_tok_s(N, bits, bw=BW): return bw / (N * bits / 8)
def kv_bytes(layers, kv_heads, d_head, seq, batch, nbytes=2):
    return 2 * layers * kv_heads * d_head * seq * batch * nbytes

print(train_days(405e9, 15.6e12, 16384, 0.41))          # 66.0
print(chinchilla_loss(70e9, 1.4e12))                      # 1.937
print(ckpt_interval(1, 54 * 24 * 60 / 419))           # 19.3 minutes
print(decode_tok_s(70e9, 4))                          # 95.7 tokens/s
print(kv_bytes(80, 8, 128, 8192, 1) / 1e9)              # 2.68 GB

The other skills, each with its own lesson

Papers behind the numbers

The takeaway. Before any run, compute five numbers: the FLOPs, the days at a real MFU, the bytes per GPU, the idle share and the checkpoint interval. To serve it, compute two more: the bytes per weight and the KV cache per user.

Now press Present or Teach and explain each formula from memory, from 6ND to the KV cache. Then go back to the hero and say why the 70B plan beats the 280B plan.

Frontier Lab Engineer: Compute, Scaling Laws, Parallelism, Kernels and Serving
Chinchilla paper · Llama 3 paper · Distributed Training · Back to Gleams