Pidoku

Your First Server, and How to Read Its Startup Log

Module 16 Lesson 16.b 40 min Difficulty 1/5

Prerequisites 16.a


Before you start: words you need#

WordPlain meaning
EndpointOne URL path on a server that does one job, such as /v1/chat/completions.
OpenAI-compatibleAccepting the same JSON requests and returning the same JSON answers as OpenAI’s API, so existing client code works unchanged.
WheelA ready-built Python package file (.whl) that pip or uv installs without compiling anything.
Profiling runA fake forward pass vLLM runs at startup, with the largest batch it will ever schedule, to measure peak memory.
CUDA graphA recorded sequence of GPU kernel launches that can be replayed with one call (5.f). vLLM records one per batch size at startup.
Server-sent events (SSE)A simple streaming format over HTTP: the server keeps the connection open and sends lines that start with data: .
Time to first token (TTFT)How long a client waits from sending a request until the first piece of the answer arrives.

1. What is it?#

vllm serve <model> is one command that downloads a model, loads it onto the GPU, measures how much memory is left, turns that leftover memory into KV cache blocks, compiles and warms up the model, and only then opens port 8000 with an OpenAI-compatible HTTP API.

The log it prints while doing this is not noise. It states the exact numbers the scheduler and the memory manager will use for the life of the process. Learn to read about ten lines of it and you can predict how the server will behave before you send a single request.

Everything here was checked against vLLM v0.32.0 (commit 5df63a7), the version Modules 16–19 read. Facts checked on 13 November 2026.

flowchart LR
  A[":i-terminal: <b>vllm serve</b><br/><small>parse flags, build config</small>"] --> B[":huggingface: <b>Download</b><br/><small>config, tokenizer, weights</small>"]
  B --> C[":pytorch: <b>Load weights</b><br/><small>onto the GPU</small>"]
  C --> D[":i-gauge: <b>Profile memory</b><br/><small>one dummy forward pass</small>"]
  D --> E[":i-layers: <b>Create KV cache</b><br/><small>leftover memory / block size</small>"]
  E --> F[":nvidia: <b>Compile + CUDA graphs</b><br/><small>warm up every batch shape</small>"]
  F --> G[":i-globe: <b>Listen on :8000</b><br/><small>OpenAI-compatible API</small>"]
  class A neutral
  class B io
  class C,E memory
  class D queue
  class F compute
  class G io

2. Why does it matter?#

Most problems people report with vLLM are visible in the first thirty seconds of its log:

  • “It only handles a few requests at once” — the KV cache line says how many tokens fit.
  • “It uses all my GPU memory while idle” — the memory budget is taken at startup, by design.
  • “Answers differ from what I get elsewhere” — the model’s own sampling defaults were applied.
  • “Startup takes minutes” — the compile and graph-capture lines say where the time went.

If you can read the log, you can answer these yourself instead of guessing. And every later lesson in Modules 16–19 explains a mechanism whose size was fixed by one of these lines.


3. Simple analogy#

A restaurant before opening. The manager reads the booking system (flags), receives the delivery (weights), checks how much fridge space is left after the stock is in (profiling), divides the remaining space into labelled shelves (KV cache blocks), runs the kitchen through every dish once so nobody fumbles at 8 p.m. (warm-up and CUDA graphs), and only then unlocks the door (port 8000). The opening checklist on the wall says how many tables the kitchen can serve. That checklist is the startup log.


4. Tiny example: install, start, ask#

Install with uv, which the project recommends because it picks the PyTorch build that matches your GPU driver:

Shell
uv venv --python 3.12 --seed
source .venv/bin/activate
uv pip install vllm --torch-backend=auto
vllm download-kernels      # optional: fetch precompiled kernels now, not at first startup

Start a server for a small model:

Shell
vllm serve Qwen/Qwen2.5-1.5B-Instruct

When the log says Starting vLLM server on http://0.0.0.0:8000, ask it something from another terminal:

Shell
curl http://localhost:8000/v1/chat/completions \
    -H "Content-Type: application/json" \
    -d '{
        "model": "Qwen/Qwen2.5-1.5B-Instruct",
        "messages": [{"role": "user", "content": "Name three uses of a GPU."}],
        "max_tokens": 64
    }'

That is the whole loop. The rest of this lesson explains what happened in between.


5. Technical explanation#

Installing on different machines#

Your machineWhat to install
Linux + NVIDIA GPUThe uv commands above. Supported Python: 3.11 to 3.14 (3.10 was dropped in v0.32.0).
Linux + AMD GPUuv pip install vllm --extra-index-url https://wheels.vllm.ai/rocm/ (the docs list Python 3.12, ROCm 7.0, glibc 2.35 or newer)
Linux, CPU onlyThe +cpu wheel attached to each GitHub release, installed with --torch-backend cpu
Google TPUA separate package, vllm-tpu
Apple SiliconA separate project, vllm-metal, which uses Apple’s MLX instead of PyTorch and needs MLX-format models
Dockervllm/vllm-openai:latest; the image’s entry point is vllm serve, so arguments after the image name are serve arguments

vllm download-kernels installs precompiled FlashInfer kernels. Without it, vLLM downloads or compiles them at first startup, which the docs say can add several minutes on Hopper and newer GPUs.

With Docker:

Shell
docker run --rm --gpus all \
    -v ~/.cache/huggingface:/root/.cache/huggingface \
    -v vllm-cache:/root/.cache/vllm \
    -p 8000:8000 --ipc=host \
    vllm/vllm-openai:latest \
    Qwen/Qwen2.5-1.5B-Instruct

--ipc=host (or a large --shm-size) matters: vLLM’s processes share data through shared memory, and Docker’s default 64 MB shared-memory segment is too small. The second -v keeps the torch.compile cache (~/.cache/vllm) between containers, so the second start skips most of the compile time.

Starting it#

One process serves one model. The address defaults to port 8000 on all interfaces; --host, --port and --uds (a Unix socket path, which makes host and port ignored) change it.

--api-key (or the VLLM_API_KEY environment variable) turns on a bearer-token check. Several keys may be given, so one can be rotated out. Read the flag’s own warning: it protects only some path prefixes, and other paths on the same port, including one that runs inference, stay open (details in 16.e). Do not rely on the key alone; put the server behind a gateway (21.g).

The vllm command has more than serve:

CommandPurpose
vllm serveThe HTTP server. Modules 16–19 are mostly about what it starts.
vllm chat, vllm completeA terminal client for a running server
vllm bench latency / throughput / serve / startup / sweepBuilt-in load generators (19.d)
vllm run-batchProcess a file of requests offline, in the OpenAI batch format
vllm launch renderA GPU-less server that only tokenises and applies chat templates
vllm preloadStart one daemon per GPU that holds the model’s weights in GPU memory; a later vllm serve --load-format ipc_cache maps them instead of reading from disk
vllm snapshot create / inspect / restoreSave an initialised engine and restore it later, to cut cold-start time
vllm download-kernelsInstall precompiled attention kernels
vllm collect-envPrint versions for a bug report

vllm serve --help=all prints every flag, --help=max-model-len prints one (dashes or underscores both work), and --help=ModelConfig prints one group.

Reading the startup log#

The lines below are the ones that carry numbers. The wording is copied from the v0.32.0 source; the values are worked out for this model (28 layers, 2 KV heads of 128 dimensions, BF16) on a 24 GiB GPU.

non-default args: {'model': 'Qwen/Qwen2.5-1.5B-Instruct'}
Initializing a V1 LLM engine (v0.32.0) with config: model='Qwen/Qwen2.5-1.5B-Instruct', ...
Chunked prefill is enabled with max_num_batched_tokens=2048.
Using max model len 32768
Loading weights took 1.42 seconds
Model loading took 2.89 GiB memory and 2.310482 seconds
Available KV cache memory: 18.4 GiB
GPU KV cache size: 689,056 tokens, Maximum concurrency for 32,768 tokens per request: 21.03x
Graph capturing finished in 9 secs, took 0.31 GiB
init engine (profile, create kv cache, warmup model) took 14.87 s (compilation: 6.12 s)
Starting vLLM server on http://0.0.0.0:8000
LineWhat it meansWhat to do with it
non-default argsEvery flag that differs from the default. API keys and other secrets are shown as ***.Paste this into bug reports. It is the reproducible configuration.
Initializing a V1 LLM engineThe engine process has started and prints the whole resolved configuration.Search it for the real value of any flag you are unsure about.
Chunked prefill is enabled with max_num_batched_tokens=…The token budget per step: the most tokens the scheduler hands the GPU in one forward pass (17.b).The default depends on the GPU: 2,048 here, 8,192 on an H100 or H200, 16,384 on a B200.
Using max model lenThe longest prompt plus answer one request may have. Read from the model’s config unless you pass --max-model-len.Lowering it raises the “maximum concurrency” number below.
Model loading took … GiBMemory the weights occupy.Subtract it from the budget to estimate what is left.
Available KV cache memoryWhat remains of the budget after weights, peak activation memory and the CUDA-graph estimate.This number divided by bytes per block is the size of the block pool (17.h).
GPU KV cache size: N tokensThe block pool expressed in tokens.The total of all tokens, across all requests, that can be in flight at once.
Maximum concurrency for M tokens per request: XHow many requests could run if every one used the full M tokens.A worst-case floor, not a limit. Real requests are shorter, so real concurrency is higher.
Graph capturing finishedCUDA graphs were recorded for a set of batch sizes (18.d).Part of startup time, and a little memory.
init engine … tookTotal time for profiling, cache creation and warm-up, with compile time in brackets when there was any.The floor on your cold-start time, on top of download and weight loading.

important

The budget is --gpu-memory-utilization, which defaults to 0.92 of the GPU’s total memory. vLLM takes that share at startup and keeps it. A vLLM process showing 22 GiB used on a 24 GiB card while idle is working as designed: the blocks are allocated up front so that no allocation happens while serving.

Where the capacity numbers come from#

The two capacity numbers are computed together in update_kv_cache_capacity() in vllm/v1/core/kv_cache_utils.py. For this model, one token’s KV cache is

2 (K and V) × 28 layers × 2 KV heads × 128 dims × 2 bytes = 28,672 bytes = 28 KiB

so one 16-token block is 448 KiB. 18.4 GiB of KV memory holds 43,066 blocks. A request at the full 32,768 tokens needs 2,048 blocks, so 43,066 / 2,048 = 21.03 such requests fit. The token figure is that concurrency times the maximum length: 21.03 × 32,768 ≈ 689,056 tokens. Models with several kinds of layer (sliding-window plus full attention, for example) count blocks per group, which is why the source computes concurrency first (17.i).

Talking to it#

The API is OpenAI’s. Anything that can call OpenAI can call vLLM by changing the base URL. The endpoints a text-generation server exposes:

PathWhat it is
/v1/chat/completionsMessages in, message out. Applies the model’s chat template.
/v1/completionsRaw text in, text out. No template.
/v1/responsesOpenAI’s Responses API
/v1/messagesAnthropic’s Messages API, served by the same engine
/v1/modelsThe model name and any loaded LoRA adapters
/tokenize, /detokenizeRun only the tokenizer
/healthReturns 200 while the engine is alive, 503 if it has died
/metricsPrometheus metrics (19.c)
/versionThe vLLM version

Embedding, scoring and speech models get their own endpoints (/v1/embeddings, /pooling, /score, /rerank, /classify, /v1/audio/transcriptions) when you serve a model of that kind.

note

By default (--generation-config auto) the server applies the sampling defaults in the model repository’s generation_config.json. If answers differ from what you expect at “default” settings, that file is usually why. Pass --generation-config vllm to ignore it.


6. Under the hood: two front doors to one engine#

The HTTP server is one of two ways into the same engine:

flowchart LR
  S[":i-globe: <b>vllm serve</b><br/><small>online: many clients, streaming</small>"] --> A[":vllm: <b>AsyncLLM</b>"]
  L[":python: <b>LLM class</b><br/><small>offline: a list of prompts</small>"] --> B[":vllm: <b>LLMEngine</b>"]
  A --> E[":vllm: <b>Engine core</b><br/><small>the same scheduler and workers</small>"]
  B --> E
  class S,L io
  class A,B queue
  class E compute

The LLM class (vllm/entrypoints/llm.py) is for batch jobs inside a Python script: give it ten thousand prompts and it returns ten thousand answers. It wraps LLMEngine (vllm/v1/engine/llm_engine.py); the server wraps AsyncLLM (vllm/v1/engine/async_llm.py, 16.f). Both talk to the same EngineCore (16.g).

The two get different defaults because a batch job cares only about throughput. The defaults are chosen in EngineArgs.get_batch_defaults() in vllm/engine/arg_utils.py from the GPU’s memory:

GPUToken budget, serverToken budget, LLM classMax sequences
160 GiB or more (B200, B300)16,38416,3841,024
70 GiB or more, not an A100 (H100, H200)8,19216,3841,024
Anything else (A100, L40S, L4, RTX)2,0488,192256

7. Performance implications#

  • Capacity is fixed at startup. GPU KV cache size does not change while serving. To hold more requests you need more memory for the cache: a shorter --max-model-len does not add tokens, but quantising weights or the KV cache (18.j) does.
  • The token budget trades latency for throughput. A bigger max_num_batched_tokens reads long prompts in fewer steps, but every step that carries a prompt chunk is slower for the requests already generating (17.b).
  • Startup time has three parts: download, weight loading, and init engine. The compile cache, vllm download-kernels, vllm preload and vllm snapshot each attack one of them.

8. Production implications#

  • Keep the non-default args line and the vLLM version from every deployment. They are the whole reproducible configuration.
  • If two processes share one GPU, each one’s --gpu-memory-utilization is a share of the total memory, so the shares must add up to less than 1.
  • Readiness: the port opens only after the engine is ready, and /health turns 503 if the engine dies. Use it for liveness probes (19.e).
  • Pin the image tag (vllm/vllm-openai:v0.32.0, not latest), because defaults change between releases.
  • --api-key is not a security boundary on its own; see above.

9. Common mistakes#

  1. Reading idle memory use as a leak. The block pool is allocated at startup.
  2. Treating “Maximum concurrency” as the limit. It assumes every request uses the full context; real concurrency is usually far higher.
  3. Forgetting --ipc=host in Docker. Multi-process and multi-GPU setups fail or hang with the default shared-memory size.
  4. Comparing outputs without --generation-config vllm. The model’s own sampling defaults are applied silently.
  5. Using latest images in production. A two-week release cycle changes defaults under you.
  6. Assuming --api-key protects every path. It covers a few path prefixes only (16.e).

10. Hands-on exercise#

This Go client streams a chat completion and measures time to first token and time per output token. It needs a running server (start one first; set VLLM_URL if it is not on localhost:8000). The response is server-sent events: lines beginning data: , each carrying a JSON chunk with the next piece of text, then a final chunk with token counts (because of include_usage) and data: [DONE].

Go
package main

import (
	"bufio"
	"bytes"
	"encoding/json"
	"fmt"
	"net/http"
	"os"
	"strings"
	"time"
)

type chunk struct {
	Choices []struct {
		Delta struct {
			Content string `json:"content"`
		} `json:"delta"`
		FinishReason *string `json:"finish_reason"`
	} `json:"choices"`
	Usage *struct {
		PromptTokens     int `json:"prompt_tokens"`
		CompletionTokens int `json:"completion_tokens"`
	} `json:"usage"`
}

func main() {
	base := "http://localhost:8000"
	if v := os.Getenv("VLLM_URL"); v != "" {
		base = v
	}
	body, _ := json.Marshal(map[string]any{
		"model":          "Qwen/Qwen2.5-1.5B-Instruct",
		"messages":       []map[string]string{{"role": "user", "content": "Explain a KV cache in two sentences."}},
		"max_tokens":     128,
		"stream":         true,
		"stream_options": map[string]bool{"include_usage": true},
	})

	start := time.Now()
	resp, err := http.Post(base+"/v1/chat/completions", "application/json", bytes.NewReader(body))
	if err != nil {
		fmt.Println("is the server running?", err)
		return
	}
	defer resp.Body.Close()

	var first time.Duration
	tokens := 0
	sc := bufio.NewScanner(resp.Body)
	for sc.Scan() {
		line := strings.TrimPrefix(sc.Text(), "data: ")
		if line == "" || line == "[DONE]" {
			continue
		}
		var c chunk
		if json.Unmarshal([]byte(line), &c) != nil {
			continue
		}
		if c.Usage != nil {
			tokens = c.Usage.CompletionTokens
		}
		if len(c.Choices) == 0 {
			continue
		}
		if first == 0 && c.Choices[0].Delta.Content != "" {
			first = time.Since(start)
		}
		fmt.Print(c.Choices[0].Delta.Content)
	}
	total := time.Since(start)

	fmt.Printf("\n\ntime to first token: %v\n", first.Round(time.Millisecond))
	fmt.Printf("total:               %v for %d tokens\n", total.Round(time.Millisecond), tokens)
	if tokens > 1 {
		fmt.Printf("per token after the first: %v\n",
			((total - first) / time.Duration(tokens-1)).Round(time.Microsecond))
	}
}

The two numbers it prints are the two that matter for an interactive client: time to first token (queueing plus reading the prompt) and time per output token (one decode step). Every later lesson explains a mechanism that moves one or both.

  1. Start the server twice, once with --max-model-len 4096 and once with --max-model-len 32768. The KV cache size in tokens is the same both times. Why does the maximum concurrency change by a factor of eight?
  2. Start it with --gpu-memory-utilization 0.5. Compare Available KV cache memory with the default run. Is it half? Explain the difference using the weights’ memory.
  3. Run the Go client three times with the same prompt. The time to first token usually drops after the first run. Form a guess about why; the answer is in 17.f.
  4. Work out GPU KV cache size for a model you use from its config.json (layers, KV heads, head dimension), the same way as section 5. Start the server and compare.

11. Interview questions#

  1. Which startup line tells you the scheduler’s token budget per step, and why does its default differ between an L4 and an H100?
  2. An idle vLLM process holds most of the GPU’s memory. Is something wrong?
  3. How is Maximum concurrency computed, and why is it a floor rather than a ceiling?
  4. What is the difference between /v1/chat/completions and /v1/completions?
  5. Why might the same prompt at “default settings” give different answers on vLLM and another server?
  6. What does --api-key protect, and what does it not?

12. Further reading#

Checked on 13 November 2026, against the v0.32.0 tag.

↑↓ navigate↵ openesc close

100% drag to pan · scroll or pinch to zoom · double-click to zoom in