Zum Inhalt springen

LMDeploy - LLM Compression & Serving Cheatsheet

LMDeploy - LLM Compression & Serving Cheatsheet

LMDeploy (aus dem InternLM/OpenMMLab Ökosystem) ist ein Toolkit zum Komprimieren, Quantisieren und Servieren von Large Language Models. Seine hochperformante TurboMind Engine liefert starken Throughput via Persistent Batching, Blocked KV Cache und Optimierten CUDA Kernels, und es bietet auch einen PyTorch Backend. Es unterstützt 4-Bit AWQ Weight Quantisierung und KV-Cache Quantisierung, einen OpenAI-kompatiblen API Server und Vision-Language Modelle (VLMs).

Installation

MethodeBefehl
pippip install lmdeploy
Mit CUDA Extraspip install lmdeploy[all]
Dockerdocker run --gpus all openmmlab/lmdeploy:latest
AnforderungenNVIDIA GPU + CUDA
Überprüfenlmdeploy --version

Quick Inference (CLI)

# Interaktive Chat im Terminal (TurboMind Engine)
lmdeploy chat internlm/internlm2_5-7b-chat

# Batch/Pipeline Inferenz in Python (unten)

Python Pipeline

from lmdeploy import pipeline

pipe = pipeline("internlm/internlm2_5-7b-chat")
resp = pipe(["Erklären Sie RAG in einem Satz."])
print(resp[0].text)
CallBeschreibung
pipeline(model)Lade ein Modell mit dem Default (TurboMind) Engine
pipe([prompts])Batch Inferenz
GenerationConfig(...)Sampling Params (Temperature, top_p, max_new_tokens)
TurbomindEngineConfig(...)Engine Tuning (tp, Cache, Session Len)

Serving eine API

# OpenAI-kompatible Server auf Port 23333
lmdeploy serve api_server internlm/internlm2_5-7b-chat --server-port 23333

# Query es
curl http://localhost:23333/v1/chat/completions \
  -H "Content-Type: application/json" \
  -d '{"model":"internlm2_5-7b-chat","messages":[{"role":"user","content":"hi"}]}'
BefehlBeschreibung
lmdeploy serve api_server MODELStarte den OpenAI-kompatiblen Server
lmdeploy serve gradio MODELStarte eine Gradio Web UI
--server-portAPI Port
--tp NTensor Parallelism über N GPUs
--session-len NMax Context Length

Quantisierung (AWQ)

# 4-Bit AWQ Weight-Only Quantisierung
lmdeploy lite auto_awq internlm/internlm2_5-7b-chat \
  --work-dir internlm2_5-7b-chat-4bit

# Serve das Quantisierte Modell
lmdeploy serve api_server internlm2_5-7b-chat-4bit --model-format awq
BefehlBeschreibung
lmdeploy lite auto_awq MODELErzeuge ein 4-Bit AWQ Modell
lmdeploy lite calibrate MODELKalibrierungs Schritt
--model-format awqServe ein AWQ-Quantisiertes Modell
KV-Cache Quant--quant-policy 4 oder 8 für INT4/INT8 KV Cache

Engine Konfiguration

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))
OptionEffekt
tpTensor-Parallel GPUs
session_lenContext Length
cache_max_entry_countFraktion von VRAM für KV Cache
quant_policyKV Cache Quantisierung (4/8)

Vision-Language Modelle

FähigkeitNotiz
VLM SupportServe Modelle wie InternVL, LLaVA, Qwen-VL
Same APIMultimodal Messages über den OpenAI-kompatiblen Server

LMDeploy vs Andere Engines

AspektLMDeployvLLMAphrodite
EngineTurboMind + PyTorchPagedAttentionvLLM Fork
QuantisierungAWQ + KV Cache QuantWachsendBreiteste Formate
VLM SupportStarkJaJa
Beste fürHigh-Throughput + AWQ + VLMsStandard ServingCommunity Quant Formate

Ressourcen