5.3.18 · HinglishMLOps & Deployment

LLM serving (vLLM, quantized inference)

2,082 words9 min readRead in English

5.3.18 · AI-ML › MLOps & Deployment


LLMs serve karna mushkil kyun hai

KV cache kya hai? Attention mein, query ke liye output ko saare pichle tokens ki Keys aur Values chahiye. Har step pe unhe recompute karna wasted work hai, isliye hum unhe cache karte hain. Wahi cache memory hog hai.


Puraana tarika memory waste karta tha (woh problem jo vLLM solve karta hai)

Figure — LLM serving (vLLM, quantized inference)

Throughput kyun jump karta hai: kam wasted memory → bada batch GPU pe fit hota hai → decode step zyada requests per weight-read process karta hai → higher tokens/sec. vLLM naive HF generate ke muqable mein ~24× throughput tak report karta hai.


Quantized inference — weights ko chhota karna


Common galtiyan


Flashcards

LLM inference ke do phases kya hain aur kaunsa memory-bound hai?
Prefill (prompt process karo, compute-bound) aur Decode (ek token at a time, memory-bound).
KV cache kyun exist karta hai?
Har decode step pe saare past tokens ki Keys/Values recompute karne se bachne ke liye; memory ke badle compute trade karta hai.
KV cache size bytes mein formula.
(2 for K aur V, p = bytes/element).
PagedAttention kaun sa OS concept use karta hai?
Virtual memory / paging — non-contiguous fixed-size blocks jo ek block table ke zariye map hote hain (page table analogy).
Naive KV allocation mein memory waste ke do types?
Internal fragmentation (reserved > used) aur external fragmentation (free memory contiguous nahi).
Continuous batching kya hai?
Har step pe nayi requests inject karna aur finished ones evict karna taaki GPU kabhi padding pe idle na rahe.
Affine quantization scale formula.
.
Zero-point formula.
, woh integer jo real 0 se map karta hai.
W4A16 ka matlab kya hai?
Weights INT4 mein, activations FP16 mein (weight-only quantization).
Weight-only INT4 decode speed up kyun karta hai lekin necessarily prefill nahi?
Decode memory-bound hai (chhote HBM read se fayda); prefill compute-bound hai aur dequant-to-FP16 overhead dominate kar sakta hai.
GPTQ aur AWQ mein kya farq hai?
GPTQ Hessian info use karke layer output error minimize karta hai; AWQ un salient weight channels ko protect karta hai jo activation magnitude se choose kiye jaate hain.
PagedAttention ke under per-request maximum waste?
Zyada se zyada block_size − 1 tokens (partially filled tail block).
INT4 error INT8 se sirf 2× nahi balki bahut zyada kyun hai?
Step ; 15 vs 255 levels → ~17× bada step.

Recall Feynman: 12 saal ke bachche ko samjhao

Socho AI ek ek word likh kar sentence bana raha hai. Har agla word choose karne ke liye woh conversation ki poori memory dobara padhta hai. Woh memory (the KV cache) sticky notes ki tarah hai — ek har word ke liye. Purane programs har user ke liye ek bada khaali drawer pakad lete the "bas aise hi," to zyaatar drawers zyaatar khaali rehte the aur desk jaldi bhar jaati thi. vLLM ki jagah chhote barabar boxes use karta hai aur ek tabhi deta hai jab note ko actually ghar chahiye — koi wasted space nahi, to bahut zyada users desk share kar sakte hain. Quantization AI ke dimag (uske numbers) ko shorthand mein likhne jaisi hai: lambe precise numbers ki jagah chhote rounded ones use karo. Thoda kam exact hai lekin unhe bahut jaldi flip kar sakte ho aur zyada le ja sakte ho.

Connections

  • Attention Mechanism — KV cache directly self-attention ke K/V se aata hai.
  • GPU Memory & HBM Bandwidth — kyun decode memory-bound hai.
  • Quantization Fundamentals — affine map, scale/zero-point.
  • GPTQ and AWQ — 4-bit weights ke liye PTQ algorithms.
  • Batching Strategies — static vs continuous/in-flight batching.
  • Model Sharding & Tensor Parallelism — large models fit karne ka complementary tarika.
  • Throughput vs Latency Tradeoffs — kaunse serving metrics optimize karte ho.

Concept Map

is

two costs

two costs

reads

reads

compute-bound

size

grows with

causes

solved by

uses

reduced by

LLM Serving

Memory-bound not compute-bound

KV Cache

Weight Memory

Decode phase

Prefill phase

2 · B · S · L · d_model · p

Sequence length and batch

Memory fragmentation 60-80% waste

PagedAttention in vLLM

Fixed-size blocks + block table

Quantization INT8/INT4