vllm-server
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChinesevLLM Server Management
vLLM 服务器管理
Deploy production-grade LLM inference servers with vLLM — the fastest open-source LLM serving engine with PagedAttention and continuous batching.
使用vLLM部署生产级LLM推理服务器——这是一款采用PagedAttention和连续批处理技术的最快开源LLM服务引擎。
When to Use This Skill
何时使用该技能
Use this skill when:
- Serving open-source LLMs (Llama, Mistral, Qwen, Gemma) at scale
- Building an OpenAI-compatible API endpoint for self-hosted models
- Optimizing LLM throughput and latency for production traffic
- Running multi-GPU inference with tensor or pipeline parallelism
- Deploying quantized models to reduce GPU memory requirements
在以下场景中使用本技能:
- 大规模部署开源LLM(Llama、Mistral、Qwen、Gemma)
- 为自托管模型构建兼容OpenAI的API端点
- 针对生产流量优化LLM的吞吐量与延迟
- 通过张量或流水线并行运行多GPU推理
- 部署量化模型以降低GPU内存需求
Prerequisites
前置条件
- NVIDIA GPU(s) with CUDA 12.1+ (A100/H100 recommended for production)
- Docker or Python 3.9+ with pip
- 40GB+ VRAM for 70B models; 8GB+ for 7B models
- for Docker GPU passthrough
nvidia-container-toolkit
- 搭载CUDA 12.1+的NVIDIA GPU(生产环境推荐使用A100/H100)
- Docker或Python 3.9+及pip
- 70B模型需40GB+显存;7B模型需8GB+显存
- 用于Docker GPU透传的
nvidia-container-toolkit
Quick Start
快速开始
bash
undefinedbash
undefinedInstall vLLM
Install vLLM
pip install vllm
pip install vllm
Serve a model (OpenAI-compatible API)
Serve a model (OpenAI-compatible API)
vllm serve meta-llama/Llama-3.1-8B-Instruct
--host 0.0.0.0
--port 8000
--api-key your-secret-key
--host 0.0.0.0
--port 8000
--api-key your-secret-key
vllm serve meta-llama/Llama-3.1-8B-Instruct
--host 0.0.0.0
--port 8000
--api-key your-secret-key
--host 0.0.0.0
--port 8000
--api-key your-secret-key
Test the endpoint
Test the endpoint
curl http://localhost:8000/v1/chat/completions
-H "Content-Type: application/json"
-H "Authorization: Bearer your-secret-key"
-d '{ "model": "meta-llama/Llama-3.1-8B-Instruct", "messages": [{"role": "user", "content": "Hello!"}] }'
-H "Content-Type: application/json"
-H "Authorization: Bearer your-secret-key"
-d '{ "model": "meta-llama/Llama-3.1-8B-Instruct", "messages": [{"role": "user", "content": "Hello!"}] }'
undefinedcurl http://localhost:8000/v1/chat/completions
-H "Content-Type: application/json"
-H "Authorization: Bearer your-secret-key"
-d '{ "model": "meta-llama/Llama-3.1-8B-Instruct", "messages": [{"role": "user", "content": "Hello!"}] }'
-H "Content-Type: application/json"
-H "Authorization: Bearer your-secret-key"
-d '{ "model": "meta-llama/Llama-3.1-8B-Instruct", "messages": [{"role": "user", "content": "Hello!"}] }'
undefinedDocker Deployment
Docker部署
bash
docker run --runtime nvidia --gpus all \
-v ~/.cache/huggingface:/root/.cache/huggingface \
-p 8000:8000 \
--ipc=host \
vllm/vllm-openai:latest \
--model meta-llama/Llama-3.1-8B-Instruct \
--api-key your-secret-keybash
docker run --runtime nvidia --gpus all \
-v ~/.cache/huggingface:/root/.cache/huggingface \
-p 8000:8000 \
--ipc=host \
vllm/vllm-openai:latest \
--model meta-llama/Llama-3.1-8B-Instruct \
--api-key your-secret-keyDocker Compose (Production)
Docker Compose(生产环境)
yaml
services:
vllm:
image: vllm/vllm-openai:latest
runtime: nvidia
environment:
- NVIDIA_VISIBLE_DEVICES=all
- HUGGING_FACE_HUB_TOKEN=${HF_TOKEN}
volumes:
- model-cache:/root/.cache/huggingface
ports:
- "8000:8000"
ipc: host
command: >
--model meta-llama/Llama-3.1-70B-Instruct
--tensor-parallel-size 2
--max-model-len 32768
--gpu-memory-utilization 0.90
--api-key ${VLLM_API_KEY}
restart: unless-stopped
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:8000/health"]
interval: 30s
timeout: 10s
retries: 3
volumes:
model-cache:yaml
services:
vllm:
image: vllm/vllm-openai:latest
runtime: nvidia
environment:
- NVIDIA_VISIBLE_DEVICES=all
- HUGGING_FACE_HUB_TOKEN=${HF_TOKEN}
volumes:
- model-cache:/root/.cache/huggingface
ports:
- "8000:8000"
ipc: host
command: >
--model meta-llama/Llama-3.1-70B-Instruct
--tensor-parallel-size 2
--max-model-len 32768
--gpu-memory-utilization 0.90
--api-key ${VLLM_API_KEY}
restart: unless-stopped
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:8000/health"]
interval: 30s
timeout: 10s
retries: 3
volumes:
model-cache:Key Configuration Options
核心配置选项
Multi-GPU Tensor Parallelism
多GPU张量并行
bash
undefinedbash
undefinedSplit one model across 4 GPUs
Split one model across 4 GPUs
vllm serve meta-llama/Llama-3.1-70B-Instruct
--tensor-parallel-size 4
--gpu-memory-utilization 0.90
--tensor-parallel-size 4
--gpu-memory-utilization 0.90
undefinedvllm serve meta-llama/Llama-3.1-70B-Instruct
--tensor-parallel-size 4
--gpu-memory-utilization 0.90
--tensor-parallel-size 4
--gpu-memory-utilization 0.90
undefinedQuantization (Lower VRAM)
量化(降低显存占用)
bash
undefinedbash
undefinedAWQ quantization (70B on 2x A100 40GB)
AWQ quantization (70B on 2x A100 40GB)
vllm serve casperhansen/llama-3-70b-instruct-awq
--quantization awq
--tensor-parallel-size 2
--quantization awq
--tensor-parallel-size 2
vllm serve casperhansen/llama-3-70b-instruct-awq
--quantization awq
--tensor-parallel-size 2
--quantization awq
--tensor-parallel-size 2
GPTQ quantization
GPTQ quantization
vllm serve TheBloke/Llama-2-70B-Chat-GPTQ
--quantization gptq
--quantization gptq
vllm serve TheBloke/Llama-2-70B-Chat-GPTQ
--quantization gptq
--quantization gptq
FP8 (H100 NVL native)
FP8 (H100 NVL native)
vllm serve meta-llama/Llama-3.1-405B-Instruct
--quantization fp8
--tensor-parallel-size 8
--quantization fp8
--tensor-parallel-size 8
undefinedvllm serve meta-llama/Llama-3.1-405B-Instruct
--quantization fp8
--tensor-parallel-size 8
--quantization fp8
--tensor-parallel-size 8
undefinedStructured Output & Tools
结构化输出与工具调用
bash
vllm serve meta-llama/Llama-3.1-8B-Instruct \
--enable-auto-tool-choice \
--tool-call-parser llama3_json \
--guided-decoding-backend outlinesbash
vllm serve meta-llama/Llama-3.1-8B-Instruct \
--enable-auto-tool-choice \
--tool-call-parser llama3_json \
--guided-decoding-backend outlinesLoRA Adapters
LoRA适配器
bash
vllm serve meta-llama/Llama-3.1-8B-Instruct \
--enable-lora \
--lora-modules sql-lora=/path/to/sql-lora \
code-lora=/path/to/code-lora \
--max-lora-rank 64bash
vllm serve meta-llama/Llama-3.1-8B-Instruct \
--enable-lora \
--lora-modules sql-lora=/path/to/sql-lora \
code-lora=/path/to/code-lora \
--max-lora-rank 64Performance Tuning
性能调优
bash
undefinedbash
undefinedMaximize throughput for batch workloads
Maximize throughput for batch workloads
vllm serve <model>
--max-num-seqs 256 \ # max concurrent sequences --max-num-batched-tokens 8192 \ # tokens per batch --gpu-memory-utilization 0.95 \ # use 95% VRAM --swap-space 4 # CPU swap (GiB)
--max-num-seqs 256 \ # max concurrent sequences --max-num-batched-tokens 8192 \ # tokens per batch --gpu-memory-utilization 0.95 \ # use 95% VRAM --swap-space 4 # CPU swap (GiB)
vllm serve <model>
--max-num-seqs 256 \ # max concurrent sequences --max-num-batched-tokens 8192 \ # tokens per batch --gpu-memory-utilization 0.95 \ # use 95% VRAM --swap-space 4 # CPU swap (GiB)
--max-num-seqs 256 \ # max concurrent sequences --max-num-batched-tokens 8192 \ # tokens per batch --gpu-memory-utilization 0.95 \ # use 95% VRAM --swap-space 4 # CPU swap (GiB)
Minimize latency for interactive use
Minimize latency for interactive use
vllm serve <model>
--max-num-seqs 32
--enforce-eager # disable CUDA graph capture
--max-num-seqs 32
--enforce-eager # disable CUDA graph capture
undefinedvllm serve <model>
--max-num-seqs 32
--enforce-eager # disable CUDA graph capture
--max-num-seqs 32
--enforce-eager # disable CUDA graph capture
undefinedBenchmarking
基准测试
bash
undefinedbash
undefinedInstall benchmark tool
Install benchmark tool
pip install vllm
pip install vllm
Run throughput benchmark
Run throughput benchmark
python -m vllm.entrypoints.openai.run_batch
--model meta-llama/Llama-3.1-8B-Instruct
--input-file prompts.jsonl
--output-file results.jsonl
--model meta-llama/Llama-3.1-8B-Instruct
--input-file prompts.jsonl
--output-file results.jsonl
python -m vllm.entrypoints.openai.run_batch
--model meta-llama/Llama-3.1-8B-Instruct
--input-file prompts.jsonl
--output-file results.jsonl
--model meta-llama/Llama-3.1-8B-Instruct
--input-file prompts.jsonl
--output-file results.jsonl
Benchmark with vllm bench
Benchmark with vllm bench
vllm bench throughput
--model meta-llama/Llama-3.1-8B-Instruct
--num-prompts 1000
--input-len 512
--output-len 128
--model meta-llama/Llama-3.1-8B-Instruct
--num-prompts 1000
--input-len 512
--output-len 128
undefinedvllm bench throughput
--model meta-llama/Llama-3.1-8B-Instruct
--num-prompts 1000
--input-len 512
--output-len 128
--model meta-llama/Llama-3.1-8B-Instruct
--num-prompts 1000
--input-len 512
--output-len 128
undefinedMonitoring
监控
bash
undefinedbash
undefinedCheck running server stats
Check running server stats
curl http://localhost:8000/metrics # Prometheus metrics
curl http://localhost:8000/metrics # Prometheus metrics
Key metrics to watch:
Key metrics to watch:
vllm:num_requests_running - active requests
vllm:num_requests_running - active requests
vllm:gpu_cache_usage_perc - KV cache utilization
vllm:gpu_cache_usage_perc - KV cache utilization
vllm:generation_tokens_per_s - throughput
vllm:generation_tokens_per_s - throughput
vllm:time_to_first_token_ms - TTFT latency
vllm:time_to_first_token_ms - TTFT latency
vllm:e2e_request_latency_seconds - end-to-end latency
vllm:e2e_request_latency_seconds - end-to-end latency
undefinedundefinedCommon Issues
常见问题
| Issue | Cause | Fix |
|---|---|---|
| Model too large for VRAM | Add |
| Slow cold start | Model not cached | Pre-pull with |
| Low throughput | Too few concurrent requests | Increase |
| KV cache full errors | Context length too long | Set |
| Tokenizer mismatch | Use |
| 问题 | 原因 | 解决方法 |
|---|---|---|
| 模型显存占用超出容量 | 添加 |
| 冷启动缓慢 | 模型未缓存 | 使用 |
| 吞吐量低 | 并发请求数过少 | 提高 |
| KV缓存已满错误 | 上下文长度过长 | 降低 |
| 分词器不匹配 | 使用 |
Best Practices
最佳实践
- Use to leave headroom for CUDA kernels.
--gpu-memory-utilization 0.90 - Pin model versions with for reproducible deployments.
--revision - Set in production to prevent unexpected downloads.
HF_HUB_OFFLINE=1 - Use AWQ or GPTQ quantization before tensor parallelism — lower VRAM first.
- Enable for long-context workloads.
--enable-chunked-prefill - Monitor — above 95% causes queuing.
gpu_cache_usage_perc
- 使用为CUDA内核预留空间。
--gpu-memory-utilization 0.90 - 通过固定模型版本,确保部署可复现。
--revision - 生产环境中设置,避免意外下载。
HF_HUB_OFFLINE=1 - 优先使用AWQ或GPTQ量化,再考虑张量并行——先降低显存占用。
- 针对长上下文工作负载启用。
--enable-chunked-prefill - 监控——超过95%会导致请求排队。
gpu_cache_usage_perc
Related Skills
相关技能
- llm-inference-scaling - Auto-scaling vLLM deployments
- gpu-server-management - GPU driver setup
- llm-gateway - Load balancing across vLLM instances
- llm-cost-optimization - Cost management
- model-serving-kubernetes - K8s deployment
- llm-inference-scaling - vLLM部署自动扩容
- gpu-server-management - GPU驱动配置
- llm-gateway - vLLM实例负载均衡
- llm-cost-optimization - 成本管理
- model-serving-kubernetes - K8s部署