Numbers to Know for ML Systems
ML infrastructure interviews reward people who can do arithmetic out loud. "How many GPUs do we need?", "Will the 70B model fit?", "How many users can one replica serve?", "Is self-hosting cheaper than the API?" Each of these has an answer you can reach in two minutes with a handful of numbers and four or five formulas. Candidates who can do that make every later design choice look grounded. Candidates who can't end up guessing, and interviewers notice.
This post collects the numbers worth memorizing and, more importantly, the reasoning that connects them:
- Hardware: what a GPU can store, read and compute.
- Memory: weights, KV cache, and training state.
- Compute: FLOPs per token for inference and training.
- Throughput: why decoding is limited by memory bandwidth, and what batching buys.
- Budgeting a fleet in tokens per second.
- Multi-GPU deployment: when and how to split a model.
- Self-hosting costs versus an API.
All figures are rounded. In an interview, round aggressively and say so. Being within 20-30% with the right reasoning beats a precise number with no reasoning.
Hardware Numbers
Three properties of an accelerator matter for almost every calculation: memory capacity (what fits), memory bandwidth (how fast you can read it) and compute (how many floating-point operations per second). Here are the common data-center GPUs, using dense (non-sparse) tensor-core throughput:
| GPU | Memory | Bandwidth | BF16/FP16 dense | FP8 dense | Typical role |
|---|---|---|---|---|---|
| NVIDIA A100 | 40 or 80 GB HBM2e | ~1.6-2.0 TB/s | ~312 TFLOP/s | not supported | previous-generation training and serving |
| NVIDIA H100 SXM | 80 GB HBM3 | ~3.35 TB/s | ~990 TFLOP/s | ~1,980 TFLOP/s | the default for LLM training and serving |
| NVIDIA H200 | 141 GB HBM3e | ~4.8 TB/s | same as H100 | same as H100 | bigger and faster memory, same compute |
| NVIDIA B200 | ~180-192 GB HBM3e | ~8 TB/s | ~2.2 PFLOP/s | ~4.5 PFLOP/s | newest generation; figures vary by system |
| NVIDIA L40S | 48 GB GDDR6 | ~0.86 TB/s | ~360 TFLOP/s | ~730 TFLOP/s | inference, smaller models |
| NVIDIA L4 | 24 GB GDDR6 | ~0.3 TB/s | ~120 TFLOP/s | ~240 TFLOP/s | cheap inference, encoders, small models |
Google TPUs and AMD's MI300X (192 GB of HBM, ~5.3 TB/s) play the same game with different numbers. The method below works for any of them.
Two derived numbers are worth knowing:
- Time to read all of memory once. An H100 reads its 80 GB in 80 / 3,350 ≈ 24 ms. That's a floor on any operation that has to touch every weight.
- The ridge point: compute divided by bandwidth. For an H100 it's 990 TFLOP/s ÷ 3.35 TB/s ≈ 295 FLOPs per byte. A kernel that does fewer than ~295 operations for every byte it reads from memory is memory-bandwidth-bound: the math units wait on memory. Above that, it's compute-bound. This single ratio explains most of LLM serving.
Interconnects, from fastest to slowest:
| Link | Bandwidth (per GPU or per link) | Used for |
|---|---|---|
| HBM (on the GPU) | 2-8 TB/s | reading weights and KV cache |
| NVLink (H100, inside one 8-GPU node) | ~900 GB/s total, ~450 GB/s each way | tensor parallelism, fast all-reduce |
| PCIe Gen5 x16 | ~64 GB/s each way | host-to-GPU copies, cheaper servers |
| InfiniBand / RoCE NIC (400 Gb/s) | ~50 GB/s per NIC, often 8 per node | data and pipeline parallelism across nodes |
| Local NVMe SSD | a few GB/s per drive | loading weights at startup |
The jump from NVLink (hundreds of GB/s) to the network (tens of GB/s per GPU) is why we split models one way inside a node and another way across nodes.
Memory: Weights
The weights take parameters × bytes per parameter:
| Precision | Bytes per parameter | 8B model | 70B model | 405B model |
|---|---|---|---|---|
| FP32 | 4 | 32 GB | 280 GB | 1,620 GB |
| BF16 / FP16 | 2 | 16 GB | 140 GB | 810 GB |
| FP8 / INT8 | 1 | 8 GB | 70 GB | 405 GB |
| INT4 | 0.5 (plus a few % for scales) | ~4.5 GB | ~38 GB | ~220 GB |
Serving normally uses BF16 or FP8. So the shortcut is "2 GB per billion parameters in BF16, 1 GB in FP8." A 70B model in BF16 doesn't fit on one 80 GB GPU; in FP8 it barely fits, with almost nothing left for anything else.
Mixture-of-experts (MoE) models break the link between size and compute. Mixtral 8x7B has about 47B parameters in total but activates about 13B per token. DeepSeek-V3 has 671B in total and about 37B active. Memory is set by the total parameter count (every expert must be resident), while compute and bandwidth per token are set by the active count. In FP8, DeepSeek-V3's 671 GB of weights don't fit in one 8×H100 node (640 GB), but they do fit in an 8×H200 node (1,128 GB).
Memory: The KV Cache
During generation, a transformer stores a key and a value vector for every previous token at every layer, so it doesn't recompute them. This KV cache usually decides how many sequences a GPU can serve at once. The formula:
KV bytes per token = 2 (K and V) × layers × KV heads × head dim × bytes per value
Note KV heads, not attention heads. Most modern models use grouped-query attention (GQA), where several query heads share one key/value head. That shrinks the cache by the group size.
| Model | Layers | KV heads × dim | KV per token (BF16) | One 8k sequence | One 128k sequence |
|---|---|---|---|---|---|
| Llama-2-7B (no GQA) | 32 | 32 × 128 | 2 × 32 × 32 × 128 × 2 = 512 KB | 4 GB | 64 GB (hypothetical; it supports 4k) |
| Llama-3-8B | 32 | 8 × 128 | 2 × 32 × 8 × 128 × 2 = 128 KB | 1 GB | 16 GB |
| Llama-3-70B | 80 | 8 × 128 | 2 × 80 × 8 × 128 × 2 = 320 KB | 2.5 GB | 40 GB |
| Llama-3.1-405B | 126 | 8 × 128 | 2 × 126 × 8 × 128 × 2 ≈ 504 KB | ~3.9 GB | ~63 GB |
(KB here means 1,024 bytes, so 8k tokens × 128 KB = 1 GB exactly.)
Two things jump out. First, GQA made a 4× difference between two models of similar size: Llama-2-7B needs 512 KB per token, Llama-3-8B needs 128 KB. Second, long context is expensive. One 128k-token conversation on the 70B model needs 40 GB of cache, half an H100, for a single user.
How Many Sequences Fit?
The capacity formula is:
concurrent sequences ≈ free memory for KV ÷ (KV bytes per token × average tokens per sequence)
Worked example: Llama-3-8B on one H100. Serving engines typically claim about 90% of GPU memory, which is 72 GB. Subtract 16 GB of BF16 weights and a couple of GB for activations and CUDA graphs: roughly 54 GB for KV cache. That's 54 × 10^9 ÷ 131,072 ≈ 410,000 tokens. If the average sequence holds 2,000 tokens (prompt plus output so far), about 200 sequences fit at once.
Worked example: Llama-3-70B on four H100s. 4 × 80 × 0.9 = 288 GB, minus 140 GB of weights and some overhead, leaves about 150-160 GB. At 320 KB per token that's roughly 500,000 tokens, or about 250 sequences of 2,000 tokens.
This only works if the engine allocates KV memory as sequences actually grow, in small blocks, instead of reserving the maximum context length for each request. Reserving 8k tokens per sequence for the 8B model would hold 54 GB ÷ 1 GB = 54 sequences instead of 200. That's what paged attention fixes; see Design an LLM Inference System.
"How many users can one GPU serve?" has a precise answer: free memory after weights, divided by KV bytes per token times average sequence length. Say it as a formula, plug in numbers, and then mention what moves it: GQA, an FP8 KV cache (halves it), prefix caching (shares it), and shorter contexts.
Memory: Training
Training needs far more memory per parameter than inference, because it keeps gradients and optimizer state. With mixed-precision training and the Adam optimizer, the usual accounting is:
| Item | Bytes per parameter |
|---|---|
| BF16 weights (used in forward/backward) | 2 |
| BF16 gradients | 2 |
| FP32 master copy of weights | 4 |
| Adam first moment (FP32) | 4 |
| Adam second moment (FP32) | 4 |
| Total | 16 |
So full fine-tuning of an 8B model needs 8 × 16 = 128 GB before activations, and a 70B model needs 70 × 16 = 1,120 GB. Neither fits on one GPU. The standard fix is to shard this state across GPUs with FSDP or ZeRO: over 64 GPUs, the 70B model's 1,120 GB becomes 17.5 GB per GPU, leaving room for activations.
Activations (the intermediate values saved for the backward pass) scale with batch size × sequence length × hidden size × layers, and can exceed the parameter memory for long sequences. Activation checkpointing stores only some of them and recomputes the rest during the backward pass, trading about a third more compute for a large memory saving.
Parameter-efficient fine-tuning changes the picture completely. With LoRA, the base weights are frozen and only small low-rank matrices are trained. For Llama-3-8B, rank-16 adapters on all seven projection matrices in every layer add up to about 42M parameters. The trainable state is 42M × 16 bytes ≈ 0.7 GB, and the frozen base is 16 GB in BF16. That fits on a single 24-48 GB GPU. QLoRA stores the frozen base in 4 bits, so even a 70B model (about 38 GB in INT4, plus a few GB of adapter state and activations) can be fine-tuned on one 80 GB GPU. The trade-offs are covered in Design an LLM Fine-Tuning System.
Compute: FLOPs per Token
The workhorse approximations, for a dense transformer with N parameters:
- Inference: about 2N FLOPs per token. Each parameter takes part in one multiply and one add. An 8B model needs about 16 GFLOPs per token; a 70B model, about 140 GFLOPs.
- Training: about 6N FLOPs per token. 2N for the forward pass and about 4N for the backward pass (gradients with respect to both activations and weights).
For MoE models, use the active parameters: DeepSeek-V3 costs roughly 2 × 37B = 74 GFLOPs per token, not 2 × 671B.
The 2N rule ignores attention over the context. Per token, attention adds about 4 × layers × context length × model width FLOPs (computing scores against every cached key, then the weighted sum of values). For Llama-3-70B (80 layers, width 8,192) at an 8k context, that's 4 × 80 × 8,192 × 8,192 ≈ 21 GFLOPs, about 15% on top of the 140. At 128k context it's about 340 GFLOPs, more than the weights themselves. Long context is expensive in compute as well as memory.
Training Time
Total training compute is 6 × N × D, where D is the number of training tokens. Divide by the cluster's real throughput. Real throughput is peak FLOP/s times MFU (model FLOPs utilization), which is commonly 35-50% for well-tuned large training runs. We'll use 40%, so an H100 delivers about 0.4 × 990 ≈ 400 TFLOP/s.
Pre-training a 70B model on 15T tokens: 6 × 70 × 10^9 × 15 × 10^12 = 6.3 × 10^24 FLOPs. At 4 × 10^14 FLOP/s per GPU, that's 1.6 × 10^10 GPU-seconds, or about 4.4 million H100-hours. On 16,000 GPUs, roughly 1.6 × 10^10 ÷ 16,000 ≈ 1 million seconds, about 11-12 days if nothing goes wrong (something always does).
Fine-tuning an 8B model on 100M tokens: 6 × 8 × 10^9 × 10^8 = 4.8 × 10^18 FLOPs, ÷ 4 × 10^14 = 12,000 GPU-seconds, about 3.3 H100-hours. Fine-tuning is cheap in compute; the cost is usually data, evaluation and iteration. LoRA mostly saves memory, not FLOPs: the forward and backward passes still run through the whole model, and skipping the weight gradients for frozen matrices saves only around a third.
Throughput: Decode Is Memory-Bandwidth-Bound
LLM inference has two phases with opposite bottlenecks:
- Prefill processes the whole prompt in one pass. A 2,000-token prompt on an 8B model is 2 × 8 × 10^9 × 2,000 = 3.2 × 10^13 FLOPs. Many tokens share each weight read, so this is compute-bound. At ~50% of an H100's peak (~500 TFLOP/s), it takes about 65 ms. That's most of the time to first token (TTFT).
- Decode generates one token per sequence per step. Each step must read every weight from memory, but does only 2 FLOPs per parameter per sequence. With one sequence, that's 2 FLOPs per 2 bytes read, 1 FLOP per byte, far below the ridge point of ~295. Decode is memory-bandwidth-bound.
So a single sequence's decode speed is bounded by weight bytes ÷ bandwidth:
- 8B in BF16 on one H100: 16 GB ÷ 3.35 TB/s ≈ 4.8 ms per token, a ceiling of about 210 tokens per second.
- 70B in BF16 on four H100s: 140 GB ÷ 13.4 TB/s ≈ 10.4 ms per token, about 96 tokens per second.
- 70B in FP8 on two H100s: 70 GB ÷ 6.7 TB/s ≈ 10.4 ms again, with half the GPUs.
Real engines reach maybe 60-80% of peak bandwidth, so real numbers are somewhat lower.
What Batching Buys
Because the weights are read once per step no matter how many sequences are in the batch, batching many sequences into one step multiplies throughput almost for free, until the KV cache reads catch up. Each sequence's step also reads its own KV cache: batch × context × KV bytes per token. Here's Llama-3-8B on one H100 with a 2,000-token average context (KV is 2,000 × 128 KB ≈ 0.26 GB per sequence), assuming the full 3.35 TB/s:
| Batch | Bytes read per step | Step time | Total tokens/s | Tokens/s per user |
|---|---|---|---|---|
| 1 | 16 + 0.26 ≈ 16.3 GB | 4.9 ms | ~210 | ~210 |
| 16 | 16 + 4.2 ≈ 20.2 GB | 6.0 ms | ~2,650 | ~165 |
| 64 | 16 + 16.8 ≈ 32.8 GB | 9.8 ms | ~6,500 | ~100 |
| 200 | 16 + 52.4 ≈ 68.4 GB | 20.4 ms | ~9,800 | ~49 |
Is the batch-200 step compute-bound yet? It does 2 × 8 × 10^9 × 200 = 3.2 × 10^12 FLOPs, about 3 ms at peak, against 20 ms of memory reads. Still firmly bandwidth-bound. And batch 200 is about the KV cache limit we computed earlier (54 GB ÷ 0.26 GB ≈ 206 sequences). Attention over the KV cache does only a few FLOPs per byte read, so adding sequences adds bandwidth demand nearly linearly. For typical context lengths, decode stays bandwidth-bound at any batch size that fits.
The table shows the central trade-off of LLM serving: bigger batches give more total throughput (cheaper per token) and slower per-user speed. You choose a point on that curve from your latency target. Humans read at roughly 4-5 words, or 5-7 tokens, per second, so 30-50 tokens per second per user already feels fast for chat, while agents and code generation benefit from more.
Say "decode is memory-bandwidth-bound" early and back it with arithmetic: one decode step reads all the weights for only 2 FLOPs per parameter, so step time ≈ (weight bytes + KV bytes) ÷ bandwidth. Nearly every LLM serving optimization (batching, quantization, speculative decoding, paged attention) follows from that one line.
Budgeting a Fleet in Tokens per Second
Fleet sizing works backwards from traffic:
- Output tokens per second = requests per second × average output tokens. This drives decode GPUs.
- Input tokens per second = requests per second × average input tokens. This drives prefill compute.
- Per-GPU capacity at your latency target, from the table above, derated for real-world efficiency.
- Check concurrency with Little's law: concurrent streams = request rate × time per request. They must fit in KV memory.
- Add headroom (often 30%+) for peaks, failures and deploys.
Worked example. A chat feature on an 8B model peaks at 2,000 requests per second, with 1,600 input tokens and 400 output tokens on average, so contexts top out near 2,000 tokens. Users should see at least ~30 tokens per second.
- Output: 2,000 × 400 = 800,000 tokens/s.
- Input: 2,000 × 1,600 = 3.2M tokens/s.
- Decode capacity: the batch-200 point gives 9,800 tokens/s and 49 tokens/s per user in theory. Derate to ~70%: about 6,800 tokens/s per GPU and ~34 tokens/s per user, which meets the target. Decode needs 800,000 ÷ 6,800 ≈ 118 GPUs.
- Prefill: 3.2M tokens/s × 16 GFLOPs ≈ 5.1 × 10^16 FLOP/s. At ~500 TFLOP/s effective per H100, that's another ~100 GPUs' worth of compute.
- Concurrency check: each request decodes for about 400 ÷ 34 ≈ 12 s, so there are about 2,000 × 12 = 24,000 live streams. Spread over 118 decode GPUs, that's ~200 each, right at the KV limit. If we wanted longer contexts, KV memory, not compute, would force more GPUs.
- Total: about 220 GPUs, or ~290 H100s with 30% headroom.
At $2.50 per GPU-hour, that's 290 × $2.50 × 730 hours ≈ $530,000 a month if provisioned for peak around the clock. Autoscaling with the daily traffic curve, or running batch work in the troughs, can cut that substantially. The architecture that makes this fleet efficient, including continuous batching and separating prefill from decode, is in Design an LLM Inference System.
Cost per million tokens is the number to compare against API prices. One H100 at $2.50 an hour producing 6,800 output tokens per second makes 6,800 × 3,600 ≈ 24.5M tokens an hour, about $0.10 per million output tokens at full utilization (prefill on top). For the 70B model, a 4-GPU replica at ~4,000 output tokens per second costs $10 an hour for 14.4M tokens, about $0.70 per million. Halve utilization and both numbers double.
Multi-GPU Deployment
When a model doesn't fit on one GPU, or one GPU is too slow, we split it. Three ways, and they combine:
- Tensor parallelism (TP) splits every weight matrix across GPUs. Each GPU holds 1/n of every layer, and the GPUs exchange partial results with an all-reduce twice per layer. It cuts per-token latency (each GPU reads only 1/n of the weights) but communicates constantly, so it stays inside one NVLink node, typically TP = 2, 4 or 8.
- Pipeline parallelism (PP) splits the layers into stages on different GPUs or nodes. Only activations cross stage boundaries, once per stage, so it tolerates slower links between nodes. It doesn't reduce per-token latency, and it needs several batches in flight to keep every stage busy.
- Data parallelism (DP), for serving, just means more replicas behind a load balancer. It scales throughput, not latency or capacity per replica.
How much does TP communicate? For the 70B model at a decode batch of 200, each all-reduce moves 200 tokens × 8,192 width × 2 bytes ≈ 3.3 MB. A ring all-reduce over 4 GPUs sends about 2 × (4 − 1) ÷ 4 = 1.5× that per GPU, ~4.9 MB, and there are 2 × 80 = 160 of them per step: about 790 MB per GPU per step. Over NVLink at ~450 GB/s each way, that's under 2 ms, plus a few microseconds of latency per call. Over a 50 GB/s network link it would be 16 ms per step, comparable to the whole step. That's why TP stays inside the node and PP crosses nodes.
Common layouts, with room for KV cache (assuming ~90% of memory usable and a few percent for activations):
| Model | Precision | Weights | Layout | Approx. KV room |
|---|---|---|---|---|
| 8B | FP8 | 8 GB | 1 × L4 (24 GB) | ~12 GB, ~90k tokens |
| 8B | BF16 | 16 GB | 1 × H100 | ~54 GB, ~410k tokens |
| 70B | FP8 | 70 GB | 2 × H100 (TP 2) | ~65 GB, ~200k tokens |
| 70B | BF16 | 140 GB | 4 × H100 (TP 4) | ~150 GB, ~500k tokens |
| 405B | FP8 | 405 GB | 8 × H100 (TP 8) | ~150 GB, ~300k tokens |
| 405B | BF16 | 810 GB | 8 × H200 (TP 8), or 2 nodes of 8 × H100 (TP 8, PP 2) | ~190 GB on H200 |
The rule: use the smallest TP degree that fits the weights plus enough KV cache for your batch, then add replicas for throughput. More TP than needed buys a little latency and costs communication overhead. MoE models add expert parallelism, which places different experts on different GPUs and routes each token to the GPUs holding its experts.
For training, the same three ideas combine as 3D parallelism, and data parallelism means synchronizing gradients rather than adding independent replicas. The details are in Inference Optimization and Distributed Training.
Self-Hosting Costs Versus an API
GPU prices move, so treat these as rough ranges, not quotes:
- H100: roughly $2-4 per GPU-hour from specialized GPU clouds, often more on demand from the largest clouds, less on long reserved contracts.
- A100: roughly $1-2 per GPU-hour.
- L4: well under $1 per GPU-hour.
Over a month (730 hours), one H100 at $2.50 is about $1,800; an 8-GPU node about $14,600.
The self-hosting question comes down to utilization. An API provider charges per token and runs its GPUs hot across many customers. Your own fleet costs the same per hour whether it's busy or idle. A rough break-even:
self-hosted cost per 1M tokens = GPU $/hour ÷ (tokens/s per GPU × 3,600 ÷ 1,000,000) ÷ utilization
For the 8B model at 6,800 output tokens per second and $2.50 an hour: $0.10 per million at 100% utilization, $0.20 at 50%, $0.50 at 20%. Compare that with the price of a hosted model of similar quality, and remember the hidden costs: engineers to run the serving stack, on-call, capacity planning, model upgrades, and evaluation. A few engineers can cost more than a small GPU fleet.
Self-hosting tends to win when traffic is large and steady, when data can't leave your environment, when you need a fine-tuned or pinned model the providers don't offer, or when latency requirements need GPUs close to your service. APIs win for spiky or small traffic, for the strongest frontier models, and for moving fast. MLOps and LLMOps works a full comparison, including when a small trained model beats both.
Other Handy Numbers
- Tokens and words: English text runs about 0.75 words per token, so 1,000 words ≈ 1,300 tokens and a dense page ≈ 600-700 tokens. Code and non-English text usually take more tokens per character.
- Embeddings: 100M vectors × 768 dimensions × 4 bytes (FP32) = 307 GB. FP16 halves it (154 GB), int8 quarters it (77 GB), and product quantization to 64 bytes per vector gives 6.4 GB. This is what decides whether a vector index fits in RAM; see Vector Databases.
- Embedding throughput: a ~100M-parameter encoder costs 2 × 100M = 0.2 GFLOPs per token. Embedding 1B tokens is 2 × 10^17 FLOPs, about 7 minutes on one H100 at ~500 TFLOP/s, or an hour or two on an L4.
- Model load time: 140 GB of weights from local NVMe at ~5 GB/s takes ~30 s; from object storage it can take minutes. That's why LLM autoscaling reacts in minutes, and why fleets keep warm capacity or cache weights on local disk.
- Checkpoints: full training state is ~16 bytes per parameter, so a 70B checkpoint with optimizer state is ~1.1 TB. Writing it at 10 GB/s takes almost 2 minutes, which is why large jobs checkpoint asynchronously.
- Classic ML serving: a GBDT scores one item in microseconds on a CPU core; a Redis lookup inside a data center takes well under a millisecond; a feature-store fetch is usually budgeted at single-digit milliseconds at p99.
- Network: round trip inside a data center ~0.5 ms; across availability zones ~1-2 ms; across a continent tens of ms. A streaming LLM response doesn't care much, but a 30-call agent loop does.
Numbers in an Interview
The Formulas to Have Ready
- Weights: params × bytes (2 for BF16, 1 for FP8).
- KV per token: 2 × layers × KV heads × head dim × bytes.
- Concurrent sequences: free memory ÷ (KV per token × average length).
- FLOPs: 2N per token for inference, 6N per token for training; training time = 6ND ÷ (GPUs × peak × MFU).
- Decode step time: (weight bytes + batch × context × KV per token) ÷ bandwidth.
- Prefill time: 2N × prompt tokens ÷ effective FLOP/s.
- Fleet: output tokens/s ÷ per-GPU decode throughput, plus prefill FLOPs ÷ effective FLOP/s, plus headroom; check concurrency with Little's law.
- Cost per million tokens: $/hour ÷ millions of tokens per hour ÷ utilization.
Write the three or four numbers your design depends on in a corner of the whiteboard (model size, KV per token, tokens per second per GPU, GPU count) and refer back to them. When the interviewer changes an assumption ("what if contexts are 32k?"), you can update the answer in seconds, which is exactly the skill being tested.
Common Follow-ups
- "Will it fit?" Weights plus KV for the target batch plus a few GB of overhead, against memory per GPU times TP degree.
- "Why is the GPU at 20% utilization during decode?" It's waiting on memory. Increase the batch, quantize weights, or use speculative decoding.
- "What happens if context length goes from 2k to 32k?" KV per sequence goes up 16×, so concurrency per GPU drops roughly 16× and decode steps get slower. Attention compute also grows. Expect to need many more GPUs, or KV quantization and prefix caching.
- "How long would it take to fine-tune?" 6 × params × tokens ÷ (GPUs × ~400 TFLOP/s on H100s).
- "Should we self-host?" Cost per million tokens at your realistic utilization, against the API price, plus the people cost.
Summary
A few hardware facts carry most ML infrastructure arithmetic: an H100 holds 80 GB, reads it at about 3.35 TB/s and computes about 990 TFLOP/s in BF16, so anything doing fewer than ~295 FLOPs per byte is limited by memory bandwidth. Weights cost 2 bytes per parameter in BF16; the KV cache costs 2 × layers × KV heads × head dim × 2 bytes per token, and it, not compute, usually limits concurrency. Training state costs about 16 bytes per parameter with Adam, so it must be sharded, while LoRA and QLoRA shrink it dramatically.
Inference costs about 2N FLOPs per token and training about 6N. Prefill is compute-bound; decode reads every weight for every step and is bandwidth-bound, so batching sets the trade-off between total throughput and per-user speed. Size fleets from output and input tokens per second, check concurrency against KV memory, keep tensor parallelism inside an NVLink node, and compare self-hosting with APIs as cost per million tokens at realistic utilization. With those formulas, most "how many GPUs" questions take two minutes.