← All courses ← Course home

Lesson 09 of 12 · Phase 5 Inference

vLLM internals and production serving

Serving is batching, KV cache, and tensor parallel. Read PagedAttention as an operator, then serve your small checkpoint.

Agent brief (llms.md)

Serving is where tokens become latency and money. PagedAttention and vLLM are the names to know. The idea: the KV cache is a paged block table, like virtual memory, so you can pack many sequences without giant contiguous reservations. Continuous batching adds new requests as others finish. Tensor parallel splits weights across GPUs when one GPU cannot hold the model.

Throughput and latency fight. A huge batch raises tokens per second and first-token wait. Prefix sharing and cache reuse help when many prompts overlap. You will measure both, not pick a slogan.

Coding: serve a replica


python -m vllm.entrypoints.openai.api_server \
  --model ./checkpoints/tiny-lm \
  --max-model-len 2048 \
  --tensor-parallel-size 1

from openai import OpenAI

client = OpenAI(base_url="http://127.0.0.1:8000/v1", api_key="not-needed")
resp = client.chat.completions.create(
    model="tiny-lm",
    messages=[{"role": "user", "content": "Say one honest sentence about KV cache."}],
    max_tokens=64,
    temperature=0.2,
)
print(resp.choices[0].message.content)
print(resp.usage)

If vLLM will not load a 10M toy because of a converter gap, serve with a Hugging Face generate loop and still write the same measurements: time to first token, inter-token latency, and tokens per second at batch 1 and batch 8. The replica is the log, not the logo.

What you must be able to explain

Assignment

Opinion checkpoint

Write this down. If you cannot estimate KV bytes, you cannot size a GPU. vLLM is not a personality. PagedAttention is a memory allocator for attention state.

Core project 7 starts: an OpenAI-compatible vLLM server and a latency log.

Next: Triton and hand-rolled kernels.

Key concepts

  • PagedAttention treats KV cache like virtual memory pages.
  • Prefill and decode have different bottlenecks.
  • Tensor parallel splits weights. Batching splits time.
  • Throughput and latency are a pair you measure together.

Takeaways

  • Serve something and log TTFT plus inter-token time.
  • Estimate KV bytes before you talk about GPU size.
  • Name PagedAttention/vLLM as the serving replica, not as hype.