Free preview

Cheat Sheet

Key takeaway

Three shifts from classic estimation: the unit is the token, the binding resource is GPU memory, and cost is a first-order constraint. Everything else is classic capacity planning underneath.

The formulas

Weight memory      =  parameters x bytes per parameter
                      (FP16 -> 2 x param count, in GB)

KV per token       =  2 x layers x kv_heads x head_dim x bytes

Cache per request  =  KV per token x context length

Max concurrency    =  free memory / cache per request

Conversation cost  =  t x N x (N + 1) / 2   ~=  t x N^2 / 2

Vector storage     =  vectors x dimensions x bytes
Index in memory    =  raw x 1.5 to 2        (HNSW graph overhead)

Training FLOPs     =  6 x N x D             (2N forward, 4N backward)
Inference FLOPs    =  2 x N per token

Concurrency        =  rate x duration       (Little's law)

Anchors

QuantityValue
FP16 / BF162 bytes per parameter
INT81 byte per parameter
Accelerator memory~80 GB
Tokens per word~1.3 (≈ 4 chars per token)
Tokens per page~500
Default embedding dims768 (large: 1,536)
One float32 value4 bytes
Decode, 7B class~50–100 tok/sec single, ~2,000 batched
Human reading speed~5 tok/sec
Model tier price spread10–30×
Output vs input price3–5×
Chinchilla ratio~20 tokens per parameter
GPU hourly cost~$2

Does it fit?

ModelFP16One 80GB card?
7B14 GBYes, ~61 GB left for cache
13B26 GBYes
34B68 GBBarely — no cache room
70B140 GBNo — 2+ with tensor parallelism

Tensor parallel inside a node, pipeline parallel across nodes.

Context length is the biggest lever on fleet size

Long context is a fleet-sizing decision, not a feature toggle. Route the few requests that need it to a separate pool.

Prefill vs decode

PrefillDecode
ParallelismWhole prompt at onceOne token at a time
Bound byComputeMemory bandwidth
SetsTime to first tokenTokens per second
Batching helpsBarely — already saturatedEnormously — weight read amortised

Continuous batching schedules per iteration, so a finished request frees its slot immediately. Paged cache recovers the 60–80% that contiguous reservation wastes. Colocated phases mean a long prompt stalls everyone — fix with chunked prefill, or disaggregate at scale and pay the cache transfer.

Vector index

MethodSize vs float32Recall cost
float161/2Negligible
int8 (scalar)~1/4Small — the default
int4~1/8Moderate
Product quantisation~1/10 or lessReal — pair with rerank

Count chunks, not documents (10–20× multiplier). Past ~100M vectors, in-memory stops being economical — shard first if the corpus partitions, disk-based only if it does not. Changing embedding model invalidates every vector: treat the choice as semi-permanent.

The adaptation ladder

Serving cost is paid forever; training is paid once. At equal quality, take the smaller model.

Cost levers, ranked

  1. Route by difficulty — attacks price per token; tier spread is 10–30×
  2. Cap or summarise history — attacks the quadratic; the only lever that compounds
  3. Cache — exact, semantic (watch the threshold), and prompt-prefix
  4. Trim retrieved context — direct quality trade
  5. Batch — buys throughput, spends latency

Where the money goes: generation 70–85%, embedding 5–10%, vector search 5–10%. Optimise generation.

Build vs buy is decided by average utilisation, not volume — a GPU costs the same idle. Colocating a batch workload with an interactive one can move the break-even on its own.

Quick decision cues

  • Asked to size a generative system → tokens, split prompt and completion
  • Multi-turn → quadratic, t × N² / 2
  • Self-hosted model → does it fit on one card, and what is left for cache
  • "Support 128K context" → that is a fleet-sizing question; ask what fraction needs it
  • Sizing a fleet → compute memory bound AND throughput bound, take the larger
  • Concurrency → Little's law: rate × duration
  • "One million documents" → ask the chunking strategy first
  • Index too big → quantise, then shard, then disk
  • "Should we fine-tune?" → is the gap knowledge or behaviour?
  • Cost too high → route first, cap history second

Enjoying the preview?

Create a free account to unlock the rest of this course, the in-browser judge, and live AI mock interviews.

Sign up free to continue