Cheat sheets

LLM Serving with vLLM

Install, start, size, tune and debug a vLLM 0.31.0 server. Flags, defaults, metrics and known failures.

  • Concepts and terms
  • Tasks and commands
  • Annotated code
  • Diagrams
  • Defaults and numbers
  • Troubleshooting
  • Questions and tips

Source

Serving stack#

HTTPrequestsone stepallocatereadclientClientcurl or OpenAI SDKprocessAPI serverHTTP and tokenizerprocessEngine coreschedulergpuGPU workerweights and forwardpassstoreKV block pool16-token blocksstoreMetrics/metrics endpointHTTPrequestsone stepallocatereadclientClientcurl or OpenAI SDKprocessAPI serverHTTP and tokenizerprocessEngine coreschedulergpuGPU workerweights and forwardpassstoreKV block pool16-token blocksstoreMetrics/metrics endpoint

One request#

1Budgeteach step has a token budget set by--max-num-batched-tokens.2Running requestseach gets the tokens it needs, up to the budget.3Waiting requestsadmitted while budget and room remain.--max-num-seqs limits them.4Memory fulla running request is stopped and computed againlater.

Start the server#

uv venv --python 3.12 --seedclean Python 3.12 environment
source .venv/bin/activateuse it in this shell
uv pip install vllm==0.31.0 --torch-backend=autopinned install
vllm serve Qwen/Qwen3-0.6B --reasoning-parser qwen3 2>&1 | tee server.logstart and keep a log
curl http://localhost:8000/v1/modelsrun in a second terminal

Tasks#

TaskCode
Install vLLM 0.31.0uv pip install vllm==0.31.0 --torch-backend=auto
Start a server with the reasoning parservllm serve Qwen/Qwen3-0.6B --reasoning-parser qwen3
Check the health routecurl -i http://localhost:8000/health
List the model namecurl http://localhost:8000/v1/models
Turn the thinking off for one request"chat_template_kwargs": {"enable_thinking": false}

Commands#

CommandWhat it does
vllm --versionPrints the installed version. It must read 0.31.0.
docker logsReads the log of the container that runs the server.
nvidia-smi --query-gpu=name,memory.total,driver_version --format=csvPrints the GPU name, memory and driver.

Defaults#

SettingDefaultNote
--hostevery network interfaceSet 127.0.0.1 for a local test
--port8000HTTP port of the server
--gpu-memory-utilization0.92Share of total GPU memory for one instance
--max-num-batched-tokens2048Under 70 GiB of GPU memory. 8192 from 70 GiB
--max-num-seqs256Under 70 GiB of GPU memory. 1024 from 70 GiB
--block-size16Tokens in one KV block
--kv-cache-dtypeautoModel data type. fp8 halves the bytes per token
-O0 to -O3-O2Compile and CUDA graph level

Key terms#

Prefix hash
a hash of a block and the block before it, so one hash names a whole prefix.
Preemption
vLLM stops a request to free its blocks and computes it again later.

Glossary#

API server
the process that serves HTTP, tokenizes and streams the answer.
Engine core
the process that runs the scheduler and the KV cache manager.
Block
a fixed group of 16 tokens in the KV cache.
Preemption
stopping a running request to free its blocks, then computing it again.

Tips#

  • Keep the log with tee server.log, and read the startup lines at every start.
  • On the pip path, install the CUDA toolkit before the first start.
  • Use the health route for liveness, and one real request for readiness.
  • Read the symptom section before you change a flag.

Troubleshooting#

SymptomCauseFix
Start stops about KV cache and maximum lengthOne request at --max-model-len needs more KV cache than is leftSet --max-model-len to your longest request
Start stops with nvcc missingFlashInfer compiles at first start and the host has no CUDA toolkitInstall the toolkit, set CUDA_HOME, and start again
Server crashes after an FP8 KV cacheThe FP8 cache selects FlashInfer, which cannot compile hereAdd --attention-backend TRITON_ATTN
Answer starts with a long thinking blockA reasoning model runs without a parserStart with --reasoning-parser qwen3
HTTP 400 about maximum context lengthPrompt tokens plus max_tokens exceed --max-model-lenSend a shorter prompt or a smaller max_tokens
Second benchmark run is fasterA fixed seed repeats prompts and the prefix cache serves themReset the prefix cache and use a new seed

Questions#

Does a 200 from /health prove a request completes?
No. The route does not generate a token.
Why is the answer empty with finish_reason set to length?
The thinking used all of max_tokens. Raise max_tokens or turn the thinking off.
Why does the scheduler serve decode first?
Each running request takes its tokens from the budget first, so the stream stays smooth.
Why are blocks not reserved per request?
No memory sits reserved for a length the request never reaches.