> For the complete documentation index, see [llms.txt](https://docs.clore.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.clore.ai/guides/guides_v2-de/sprachmodelle/lmdeploy.md).

# LMDeploy

**Effizientes LLM-Deployment-Toolkit vom Shanghai AI Lab** — produktionsreife Inferenz, Quantisierung und Bereitstellung für große Sprachmodelle mit Continuous Batching und PagedAttention.

> 🏛️ Entwickelt von **OpenMMLab / Shanghai AI Lab** | Apache-2.0-Lizenz | 4.000+ GitHub-Sterne

***

## Was ist LMDeploy?

LMDeploy ist ein umfassendes Toolkit zum Komprimieren, Bereitstellen und Betreiben großer Sprachmodelle in der Produktion. Es wurde vom selben Team hinter OpenMMLab (MMDetection, MMSeg) entwickelt und bringt Optimierungen auf Forschungsniveau in die praktische Bereitstellung ein:

* **TurboMind-Engine** — leistungsstarkes C++-Inferenz-Backend mit CUDA-Optimierungen
* **PyTorch-Engine** — flexible Python-basierte Engine für breite Modellkompatibilität
* **Kontinuierliches Batching** — maximiert die GPU-Auslastung über gleichzeitige Anfragen hinweg
* **PagedAttention** — effizientes KV-Cache-Management (ähnlich wie vLLM)
* **4-Bit / 8-Bit-Quantisierung** — Unterstützung für AWQ und SmoothQuant
* **Vision-Language-Modelle** — Unterstützung für InternVL, LLaVA, Qwen-VL

Im Vergleich zu vLLM liefert LMDeploys TurboMind-Engine bei Llama 3 8B und batch=32 einen um etwa 1,36× höheren Durchsatz, und seine AWQ-Quantisierung ist erstklassig — kein Nebengedanke. Für VLMs (insbesondere InternVL2) ist LMDeploy der Referenz-Deployment-Stack.

### Warum LMDeploy?

| Funktion                              | LMDeploy | vLLM     | TGI      |
| ------------------------------------- | -------- | -------- | -------- |
| Kontinuierliches Batching             | ✅        | ✅        | ✅        |
| AWQ-Quantisierung                     | ✅        | ✅        | ❌        |
| Spezulative Dekodierung               | ✅        | ✅        | ✅        |
| Vision-Language                       | ✅        | Begrenzt | Begrenzt |
| OpenAI-API                            | ✅        | ✅        | ✅        |
| TurboMind (benutzerdefinierte Engine) | ✅        | ❌        | ❌        |

***

## Schnellstart auf Clore.ai

### Schritt 1: Wählen Sie einen GPU-Server

Auf [clore.ai](https://clore.ai) Marktplatz:

* **Mindestanforderung:** NVIDIA-GPU mit 8 GB VRAM (für 7B-Modelle)
* **Empfohlen:** RTX 3090/4090 (24 GB) oder A100 (40/80 GB)
* **CUDA:** 11.8 oder 12.x erforderlich

### Schritt 2: LMDeploy-Docker bereitstellen

```
Docker-Image: openmmlab/lmdeploy
```

**Port-Zuordnungen:**

| Container-Port | Zweck               |
| -------------- | ------------------- |
| `22`           | SSH-Zugriff         |
| `23333`        | LMDeploy-API-Server |

**Umgebungsvariablen:**

```
HUGGING_FACE_HUB_TOKEN=your_hf_token_here  # Für gesperrte Modelle
```

### Schritt 3: Per SSH verbinden und überprüfen

```bash
ssh root@<clore-node-ip> -p <ssh-port>

# Installation überprüfen
python -c "import lmdeploy; print(lmdeploy.__version__)"
lmdeploy --help
```

***

## Starten des API-Servers

### OpenAI-kompatibler Server (empfohlen)

```bash
# Llama 3 8B mit TurboMind-Engine bereitstellen
lmdeploy serve api_server \
  meta-llama/Meta-Llama-3-8B-Instruct \
  --server-port 23333 \
  --server-name 0.0.0.0 \\
  --model-name llama3-8b

# Mit expliziter Engine-Auswahl
lmdeploy serve api_server \
  meta-llama/Meta-Llama-3-8B-Instruct \
  --backend turbomind \
  --server-port 23333 \
  --server-name 0.0.0.0 \\
  --tp 1 \
  --max-batch-size 128 \
  --cache-max-entry-count 0.8
```

### PyTorch-Engine (breitere Kompatibilität)

```bash
# Verwenden Sie die PyTorch-Engine für Modelle, die von TurboMind nicht unterstützt werden
lmdeploy serve api_server \
  mistralai/Mistral-7B-Instruct-v0.2 \
  --backend pytorch \
  --server-port 23333 \
  --server-name 0.0.0.0
```

### Startausgabe des Servers

```
[2024-01-01 12:00:00,000] INFO: Lade Modell: meta-llama/Meta-Llama-3-8B-Instruct
[2024-01-01 12:00:20,000] INFO: TurboMind-Engine initialisiert
[2024-01-01 12:00:20,000] INFO: Server gestartet unter http://0.0.0.0:23333
[2024-01-01 12:00:20,000] INFO: API-Dokumentation: http://0.0.0.0:23333/docs
```

{% hint style="success" %}
Nach dem Start stellt LMDeploy interaktive API-Dokumentation unter `http://<your-ip>:23333/docs` — nützlich zum direkten Testen von Endpunkten im Browser.
{% endhint %}

***

## Unterstützte Modelle

### Textmodelle

```bash
# Llama 3
meta-llama/Meta-Llama-3-8B-Instruct
meta-llama/Meta-Llama-3-70B-Instruct

# Mistral / Mixtral
mistralai/Mistral-7B-Instruct-v0.2
mistralai/Mixtral-8x7B-Instruct-v0.1

# Qwen
Qwen/Qwen2-7B-Instruct
Qwen/Qwen2-72B-Instruct

# InternLM
internlm/internlm2-chat-7b
internlm/internlm2-chat-20b

# Yi
01-ai/Yi-1.5-9B-Chat
01-ai/Yi-1.5-34B-Chat

# Gemma
google/gemma-7b-it
google/gemma-2b-it
```

### Vision-Language-Modelle

```bash
# InternVL (empfohlenes VLM)
OpenGVLab/InternVL2-8B
OpenGVLab/InternVL2-26B

# LLaVA
llava-hf/llava-1.5-7b-hf

# Qwen-VL
Qwen/Qwen-VL-Chat
```

***

## Quantisierung

### AWQ 4-Bit-Quantisierung

LMDeploys AWQ (Activation-aware Weight Quantization) liefert hervorragende Qualität bei 4 Bit:

```bash
# Modell auf AWQ 4-Bit quantisieren
lmdeploy lite auto_awq \
  meta-llama/Meta-Llama-3-8B-Instruct \
  --calib-dataset ptb \
  --calib-samples 128 \
  --calib-seqlen 2048 \
  --w-bits 4 \
  --w-group-size 128 \
  --work-dir ./quantized/llama3-8b-awq

# Das quantisierte Modell bereitstellen
lmdeploy serve api_server \
  ./quantized/llama3-8b-awq \
  --server-port 23333 \
  --server-name 0.0.0.0
```

### SmoothQuant W8A8

8-Bit-Quantisierung von Gewichten und Aktivierungen (besser für deployments mit hohem Durchsatz):

```bash
lmdeploy lite smooth_quant \
  meta-llama/Meta-Llama-3-8B-Instruct \
  --work-dir ./quantized/llama3-8b-sq \
  --calib-dataset ptb \
  --calib-samples 512
```

### Auswirkung der Quantisierung

| Quantisierung    | VRAM (7B) | Qualitätsverlust | Durchsatzgewinn |
| ---------------- | --------- | ---------------- | --------------- |
| Keine (bf16)     | \~14 GB   | Keine            | Basiswert       |
| SmoothQuant W8A8 | \~8 GB    | Minimal          | +20%            |
| AWQ W4A16        | \~4 GB    | Niedrig          | +15%            |
| GPTQ W4A16       | \~4 GB    | Niedrig          | +10%            |

{% hint style="info" %}
**AWQ-Empfehlung:** Für die meisten Anwendungsfälle ist AWQ 4-Bit der beste Kompromiss aus Qualität und VRAM-Einsparung. Verwenden Sie `--w-group-size 128` für bessere Qualität bei etwas höherem Speicherverbrauch.
{% endhint %}

***

## API-Verwendungsbeispiele

### Python-Client

```python
from openai import OpenAI

client = OpenAI(
    base_url="http://<clore-node-ip>:<api-port>/v1",
    api_key="none"
)

# Chat-Vervollständigung
response = client.chat.completions.create(
    model="llama3-8b",
    messages=[
        {"role": "system", "content": "Du bist ein hilfreicher Assistent."},
        {"role": "user", "content": "Fasse die Geschichte der KI in 3 Sätzen zusammen."}
    ],
    temperature=0.7,
    max_tokens=512
)
print(response.choices[0].message.content)
```

### Streaming

```python
stream = client.chat.completions.create(
    model="llama3-8b",
    messages=[{"role": "user", "content": "Schreibe ein Gedicht über den Weltraum."}],
    stream=True
)

for chunk in stream:
    delta = chunk.choices[0].delta
    if delta.content:
        print(delta.content, end="", flush=True)
print()
```

### LMDeploy nativer Python-Client

```python
from lmdeploy import pipeline, TurbomindEngineConfig

# Direkte Pipeline (kein Server erforderlich)
pipe = pipeline(
    'meta-llama/Meta-Llama-3-8B-Instruct',
    backend_config=TurbomindEngineConfig(max_batch_size=16)
)

# Einzelne Inferenz
response = pipe("Was ist die Hauptstadt von Frankreich?")
print(response.text)

# Batch-Inferenz
responses = pipe([
    "Erkläre die Schwerkraft",
    "Was ist DNA?",
    "Wie funktioniert Bitcoin?"
])
for r in responses:
    print(r.text)
    print("---")
```

### Vision-Language-Modell

```python
from lmdeploy import pipeline
from lmdeploy.vl import load_image

pipe = pipeline('OpenGVLab/InternVL2-8B')

image = load_image('https://example.com/photo.jpg')
response = pipe(('Beschreibe dieses Bild detailliert', image))
print(response.text)
```

***

## Multi-GPU-Bereitstellung

### Tensor-Parallelismus

```bash
# Verteile ein 70B-Modell auf 4 GPUs
lmdeploy serve api_server \
  meta-llama/Meta-Llama-3-70B-Instruct \
  --backend turbomind \
  --server-port 23333 \
  --server-name 0.0.0.0 \\
  --tp 4 \
  --max-batch-size 64
```

```python
from lmdeploy import pipeline, TurbomindEngineConfig

pipe = pipeline(
    'meta-llama/Meta-Llama-3-70B-Instruct',
    backend_config=TurbomindEngineConfig(tp=4)
)
```

***

## Erweiterte Konfiguration

### TurboMind-Engine-Konfiguration

```python
from lmdeploy import pipeline, TurbomindEngineConfig

engine_config = TurbomindEngineConfig(
    max_batch_size=64,          # Maximale gleichzeitige Anfragen
    cache_max_entry_count=0.8,  # KV-Cache-Anteil (0.0-1.0)
    quant_policy=0,             # 0=keine Quantisierung, 4=4-Bit-KV-Cache, 8=8-Bit-KV-Cache
    rope_scaling_factor=1.0,    # Für erweiterten Kontext
    num_tokens_per_iter=4096,   # Prefill-Chunk-Größe
    max_prefill_token_num=8192, # Maximale Prefill-Länge
)

pipe = pipeline('meta-llama/Meta-Llama-3-8B-Instruct', backend_config=engine_config)
```

### Generierungs-Konfiguration

```python
from lmdeploy import GenerationConfig

gen_config = GenerationConfig(
    temperature=0.7,
    top_p=0.9,
    top_k=40,
    repetition_penalty=1.1,
    max_new_tokens=1024,
    stop_words=['<|eot_id|>', '<|end_of_text|>'],
)

response = pipe("Hallo, Welt!", gen_config=gen_config)
```

***

## Überwachung & Metriken

### Serverzustand prüfen

```bash
# Health-Check-Endpunkt
curl http://localhost:23333/health

# Verfügbare Modelle auflisten
curl http://localhost:23333/v1/models

# Serverstatistiken
curl http://localhost:23333/stats
```

### GPU-Überwachung

```bash
# GPU-Statistiken in Echtzeit
watch -n 1 'nvidia-smi --query-gpu=name,memory.used,memory.free,utilization.gpu --format=csv'
```

***

## Docker-Compose-Beispiel

```yaml
version: '3.8'
services:
  lmdeploy:
    image: openmmlab/lmdeploy:latest
    runtime: nvidia
    environment:
      - NVIDIA_VISIBLE_DEVICES=all
      - HUGGING_FACE_HUB_TOKEN=${HF_TOKEN}
    ports:
      - "23333:23333"
      - "22:22"
    volumes:
      - hf-cache:/root/.cache/huggingface
      - ./models:/models
    command: >
      lmdeploy serve api_server
      meta-llama/Meta-Llama-3-8B-Instruct
      --server-port 23333
      --server-name 0.0.0.0
      --model-name llama3-8b
      --max-batch-size 64
    restart: unless-stopped
    shm_size: '2g'

volumes:
  hf-cache:
```

***

## Benchmarking

```bash
# Integriertes Benchmark-Tool
lmdeploy benchmark \
  meta-llama/Meta-Llama-3-8B-Instruct \
  --backend turbomind \
  --concurrency 1 4 8 16 32 \
  --num-prompts 1000 \
  --prompt-len 128 \
  --output-len 256
```

Beispielausgabe (RTX 4090, TurboMind, bf16):

```
concurrency=1:  throughput=42.3 tokens/s, latency_p50=23ms
concurrency=8:  throughput=287.1 tokens/s, latency_p50=156ms
concurrency=32: throughput=412.6 tokens/s, latency_p50=621ms
```

Auf einer A100 80GB ist bei hoher Parallelität im Vergleich zur RTX 4090 ein etwa 2,2× höherer Durchsatz zu erwarten, aufgrund der HBM2e-Speicherbandbreite (2 TB/s vs. 1 TB/s).

***

## GPU-Empfehlungen für Clore.ai

Wählen Sie basierend auf Ihrer Zielmodellgröße und Auslastung des Bereitstellungsdienstes:

| Anwendungsfall                     | GPU           | VRAM  | Warum                                                                     |
| ---------------------------------- | ------------- | ----- | ------------------------------------------------------------------------- |
| 7–13B-Modelle, Entwicklung/Staging | **RTX 3090**  | 24 GB | Bestes Preis/VRAM-Verhältnis; verarbeitet 7B bf16 oder 13B AWQ            |
| 7–13B-Modelle, Produktion          | **RTX 4090**  | 24 GB | \~40 % schneller als die 3090 bei gleichem VRAM; 412 tok/s auf Llama 3 8B |
| 70B-Modelle, Team-Bereitstellung   | **A100 40GB** | 40 GB | Passt für 70B AWQ; ECC-Speicher für Zuverlässigkeit                       |
| 70B-Modelle, hoher Durchsatz       | **A100 80GB** | 80 GB | Passt für 70B bf16; 2× Durchsatz gegenüber A100 40GB bei batch=32         |

**Budget-Empfehlung:** RTX 3090 + AWQ 4-Bit — bedient Llama 3 8B mit \~280 tok/s bei batch=8 und deckt die meisten API-Anwendungsfälle ab.

**Geschwindigkeits-Empfehlung:** RTX 4090 — das schnellste Preis-Leistungs-Verhältnis für 7–13B-Modelle; TurboMind holt jede GB/s aus der 1 TB/s Bandbreite heraus.

**Produktions-Empfehlung:** A100 80GB — Qwen2-72B oder Llama 3 70B in vollem bf16 ohne Qualitätseinbußen durch Quantisierung ausführen; passt problemlos in Multi-Instance-GPU-Bereitstellung.

***

## Fehlerbehebung

### Modell wird nicht geladen

```bash
# Prüfen, ob das HuggingFace-Token gesetzt ist
echo $HUGGING_FACE_HUB_TOKEN

# Modell manuell herunterladen
pip install huggingface_hub
huggingface-cli download meta-llama/Meta-Llama-3-8B-Instruct --local-dir ./llama3-8b

# Stattdessen lokalen Pfad verwenden
lmdeploy serve api_server ./llama3-8b --server-port 23333
```

### CUDA Out of Memory

```bash
# KV-Cache-Zuweisung reduzieren
lmdeploy serve api_server MODEL \
  --cache-max-entry-count 0.5  # Verringert von 0.8

# Quantisierten KV-Cache verwenden
lmdeploy serve api_server MODEL \
  --quant-policy 8  # 8-Bit-KV-Cache
```

### Port bereits in Verwendung

```bash
# Prüfen, was Port 23333 verwendet
ss -tlnp | grep 23333
fuser 23333/tcp

# Bestehenden Prozess beenden
kill -9 $(fuser 23333/tcp)
```

{% hint style="warning" %}
**Docker-Netzwerkmodus:** Wenn Sie in Docker ausführen, stellen Sie sicher, dass der Container `--network host` oder korrektes Port-Mapping (`-p 23333:23333`) verwendet, damit die API von außen erreichbar ist.
{% endhint %}

***

## GPU-Empfehlungen für Clore.ai

Die TurboMind-Engine und die W4A16-Quantisierung von LMDeploy liefern branchenführenden Durchsatz — besonders auf Ampere-/Hopper-GPUs.

| GPU         | VRAM  | Clore.ai-Preis                            | Llama 3 8B-Durchsatz               | Llama 3 70B Q4     |
| ----------- | ----- | ----------------------------------------- | ---------------------------------- | ------------------ |
| RTX 3090    | 24 GB | ca. 0,07–0,21 $/h                         | \~120 tok/s (fp16)                 | ❌ Zu groß          |
| RTX 4090    | 24 GB | ca. 0,14–0,42 $/h                         | \~200 tok/s (fp16)                 | ❌ Zu groß          |
| A100 40GB   | 40 GB | [Bare Metal](https://clore.ai/bare-metal) | \~160 tok/s (fp16)                 | \~55 tok/s (W4A16) |
| A100 80GB   | 80 GB | [Bare Metal](https://clore.ai/bare-metal) | \~175 tok/s (fp16)                 | \~80 tok/s (fp16)  |
| 2× RTX 4090 | 48 GB | $0.28–0.84/Std.                           | \~380 tok/s (Tensor-Parallelismus) | \~60 tok/s         |

{% hint style="info" %}
**RTX 3090 für 0,07–0,21 $/Std.** ist die Top-Wahl für 7B–13B-Modelle. Die TurboMind-Engine von LMDeploy holt nahezu maximalen Durchsatz aus Consumer-GPUs heraus. Eine einzelne RTX 3090, die Llama 3 8B bereitstellt, schafft 120 tok/s — ausreichend für Produktions-APIs mit 10–20 gleichzeitigen Nutzern.

Für 70B-Modelle: A100 40GB ([Bare Metal](https://clore.ai/bare-metal)) mit W4A16-Quantisierung liefert \~55 tok/s — kosteneffizienter als zwei RTX 4090s.
{% endhint %}

***

## Ressourcen

* 📦 **Docker Hub:** [hub.docker.com/r/openmmlab/lmdeploy](https://hub.docker.com/r/openmmlab/lmdeploy)
* 🐙 **GitHub:** [github.com/InternLM/lmdeploy](https://github.com/InternLM/lmdeploy)
* 📚 **Dokumentation:** [lmdeploy.readthedocs.io](https://lmdeploy.readthedocs.io)
* 💬 **Discord:** [discord.gg/xa29JuW84p](https://discord.gg/xa29JuW84p)
* 🤗 **Vorquantisierte Modelle:** [huggingface.co/lmdeploy](https://huggingface.co/lmdeploy)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.clore.ai/guides/guides_v2-de/sprachmodelle/lmdeploy.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
