Math for Memory, Throughput & Speedups

Nearly every number in this field is one of three kinds of quantity. An amount says how much of something there is: 16 GB of weights. A rate says how fast something moves: 3.35 TB/s of memory bandwidth. A ratio compares two quantities of the same kind: a 1.25× speedup. Orientation already leaned on the first two when it divided a model's bytes by a GPU's bandwidth and predicted a hard speed ceiling.

This lesson makes the arithmetic explicit. None of it goes past napkin level: multiplication, division, and careful units. By the end you should be able to pick up a model card, the spec page a model ships with, and a GPU datasheet, and answer three questions before touching hardware: does it fit, how fast can it possibly run, and what a claimed speedup is worth.

Counting bytes

Start with amounts. A model's parameters are numbers, and each one is stored at some width, its precision. Full 32-bit floating point spends four bytes per number; the formats models actually ship and serve in are narrower. For napkin math, a format is its byte width.

Weight memory is then one multiplication: parameter count × bytes per parameter. Llama 3.1 8B has 8.03 billion parameters, so:

PrecisionBytes per parameterWeights at 8.03B parameters
FP324~32 GB
BF16 / FP162~16 GB
FP81~8 GB
INT40.5~4 GB

The same model spans an eightfold memory range before any other technique is involved, which is why precision is the first lever anyone reaches for when a model does not fit. Llama 3.1 8B ships at BF16; that is where the course's 16 GB figure comes from. What the narrow formats trade away, and why real 4-bit checkpoints run larger than the half-byte row suggests (some tensors stay wide, and quantization bookkeeping rides along), is covered in quantization and KV compression.

Gigabytes come in two sizes, and the difference is just big enough to look like a mistake. This course uses decimal prefixes: kilo, mega, giga, and tera are powers of ten, so a gigabyte is 10⁹ bytes, and bandwidth specs and model download sizes are usually quoted the same way. But many tools count in powers of two, in units named kibi, mebi, and gibi: a gibibyte (GiB) is 1024³ bytes, about 7 percent more than a gigabyte. The 16 GB weights file and a 14.9 GiB weights file are the same file. When a memory reading looks a few percent off from your arithmetic, check the unit before doubting the math.

Check your napkin against real checkpoints

Hugging Face's Model Memory Utility runs the parameters-times-bytes multiplication against real checkpoints on the Hub; gated models, Llama included, ask for your Hugging Face token. Use it to confirm your own numbers.

Rates and time

A rate is an amount per second, and three of them do most of the work in this field. Memory bandwidth is bytes per second: how fast data moves between a GPU's memory and its compute units. Compute rate is floating-point operations per second, FLOPS: how fast the chip does math. Generation speed is tokens per second, the rate a product actually feels.

The capitalization there is a genuine trap. FLOPs, lowercase s, is a count of operations: an amount. FLOPS, capital S, is operations per second: a rate. A model costs FLOPs; a GPU supplies FLOPS. Papers and datasheets mix the two freely, so read which is meant from the units, not the spelling.

Amounts and rates connect through one identity: time equals amount divided by rate. The skill is keeping the units honest, which means putting both sides in the same prefix before dividing. Redo orientation's ceiling with the units visible. Generating one token reads all 16 GB of weights, and an H100 SXM moves 3.35 TB/s, which is 3,350 GB/s. Then 16 ÷ 3,350 gigabytes over gigabytes-per-second leaves seconds: about 0.0048 of them, orientation's 4.8 milliseconds per token, about 200 tokens per second.

The compute side runs the same identity. Generating one token costs roughly 2 FLOPs per parameter (the module on prefill, decode, and KV memory derives where the 2 comes from), about 16 GFLOPs for the 8B model. The H100 supplies 989 TFLOPS at BF16, which is 989,000 GFLOPS, and 16 ÷ 989,000 leaves about 16 microseconds. Two divisions, and you have reproduced the imbalance the whole field organizes around: microseconds of math against milliseconds of byte-moving.

Both results are floors, and a floor under time per token is the same fact as a ceiling over tokens per second, which is how orientation phrased it. They are floors because datasheet numbers are peaks: the vendor's best case under ideal conditions, which real systems never fully sustain.

So treat napkin results as bounds, not predictions. A real measurement will land above the floor, and one that lands below it means an assumption broke: fewer bytes moved than you assumed, or the measurement itself is wrong. Either way the napkin told you where to look.

The napkin generalizes to any model and GPU in a few lines. Here it is for a nominal 70-billion-parameter model on the same H100:

Run it and three lines come back: 140 GB at BF16, which does not fit; 70 GB at FP8 and 35 GB at INT4, which do, with floors of about 21 and 10 milliseconds per token. Read them with two cautions. Fits means the weights fit: a running model also holds growing per-request state and runtime overhead, the accounting from prefill, decode, and KV memory, so a near-capacity fit like the FP8 line is tight rather than comfortable. And the fit check comes before the floor, because a bandwidth floor for a model that does not fit is fiction; the BF16 line's 41.8 milliseconds would mean something only on hardware that could hold the weights.

Latency and throughput

The field's two performance words belong to different unit families. Latency is time per event: milliseconds per token, seconds per request. Smaller is better. Throughput is events per second: tokens per second, requests per second. Bigger is better. Tokens, not requests, are usually the event worth counting, for the reason the lesson on inference engineering gave: the expensive resource is bytes moved per token.

For a single stream the two are reciprocals carrying one fact. A stream at about 5 milliseconds per token runs at about 200 tokens per second; flip one and you have the other.

Common misconception. Because the single-stream numbers are reciprocals, engineers read a system's tokens-per-second figure as a promise of per-user speed. Once requests share the hardware, the two decouple: batching can raise a GPU's total tokens per second by an order of magnitude while each individual stream gets no faster, and under load somewhat slower. A throughput claim says nothing about one user's experience until you know how many streams share it.

Keeping the two on separate mental ledgers is enough for now. Measuring them honestly, and the named metrics the industry reports, is covered in inference benchmarking.

Speedup arithmetic

A speedup is a ratio of times: time before divided by time after. A change that takes a step from 20 milliseconds to 15 is 20 ÷ 15, a 1.33× speedup.

Percentages are where speedup talk goes wrong, because they come in two incompatible flavors. “25 percent faster” usually means 1.25×, while the change above, which takes 25 percent less time, is 1.33×; by the first convention, a 2× speedup is 100 percent faster, not 50. Report ×, and when you read a percent claim, ask which flavor it is.

Speedups compose by time accounting, not by addition. A step is a sum of parts, and speeding up one part shrinks only that part's share.

Suppose one operation takes 30 percent of a step, and a rewrite makes that operation 3× faster. The other 70 percent is untouched; the 30 becomes 10; the step falls from 100 to 80 percent of its old time, a 1.25× overall speedup. The general form is Amdahl's law: if a fraction p of the time gets s times faster, the whole gets 1 ÷ ((1 − p) + p/s) faster.

The sting is the limit: make the rewrite infinitely fast and the ceiling is 1 ÷ (1 − p), which for the 30 percent operation is 1.43×, no matter how good the rewrite is. The habit to build: before valuing any optimization, ask what fraction of the time it touches. That is why measurement comes before improvement in the run, measure, improve spine levels of inference engineering drew.

That is the whole toolkit: three kinds of quantity, time as amount over rate, and speedups bounded by the share of time they touch. Every module ahead reuses it, mostly without comment. The next lesson turns to where the amounts come from: the vectors, matrices, and tensor shapes that a model's parameters actually live in.