Skip to main content
vLLM is a high-throughput and memory-efficient inference engine for large language models. It provides significant performance improvements over standard PyTorch inference through continuous batching, PagedAttention, and optimized CUDA kernels.

Why vLLM?

High Throughput

2-3x faster than standard inference with continuous batching

Memory Efficient

PagedAttention reduces memory waste by up to 80%

Easy Integration

Compatible with HuggingFace models and OpenAI API format

Multi-GPU Support

Built-in tensor parallelism for distributed inference

Installation

1

Install vLLM

For CUDA 12.1 and PyTorch 2.1:
For other CUDA versions, see vLLM Installation Guide
2

Verify Installation

3

Using Docker (Recommended)

vLLM requires CUDA 11.4 or higher and a GPU with compute capability 7.0 or higher.

GPU Requirements

Memory Requirements by Model Size

Supported Consumer GPUs

Bfloat16 requires GPU compute capability ≥ 8.0. For older GPUs, use --dtype float16.

Quick Start

Standalone OpenAI API Server

Deploy an OpenAI-compatible API server with vLLM:

Chat Template Configuration

Download and use the ChatML template for proper formatting:
The chat template file is required for proper message formatting with the Qwen models.

Python Wrapper

Use the vLLM wrapper for Transformers-like interface:
1

Download the Wrapper

2

Use in Python

Wrapper Configuration

API Usage

Using OpenAI Python Client

For vLLM standalone API, you must set stop_token_ids=[151645] or stop=["<|im_end|>"] to prevent infinite generation.

Advanced Configuration

Performance Tuning

Configuration Parameters

string
required
Model name or path (HuggingFace format)
int
default:"1"
Number of GPUs for tensor parallelism
string
default:"auto"
Data type: auto, bfloat16, float16, float32
int
Maximum sequence length (prompt + generation)
float
default:"0.90"
Fraction of GPU memory to use (0.0 to 1.0)
int
default:"256"
Maximum number of sequences processed in parallel
int
Maximum tokens processed in a batch
int
default:"4"
CPU swap space size in GB
boolean
Disable request logging for reduced overhead

Multi-GPU Deployment

Tensor Parallelism

Distribute model layers across multiple GPUs:

GPU Selection

Control which GPUs to use:

Production Deployment

Systemd Service

Create /etc/systemd/system/qwen-vllm.service:
Manage the service:

Docker Deployment

Load Balancing

Nginx configuration for multiple vLLM instances:

Performance Benchmarks

Throughput Comparison

Qwen-7B on A100 80GB GPU:

Memory Efficiency

Qwen-72B memory usage:

Limitations

Current vLLM Limitations with Qwen:
  1. Dynamic NTK ROPE: vLLM does not support dynamic NTK ROPE scaling. Long sequence generation quality may degrade.
  2. Context Length: Maximum context length is fixed at model initialization. Cannot dynamically extend beyond max_model_len.
  3. Repetition Penalty: Requires vLLM ≥ 0.2.2 for repetition penalty support.

Troubleshooting

Error: torch.cuda.OutOfMemoryErrorSolutions:
  • Reduce --gpu-memory-utilization (try 0.85 or 0.80)
  • Decrease --max-model-len
  • Use quantized Int4 model
  • Increase --tensor-parallel-size
Error: ValueError: trust_remote_code is requiredSolution: Always include --trust-remote-code:
Issue: Model generates indefinitelySolution: Set proper stop tokens:
Issue: Not achieving expected performanceSolutions:
  • Increase --max-num-seqs for more concurrent requests
  • Use --dtype bfloat16 instead of float16/float32
  • Disable request logging with --disable-log-requests
  • Check GPU utilization with nvidia-smi
Error: Issues with multi-GPU deploymentSolutions:
  • Ensure all GPUs have same model
  • Check NCCL configuration
  • Verify GPU visibility:
  • Test with Ray backend:

Monitoring

Health Checks

Metrics Collection

vLLM exposes Prometheus metrics:

Next Steps

FastChat Integration

Add web UI and more features with FastChat

Production Guide

Production deployment best practices

Performance Tuning

Advanced performance optimization

Monitoring Setup

Set up comprehensive monitoring