Lesson 10 of 11 · The Landscape
Model Sizes and Trade-offs
What LLM size means: parameters and memory, 8-bit and 4-bit quantisation, the KV cache, mixture-of-experts, speed and cost, and when a small model is enough.
- 6 min read
- Intermediate
- Reviewed
- How a model's size translates into memory
- What quantisation is and what it costs in quality
- How mixture-of-experts models separate total and active parameters
- How size affects speed and cost, and when smaller is better
What "8B" means
A model described as "8B" has about 8 billion parameters. Every parameter is a number that must be stored in memory, usually on a graphics card (GPU), while the model runs. So size decides what hardware a model needs.
At 16-bit precision, each parameter takes 2 bytes: an 8B model needs about 16 GB just for its weights, plus extra for the work it does while generating.
Quantisation
Think of it as rounding: instead of storing 0.0172836, store something close to it using far fewer bits. Modern methods are clever about which numbers can be rounded more aggressively.
bytes_per_parameter = {"16-bit": 2, "8-bit": 1, "4-bit": 0.5}
def memory_gb(parameters_billions, precision):
weights = parameters_billions * 1e9 * bytes_per_parameter[precision]
return weights * 1.2 / 1e9 # add about 20% for the KV cache and other overhead
print(f"{'model':>6} {'16-bit':>8} {'8-bit':>8} {'4-bit':>8}")
for size in [3, 8, 70, 405]:
row = f"{str(size) + 'B':>6}"
for precision in ["16-bit", "8-bit", "4-bit"]:
row += f" {memory_gb(size, precision):7.1f}G"
print(row)At 4-bit, an 8B model fits in under 5 GB, small enough for many laptops. A 70B model drops from about 168 GB to 42 GB. The very largest models still need several high-end GPUs even when quantised.
Mixture of experts
# A mixture-of-experts model: many experts, only a few used per token
experts = 64
active_experts = 4
expert_size = 1.5e9 # parameters in each expert
shared = 6e9 # parameters every token uses (attention, embeddings...)
total = shared + experts * expert_size
active = shared + active_experts * expert_size
print(f"Total parameters: {total / 1e9:.0f} billion (all must be stored in memory)")
print(f"Active per token: {active / 1e9:.0f} billion (sets the speed and cost per token)")This MoE model has the knowledge capacity of about 100 billion parameters but the per-token computation of about 12 billion, so it runs much faster than a dense 100B model. The catch: all the experts still have to be in memory. Many of today's largest models use this design. When comparing models, check whether a size means total or active parameters.
Size, speed and cost
| Smaller models | Larger models | |
|---|---|---|
| Speed | Many tokens per second | Fewer tokens per second |
| Cost per token | Low | High |
| Hardware | Laptop or a single GPU | Many GPUs |
| Knowledge and nuance | Less | More |
| Hard reasoning | Weaker | Stronger |
Generating each token requires reading essentially all the active parameters from memory, so bigger models are slower per token. Providers price accordingly: the largest tier can cost many times more per token than the smallest.
Common mistakes
Check whether a quantised model fits on a graphics card.
parameters = 13e9 # a 13-billion-parameter model bytes_each = 0.5 # 4-bit quantised: half a byte per parameter overhead = 1.2 # add 20% for the KV cache and other needs card_memory_gb = 8 # memory on the graphics card # Print, like the lines below: # 13B at 4-bit needs about 7.8 GB # Fits on an 8 GB graphics card: yes
A mixture-of-experts model has 100 billion total parameters but 12 billion active per token. Which statement is true?
Summary
- Memory for weights is about parameters × bytes per parameter: 2 bytes at 16-bit, 1 at 8-bit, half a byte at 4-bit.
- Quantisation shrinks models with a small quality cost; 4-bit is popular for running models locally.
- The KV cache adds memory that grows with context length.
- Mixture-of-experts models store many parameters but use few per token: check total versus active.
- Bigger means more capable but slower and costlier; small models are often the right tool.
Next: how to read benchmark results without being misled.
Finished reading? Tick it off to track your progress.