SKILL.md
SKILL.mdBrowse 5 files
2,585 tokens
9,335 bytes
Token encoding: o200k_base
Snapshot 24fd22b
1---2name: serving-llms-vllm3description: "vLLM: high-throughput LLM serving, OpenAI API, quantization."4version: 1.0.15author: Orchestra Research6license: MIT7dependencies: [vllm, torch, transformers]8platforms: [linux, macos]9metadata:10 hermes:11 tags: [vLLM, Inference Serving, PagedAttention, Continuous Batching, High Throughput, Production, OpenAI API, Quantization, Tensor Parallelism]12 13---14 15# vLLM - High-Performance LLM Serving16 17## When to use18 19Use when deploying production LLM APIs, optimizing inference latency/throughput, or serving models with limited GPU memory. Supports OpenAI-compatible endpoints, quantization (GPTQ/AWQ/FP8), and tensor parallelism.20 21## Quick start22 23vLLM achieves 24x higher throughput than standard transformers through PagedAttention (block-based KV cache) and continuous batching (mixing prefill/decode requests).24 25**Installation**:26```bash27pip install vllm28```29 30**Basic offline inference**:31```python32from vllm import LLM, SamplingParams33 34llm = LLM(model="meta-llama/Meta-Llama-3-8B-Instruct")35sampling = SamplingParams(temperature=0.7, max_tokens=256)36 37outputs = llm.generate(["Explain quantum computing"], sampling)38print(outputs[0].outputs[0].text)39```40 41**OpenAI-compatible server**:42```bash43vllm serve meta-llama/Meta-Llama-3-8B-Instruct44 45# Query with OpenAI SDK46python -c "47from openai import OpenAI48client = OpenAI(base_url='http://localhost:8000/v1', api_key='EMPTY')49print(client.chat.completions.create(50 model='meta-llama/Meta-Llama-3-8B-Instruct',51 messages=[{'role': 'user', 'content': 'Hello!'}]52).choices[0].message.content)53"54```55 56## Common workflows57 58### Workflow 1: Production API deployment59 60Copy this checklist and track progress:61 62```63Deployment Progress:64- [ ] Step 1: Configure server settings65- [ ] Step 2: Test with limited traffic66- [ ] Step 3: Enable monitoring67- [ ] Step 4: Deploy to production68- [ ] Step 5: Verify performance metrics69```70 71**Step 1: Configure server settings**72 73Choose configuration based on your model size:74 75```bash76# For 7B-13B models on single GPU77vllm serve meta-llama/Meta-Llama-3-8B-Instruct \78 --gpu-memory-utilization 0.9 \79 --max-model-len 8192 \80 --port 800081 82# For 30B-70B models with tensor parallelism83vllm serve meta-llama/Meta-Llama-3-70B-Instruct \84 --tensor-parallel-size 4 \85 --gpu-memory-utilization 0.9 \86 --quantization awq \87 --port 800088 89# For production with caching (Prometheus metrics are exposed90# automatically at /metrics on the API port)91vllm serve meta-llama/Meta-Llama-3-8B-Instruct \92 --gpu-memory-utilization 0.9 \93 --enable-prefix-caching \94 --port 8000 \95 --host 0.0.0.096```97 98**Step 2: Test with limited traffic**99 100Run load test before production:101 102```bash103# Install load testing tool104pip install locust105 106# Create test_load.py with sample requests107# Run: locust -f test_load.py --host http://localhost:8000108```109 110Verify TTFT (time to first token) < 500ms and throughput > 100 req/sec.111 112**Step 3: Enable monitoring**113 114vLLM exposes Prometheus metrics at `/metrics` on the API port (default 8000):115 116```bash117curl http://localhost:8000/metrics | grep vllm118```119 120Key metrics to monitor:121- `vllm:time_to_first_token_seconds` - Latency122- `vllm:num_requests_running` - Active requests123- `vllm:gpu_cache_usage_perc` - KV cache utilization124 125**Step 4: Deploy to production**126 127Use Docker for consistent deployment:128 129```bash130# Run vLLM in Docker131docker run --gpus all -p 8000:8000 \132 vllm/vllm-openai:latest \133 --model meta-llama/Meta-Llama-3-8B-Instruct \134 --gpu-memory-utilization 0.9 \135 --enable-prefix-caching136```137 138**Step 5: Verify performance metrics**139 140Check that deployment meets targets:141- TTFT < 500ms (for short prompts)142- Throughput > target req/sec143- GPU utilization > 80%144- No OOM errors in logs145 146### Workflow 2: Offline batch inference147 148For processing large datasets without server overhead.149 150Copy this checklist:151 152```153Batch Processing:154- [ ] Step 1: Prepare input data155- [ ] Step 2: Configure LLM engine156- [ ] Step 3: Run batch inference157- [ ] Step 4: Process results158```159 160**Step 1: Prepare input data**161 162```python163# Load prompts from file164prompts = []165with open("prompts.txt") as f:166 prompts = [line.strip() for line in f]167 168print(f"Loaded {len(prompts)} prompts")169```170 171**Step 2: Configure LLM engine**172 173```python174from vllm import LLM, SamplingParams175 176llm = LLM(177 model="meta-llama/Meta-Llama-3-8B-Instruct",178 tensor_parallel_size=2, # Use 2 GPUs179 gpu_memory_utilization=0.9,180 max_model_len=4096181)182 183sampling = SamplingParams(184 temperature=0.7,185 top_p=0.95,186 max_tokens=512,187 stop=["</s>", "\n\n"]188)189```190 191**Step 3: Run batch inference**192 193vLLM automatically batches requests for efficiency:194 195```python196# Process all prompts in one call197outputs = llm.generate(prompts, sampling)198 199# vLLM handles batching internally200# No need to manually chunk prompts201```202 203**Step 4: Process results**204 205```python206# Extract generated text207results = []208for output in outputs:209 prompt = output.prompt210 generated = output.outputs[0].text211 results.append({212 "prompt": prompt,213 "generated": generated,214 "tokens": len(output.outputs[0].token_ids)215 })216 217# Save to file218import json219with open("results.jsonl", "w") as f:220 for result in results:221 f.write(json.dumps(result) + "\n")222 223print(f"Processed {len(results)} prompts")224```225 226### Workflow 3: Quantized model serving227 228Fit large models in limited GPU memory.229 230```231Quantization Setup:232- [ ] Step 1: Choose quantization method233- [ ] Step 2: Find or create quantized model234- [ ] Step 3: Launch with quantization flag235- [ ] Step 4: Verify accuracy236```237 238**Step 1: Choose quantization method**239 240- **AWQ**: Best for 70B models, minimal accuracy loss241- **GPTQ**: Wide model support, good compression242- **FP8**: Fastest on H100 GPUs243 244**Step 2: Find or create quantized model**245 246Use pre-quantized models from HuggingFace:247 248```bash249# Search for AWQ models250# Example: TheBloke/Llama-2-70B-AWQ251```252 253**Step 3: Launch with quantization flag**254 255```bash256# Using pre-quantized model257vllm serve TheBloke/Llama-2-70B-AWQ \258 --quantization awq \259 --tensor-parallel-size 1 \260 --gpu-memory-utilization 0.95261 262# Results: 70B model in ~40GB VRAM263```264 265**Step 4: Verify accuracy**266 267Test outputs match expected quality:268 269```python270# Compare quantized vs non-quantized responses271# Verify task-specific performance unchanged272```273 274## When to use vs alternatives275 276**Use vLLM when:**277- Deploying production LLM APIs (100+ req/sec)278- Serving OpenAI-compatible endpoints279- Limited GPU memory but need large models280- Multi-user applications (chatbots, assistants)281- Need low latency with high throughput282 283**Use alternatives instead:**284- **llama.cpp**: CPU/edge inference, single-user285- **HuggingFace transformers**: Research, prototyping, one-off generation286- **TensorRT-LLM**: NVIDIA-only, need absolute maximum performance287- **Text-Generation-Inference**: Already in HuggingFace ecosystem288 289## Common issues290 291**Issue: Out of memory during model loading**292 293Reduce memory usage:294```bash295vllm serve MODEL \296 --gpu-memory-utilization 0.7 \297 --max-model-len 4096298```299 300Or use quantization:301```bash302vllm serve MODEL --quantization awq303```304 305**Issue: Slow first token (TTFT > 1 second)**306 307Enable prefix caching for repeated prompts:308```bash309vllm serve MODEL --enable-prefix-caching310```311 312For long prompts, enable chunked prefill:313```bash314vllm serve MODEL --enable-chunked-prefill315```316 317**Issue: Model not found error**318 319Use `--trust-remote-code` for custom models:320```bash321vllm serve MODEL --trust-remote-code322```323 324**Issue: Low throughput (<50 req/sec)**325 326Increase concurrent sequences:327```bash328vllm serve MODEL --max-num-seqs 512329```330 331Check GPU utilization with `nvidia-smi` - should be >80%.332 333**Issue: Inference slower than expected**334 335Verify tensor parallelism uses power of 2 GPUs:336```bash337vllm serve MODEL --tensor-parallel-size 4 # Not 3338```339 340Enable speculative decoding for faster generation (pass config as JSON;341`--speculative-model` was removed in favor of `--speculative-config`):342```bash343vllm serve MODEL \344 --speculative-config '{"model": "DRAFT_MODEL", "num_speculative_tokens": 5, "method": "draft_model"}'345```346 347## Advanced topics348 349**Server deployment patterns**: See [references/server-deployment.md](references/server-deployment.md) for Docker, Kubernetes, and load balancing configurations.350 351**Performance optimization**: See [references/optimization.md](references/optimization.md) for PagedAttention tuning, continuous batching details, and benchmark results.352 353**Quantization guide**: See [references/quantization.md](references/quantization.md) for AWQ/GPTQ/FP8 setup, model preparation, and accuracy comparisons.354 355**Troubleshooting**: See [references/troubleshooting.md](references/troubleshooting.md) for detailed error messages, debugging steps, and performance diagnostics.356 357## Hardware requirements358 359- **Small models (7B-13B)**: 1x A10 (24GB) or A100 (40GB)360- **Medium models (30B-40B)**: 2x A100 (40GB) with tensor parallelism361- **Large models (70B+)**: 4x A100 (40GB) or 2x A100 (80GB), use AWQ/GPTQ362 363Supported platforms: NVIDIA (primary), AMD ROCm, Intel GPUs, TPUs364 365## Resources366 367- Official docs: https://docs.vllm.ai368- GitHub: https://github.com/vllm-project/vllm369- Paper: "Efficient Memory Management for Large Language Model Serving with PagedAttention" (SOSP 2023)370- Community: https://discuss.vllm.ai371 372 373 374 Discovery context
Discovered by repository scan. No exact path reference found in the snapshot’s root AGENTS.md.