Aller au contenu

LMDeploy - Compression et service des LLM

LMDeploy - Compression et service des LLM

LMDeploy (de l’écosystème InternLM/OpenMMLab) est une boîte à outils pour compresser, quantifier et servir les grands modèles de langage. Son moteur haute performance TurboMind offre un bon débit via la mise en lot persistante, le cache KV bloqué, et les noyaux CUDA optimisés, et il offre également un backend PyTorch. Il supporte la quantification de poids AWQ 4-bit et la quantification du cache KV, un serveur API compatible OpenAI, et les modèles vision-langage (VLM).

Installation

MéthodeCommande
pippip install lmdeploy
Avec extras CUDApip install lmdeploy[all]
Dockerdocker run --gpus all openmmlab/lmdeploy:latest
ExigencesNVIDIA GPU + CUDA
Vérifierlmdeploy --version

Inférence rapide (CLI)

# Chat interactif dans le terminal (moteur TurboMind)
lmdeploy chat internlm/internlm2_5-7b-chat

# Inférence batch/pipeline en Python (ci-dessous)

Pipeline Python

from lmdeploy import pipeline

pipe = pipeline("internlm/internlm2_5-7b-chat")
resp = pipe(["Expliquer RAG en une phrase."])
print(resp[0].text)
AppelDescription
pipeline(model)Charger un modèle avec le moteur par défaut (TurboMind)
pipe([prompts])Inférence en lot
GenerationConfig(...)Params d’échantillonnage (température, top_p, max_new_tokens)
TurbomindEngineConfig(...)Tuning du moteur (tp, cache, session len)

Servir une API

# Serveur compatible OpenAI sur le port 23333
lmdeploy serve api_server internlm/internlm2_5-7b-chat --server-port 23333

# L'interroger
curl http://localhost:23333/v1/chat/completions \
  -H "Content-Type: application/json" \
  -d '{"model":"internlm2_5-7b-chat","messages":[{"role":"user","content":"hi"}]}'
CommandeDescription
lmdeploy serve api_server MODELDémarrer le serveur compatible OpenAI
lmdeploy serve gradio MODELLancer une interface Web Gradio
--server-portPort de l’API
--tp NParallélisme de tenseur entre N GPU
--session-len NLongueur maximale du contexte

Quantification (AWQ)

# Quantification de poids AWQ 4-bit poids-only
lmdeploy lite auto_awq internlm/internlm2_5-7b-chat \
  --work-dir internlm2_5-7b-chat-4bit

# Servir le modèle quantifié
lmdeploy serve api_server internlm2_5-7b-chat-4bit --model-format awq
CommandeDescription
lmdeploy lite auto_awq MODELProduire un modèle AWQ 4-bit
lmdeploy lite calibrate MODELÉtape d’étalonnage
--model-format awqServir un modèle quantifié AWQ
KV-cache quant--quant-policy 4 ou 8 pour cache KV INT4/INT8

Configuration du moteur

from lmdeploy import pipeline, TurbomindEngineConfig
pipe = pipeline("internlm/internlm2_5-7b-chat",
    backend_config=TurbomindEngineConfig(
        tp=2, session_len=8192, cache_max_entry_count=0.8, quant_policy=8))
OptionEffet
tpGPU parallélisme-tenseur
session_lenLongueur du contexte
cache_max_entry_countFraction de VRAM pour le cache KV
quant_policyQuantification du cache KV (4/8)

Modèles vision-langage

CapacitéRemarque
Support VLMServir des modèles comme InternVL, LLaVA, Qwen-VL
Même APIMessages multimodaux via le serveur compatible OpenAI

LMDeploy vs autres moteurs

AspectLMDeployvLLMAphrodite
MoteurTurboMind + PyTorchPagedAttentionDérivé de vLLM
QuantificationAWQ + quant cache KVCroissanteFormats les plus larges
Support VLMForteOuiOui
Meilleur pourDébit élevé + AWQ + VLMService standardFormats quant communautaires

Ressources