Compute, memory and scale
Training and running LLMs is dominated by multiplying large matrices on GPUs. Work is measured in floating-point operations (FLOPs), and memory is measured in bytes: each weight is typically a 2-byte number. Big models are trained across thousands of GPUs that must constantly exchange results. Larger models trained on more data reach predictably lower loss, which is why scale matters. Serving users is a separate, ongoing cost, in which each generated token needs every weight read from memory.
What the animation says
Counting the arithmetic
A language model is mostly a stack of big matrices full of learned numbers, called weights. To process one token, its vector gets multiplied by each matrix. Here's a tiny case: three by three weights times a vector of three. Nine multiplies, and nearly as many adds. Each multiply or add is one FLOP. In big matrices, every weight costs about two FLOPs per token. Training must also work out how to adjust each weight. Per weight, per token, roughly how many FLOPs then?
The training bill
Six. Working out the adjustments roughly triples the work, so training costs about six FLOPs per weight, per token. With N weights and D training tokens, the total is about six times N times D. Take a seven billion weight model and two trillion tokens. That's eight point four times ten to the twenty-two FLOPs. One GPU doing four hundred trillion FLOPs a second would need about fifty-eight thousand hours. Split across a thousand GPUs, that's about two and a half days, with GPUs exchanging results the whole time.
Holding the weights
Arithmetic is one bill. Memory is the other, and it's counted in bytes. Each weight is usually stored in two bytes. So N weights need about two N bytes. Our seven billion weight model needs fourteen gigabytes, just for the weights. When the weights don't fit on one GPU, they're split across several. And you can only use whole GPUs. Try it: twenty billion weights, GPUs with sixteen gigabytes each. Tap the last GPU you need.
One token, one user
Now serving. For one user, each new token needs every weight read from memory once. For our model, that's fourteen gigabytes read, and about fourteen billion FLOPs of arithmetic. This GPU reads about three point three trillion bytes a second, and computes four hundred trillion FLOPs a second. So which takes longer for each new token?
Memory sets the speed
Reading the weights. This line divides FLOPs by compute speed: about thirty-five thousandths of a millisecond. This line divides bytes by read speed: over four milliseconds. So the GPU mostly waits on memory, about a hundred and twenty times longer than it computes. That caps one user at about two hundred thirty-six tokens a second. And serving is paid for every token, for as long as people use the model.
Why bigger keeps winning
So why do labs keep building bigger models trained on more text? The loss measures how badly the model predicts the next token. Lower is better. As weights and training tokens grow, the loss falls along a smooth, predictable curve. So bigger models on more text buy lower loss, and you can predict how much. Remember: two N FLOPs per token, six N D to train, two N bytes to store the weights.
Big matrices, counted in FLOPs and bytes
The rough rules
Training a 7B model
Serving: reading weights sets the speed
N = 7e9 # weights
bytes_w = 2 * N # 14e9 bytes of weights
flops_tok = 2 * N # FLOPs per generated token
gpu_flops = 4e14 # sustained FLOP/s
gpu_read = 3.3e12 # memory read speed, bytes/s
t_math = flops_tok / gpu_flops # arithmetic time
t_read = bytes_w / gpu_read # time to read all weights
print(f"math {t_math*1e3:.3f} ms, read {t_read*1e3:.2f} ms")
print(f"max ~{1/t_read:.0f} tokens/s for one user")
Remember
On Bytewise this lesson comes in small steps with a check at the end, and the app brings it back right before you would forget it.
Bytewise
All courses