Yashotantra Academy logo
level 1
Curious · 0 XP
streak
0d
perfect
0
badges
0

100 XP to Apprentice

Serving · hard

12. Serving economics: quantisation, batching, KV cache

Throughput and cost come from memory, not magic.

1 min read4 questionsup to 50 XPtopic 12/12

Read in another language

AI translates the explanation and quiz text while preserving code and answer scoring.

Self-hosting an LLM is a memory problem. Weights plus KV cache must fit in GPU VRAM.

- Weights: ~2 bytes/param at FP16. A 70B model ≈ 140 GB — hence quantisation to INT8/INT4 (AWQ, GPTQ, or FP8 on modern accelerators), roughly halving or quartering that. - KV cache: grows linearly with (batch × sequence length × layers × heads). It usually dominates at long context. PagedAttention (vLLM) allocates it in pages to stop fragmentation waste. - Continuous batching: new requests join the running batch each step rather than waiting for a full batch — the single biggest throughput win in real serving. - Speculative decoding: a small draft model proposes tokens, the big model verifies several at once, cutting latency for accepted spans.

bash
vllm serve meta-llama/Llama-3.3-70B-Instruct \
  --quantization awq --max-model-len 32768 \
  --gpu-memory-utilization 0.92 --enable-prefix-caching

Measure TTFT (time to first token, prefill-bound) and TPOT (time per output token, bandwidth-bound) separately — they have different fixes.

Gotcha: aggressive 4-bit quantisation can quietly degrade reasoning and long-context recall. Re-run your evals after any quantisation change.

How to study this topic

  1. 1. Read the explanation once end to end, skipping the code.
  2. 2. Re-read the code snippets and say out loud what each line does.
  3. 3. Answer the quiz without scrolling back — that is the real check.
  4. 4. Read every explanation, even for the answers you got right.

Scoring

  • · Up to 30 XP from quiz accuracy.
  • · +15 XP for a perfect first attempt.
  • · +5 XP while a 3-day streak is running.
  • · 75% or higher marks the topic complete.

Check your understanding

  1. 1. Which serving technique most improves GPU throughput under mixed traffic?

  2. 2. What does PagedAttention solve?

  3. 3. TTFT is dominated by which phase?

  4. 4. What must follow any quantisation change?

Badges

First light
Pass your first topic
Sharp shooter
3 perfect first-try quizzes
On a roll
Study 3 days in a row
Week warrior
Study 7 days in a row
Grinder
Earn 500 XP
Deep diver
Earn 1500 XP