Aller au contenu

⚙️ Configurer vLLM en production multi-GPU


1. Installation

Via pip (recommandé)

Fenêtre de terminal
# Python 3.10-3.12, CUDA 12.1+
pip install vllm
# Vérification
python -c "import vllm; print(vllm.__version__)"

Via Docker (production recommandée)

L’image officielle évite les conflits de dépendances CUDA1 :

Fenêtre de terminal
docker pull vllm/vllm-openai:latest
docker run --runtime nvidia --gpus all \
-p 8000:8000 \
-v ~/.cache/huggingface:/root/.cache/huggingface \
vllm/vllm-openai:latest \
--model meta-llama/Llama-3.1-8B-Instruct \
--dtype auto

2. Configuration mono-GPU

Démarrage minimal

Fenêtre de terminal
vllm serve meta-llama/Llama-3.1-8B-Instruct \
--host 0.0.0.0 \
--port 8000

Paramètres essentiels

Fenêtre de terminal
vllm serve meta-llama/Llama-3.1-70B-Instruct \
--host 0.0.0.0 \
--port 8000 \
--dtype bfloat16 \ # bf16 natif sur Ampere+, plus stable que fp16
--max-model-len 8192 \ # fenêtre de contexte max (limite le KV Cache)
--gpu-memory-utilization 0.90 \ # % VRAM alloué au KV Cache (0.85-0.95)
--max-num-seqs 256 \ # requêtes concurrentes max en continuous batching
--served-model-name llama-70b # alias dans l'API (évite d'exposer le chemin HF)

Paramètre critique — gpu-memory-utilization : vLLM réserve au démarrage la fraction indiquée de VRAM pour le KV Cache. Si vos prompts sont longs ou si vous avez beaucoup de requêtes concurrentes, montez à 0.95. Si des OOM apparaissent, descendez à 0.852.

Modèles quantifiés (AWQ / GPTQ)

Fenêtre de terminal
# Modèle AWQ (meilleure qualité à iso-mémoire vs GGUF Q4)
vllm serve TheBloke/Llama-2-70B-Chat-AWQ \
--quantization awq \
--dtype auto
# Modèle GPTQ
vllm serve TheBloke/Llama-2-70B-GPTQ \
--quantization gptq \
--dtype float16

3. Configuration multi-GPU (Tensor Parallelism)

Le Tensor Parallelism répartit les poids d’une même couche sur plusieurs GPU du même serveur via NVLink ou PCIe. C’est le mode recommandé pour les modèles qui ne tiennent pas dans une seule carte3.

Fenêtre de terminal
# 2 GPU — modèle 70B dans 2 × 40 Go
vllm serve meta-llama/Llama-3.1-70B-Instruct \
--tensor-parallel-size 2 \
--dtype bfloat16
# 4 GPU — modèle 70B avec marges confortables
vllm serve meta-llama/Llama-3.1-70B-Instruct \
--tensor-parallel-size 4 \
--gpu-memory-utilization 0.90
# 8 GPU — modèle 405B ou MoE massif
vllm serve meta-llama/Llama-3.1-405B-Instruct \
--tensor-parallel-size 8 \
--pipeline-parallel-size 1 \
--dtype bfloat16

Règle de dimensionnement :

  • tensor-parallel-size doit être une puissance de 2 (1, 2, 4, 8)
  • Chaque GPU doit avoir accès à taille_modèle / tensor_parallel_size de VRAM
  • L’interconnexion décide de l’efficacité : NVLink >> PCIe (voir Stations Multi-GPU)
graph LR
    A[Requête API] --> B[vLLM Scheduler]
    B --> C[GPU 0 — couches 0-17]
    B --> D[GPU 1 — couches 18-35]
    B --> E[GPU 2 — couches 36-53]
    B --> F[GPU 3 — couches 54-71]
    C & D & E & F --> G[Réponse]

4. Déploiement multi-nœuds avec Ray

Pour dépasser la capacité d’un seul serveur, vLLM s’appuie sur Ray pour distribuer le modèle entre plusieurs machines4.

Prérequis réseau

Les nœuds doivent se voir sur un réseau à faible latence. Idéalement RoCE/InfiniBand — en pratique, 25 Gb Ethernet suffit pour du Pipeline Parallelism4.

Configuration du cluster Ray

Fenêtre de terminal
# === Sur le nœud HEAD (nœud 0) ===
pip install ray vllm
# Démarrer le processus Ray head
ray start --head --port=6379
# === Sur chaque nœud WORKER (nœuds 1, 2, ...) ===
pip install ray vllm
# Rejoindre le cluster (remplacer HEAD_IP par l'IP du nœud head)
ray start --address='HEAD_IP:6379'
# === Vérifier le cluster ===
ray status
# → affiche les nœuds connectés et les GPU disponibles

Lancer vLLM sur le cluster

Fenêtre de terminal
# Sur le nœud HEAD — vLLM utilise Ray pour distribuer automatiquement
vllm serve meta-llama/Llama-3.1-405B-Instruct \
--tensor-parallel-size 4 \ # 4 GPU par nœud
--pipeline-parallel-size 2 \ # 2 nœuds
--host 0.0.0.0 \
--port 8000

vLLM et Ray gèrent automatiquement la répartition : les 4 premiers GPU (nœud 0) traitent les premières couches, les 4 suivants (nœud 1) les suivantes4.

Désagrégation Prefill / Decode (2026)

Architecture avancée disponible depuis vLLM v0.6+ : des nœuds dédiés au Prefill (lecture du prompt, CPU-bound) et d’autres au Decode (génération, memory-bandwidth-bound)5. Réduit le TTFT de 30 à 50% sur des prompts longs.

Fenêtre de terminal
# Nœud Prefill (optimisé calcul)
vllm serve ... --num-speculative-tokens 5 --role prefill
# Nœud Decode (optimisé mémoire)
vllm serve ... --role decode

5. Configuration production — paramètres avancés

Authentification API

Fenêtre de terminal
vllm serve ... \
--api-key "sk-votre-token-secret"

Ou via variable d’environnement :

Fenêtre de terminal
export VLLM_API_KEY="sk-votre-token-secret"
vllm serve ...

Les clients doivent envoyer Authorization: Bearer sk-votre-token-secret.

Limites et timeouts

Fenêtre de terminal
vllm serve ... \
--max-num-seqs 512 \ # file d'attente max (au-delà : erreur 503)
--request-timeout 120 \ # timeout par requête en secondes
--disable-log-requests # désactiver les logs de requêtes en production

Optimisation KV Cache — quantification FP8

Sur GPU NVIDIA Hopper (H100, H200), la quantification du KV Cache en FP8 réduit son empreinte de ~50% sans perte de qualité notable6 :

Fenêtre de terminal
vllm serve ... \
--kv-cache-dtype fp8 \
--calculate-kv-cache-size # affiche la taille KV cache configurée

Automatic Prefix Caching (APC) — indispensable pour RAG et agents

En environnement multi-utilisateurs ou multi-agents, plusieurs requêtes partagent souvent le même System Prompt (500-2000 tokens) ou le même document RAG en contexte. Sans APC, vLLM calcule et stocke le KV Cache de ce préfixe N fois — une fois par requête — gaspillant VRAM et temps de calcul.

Fenêtre de terminal
vllm serve meta-llama/Llama-3.1-70B-Instruct \
--enable-prefix-caching \ # active le hachage de blocs de prompt
--max-model-len 8192 \
--gpu-memory-utilization 0.90

Fonctionnement : vLLM hache chaque bloc de 16 tokens. Si une nouvelle requête commence par la même séquence de blocs qu’une requête précédente encore en cache GPU, les vecteurs Key/Value sont réutilisés directement — sans recalcul du Prefill7.

Impact mesuré :

ScénarioSans APCAvec APC
20 agents parallèles, même system prompt 800 tokensTTFT 3-8s chacunTTFT < 100ms dès la 2e requête
Pipeline RAG : même contexte document partagérecalcul intégral × Nhit cache : ~96% VRAM économisée sur le préfixe

Systemd service (Linux)

/etc/systemd/system/vllm.service
[Unit]
Description=vLLM Inference Server
After=network.target
[Service]
Type=simple
User=vllm
Environment="HF_HOME=/data/models"
Environment="CUDA_VISIBLE_DEVICES=0,1,2,3"
ExecStart=/usr/bin/python -m vllm.entrypoints.openai.api_server \
--model meta-llama/Llama-3.1-70B-Instruct \
--tensor-parallel-size 4 \
--host 127.0.0.1 \
--port 8000 \
--gpu-memory-utilization 0.90
Restart=always
RestartSec=10
[Install]
WantedBy=multi-user.target
Fenêtre de terminal
sudo systemctl daemon-reload
sudo systemctl enable --now vllm
sudo journalctl -u vllm -f # suivre les logs

6. Vérification et tests

Fenêtre de terminal
# Health check
curl http://localhost:8000/health
# Liste des modèles chargés
curl http://localhost:8000/v1/models | python3 -m json.tool
# Test de génération
curl http://localhost:8000/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer sk-votre-token" \
-d '{
"model": "llama-70b",
"messages": [{"role": "user", "content": "Bonjour, tu fonctionnes ?"}],
"max_tokens": 100
}'
# Métriques Prometheus
curl http://localhost:8000/metrics | grep vllm

Prochaines étapes


Sources et Références

Footnotes

  1. vLLM Project, Installation — Docker (image officielle vllm/vllm-openai, CUDA 12.x, dépendances). https://docs.vllm.ai/en/stable/getting_started/installation.html

  2. vLLM Project, Engine Arguments (--gpu-memory-utilization, --max-model-len, --max-num-seqs, comportement KV Cache). https://docs.vllm.ai/en/stable/serving/engine_args.html

  3. vLLM Project, Parallelism and Scaling — Tensor Parallelism (--tensor-parallel-size, sharding des poids, recommandations NVLink). https://docs.vllm.ai/en/stable/serving/parallelism_scaling/

  4. Anyscale & vLLM Blog, Streamlined multi-node serving with Ray symmetric-run (configuration Ray cluster, pipeline parallelism inter-nœuds). https://www.anyscale.com/blog/streamlined-multi-node-serving, Novembre 2025. 2 3

  5. vLLM Project, Disaggregated Prefill and Decode (architecture séparation phases, réduction TTFT). https://docs.vllm.ai/en/stable/features/disagg_prefill.html

  6. vLLM Project, KV Cache Quantization (FP8 KV cache, prise en charge NVIDIA Hopper, impact mémoire). https://docs.vllm.ai/en/stable/features/quantization/fp8_kv_cache.html

  7. vLLM Project, Automatic Prefix Caching (fonctionnement par blocs de 16 tokens, impact TTFT, compatibilité tensor parallelism). https://docs.vllm.ai/en/stable/features/automatic_prefix_caching.html 2