> 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 Toolkit zur Bereitstellung von LLMs vom Shanghai AI Lab** — inference, Quantisierung und Serving in Produktionsqualität für große Sprachmodelle mit kontinuierlicher Bündelung 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 Servieren großer Sprachmodelle in der Produktion. Entwickelt vom selben Team hinter OpenMMLab (MMDetection, MMSeg), bringt es forschungsnahe Optimierungen in die praktische Bereitstellung:

* **TurboMind-Engine** — leistungsstarkes C++-Inference-Backend mit CUDA-Optimierungen
* **PyTorch-Engine** — flexibles, Python-basiertes Engine für breite Modellkompatibilität
* **Kontinuierliches Batching** — maximiert die GPU-Auslastung bei gleichzeitigen Anfragen
* **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 etwa 1,36× höheren Durchsatz auf Llama 3 8B bei batch=32, und seine AWQ-Quantisierung ist erstklassig — kein Nachgedanke. Für VLMs (insbesondere InternVL2) ist LMDeploy der Referenz-Deployment-Stack.

### Warum LMDeploy?

| Funktion                              | LMDeploy | vLLM     | TGI      |
| ------------------------------------- | -------- | -------- | -------- |
| Kontinuierliches Batching             | ✅        | ✅        | ✅        |
| AWQ-Quantisierung                     | ✅        | ✅        | ❌        |
| Spekulatives Decoding                 | ✅        | ✅        | ✅        |
| 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:

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

### Schritt 2: LMDeploy Docker bereitstellen

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

**Port-Mappings:**

| 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: SSH und Überprüfung

```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
```

### Server-Startausgabe

```
[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" %}
Sobald gestartet, stellt LMDeploy interaktive API-Dokumentation bereit unter `http://<your-ip>:23333/docs` — nützlich, um Endpunkte direkt aus dem Browser zu testen.
{% 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 exzellente Qualität bei 4 Bit:

```bash
# Ein Modell mit 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-Gewichts- und Aktivierungsquantisierung (besser für durchsatzkritische Deployments):

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

### Auswirkungen der Quantisierung

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

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

***

## API-Nutzungsbeispiele

### Python-Client

```python
from openai import OpenAI

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

# Chat-Completion
response = client.chat.completions.create(
    model="llama3-8b",
    messages=[
        {"role": "system", "content": "You are a helpful assistant."},
        {"role": "user", "content": "Summarize the history of AI in 3 sentences."}
    ],
    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": "Write a poem about space."}],
    stream=True
)

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

### LMDeploy Native 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("What is the capital of France?")
print(response.text)

# Batch-Inferenz
responses = pipe([
    "Explain gravity",
    "What is DNA?",
    "How does Bitcoin work?"
])
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(('Describe this image in detail', image))
print(response.text)
```

***

## Multi-GPU-Bereitstellung

### Tensor-Parallellität

```bash
# Ein 70B-Modell auf 4 GPUs verteilen
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-Verhältnis (0.0-1.0)
    quant_policy=0,             # 0=keine Quantisierung, 4=4bit KV-Cache, 8=8bit 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("Hello, world!", gen_config=gen_config)
```

***

## Überwachung & Metriken

### Server-Health prüfen

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

# Liste verfügbare Modelle auf
curl http://localhost:23333/v1/models

# Server-Statistiken
curl http://localhost:23333/stats
```

### GPU-Überwachung

```bash
# Echtzeit-GPU-Statistiken
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
# Eingebautes 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 erwartet man bei hoher Parallelität etwa 2,2× höheren Durchsatz gegenüber einer RTX 4090 wegen der HBM2e-Speicherbandbreite (2 TB/s vs. 1 TB/s).

***

## Clore.ai GPU-Empfehlungen

Wählen Sie basierend auf der Zielmodellgröße und der Serving-Last:

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

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

**Geschwindigkeits-Wahl:** RTX 4090 — am schnellsten pro Dollar für 7–13B-Modelle; TurboMind holt jede GB/s aus seiner 1 TB/s-Bandbreite heraus.

**Produktions-Wahl:** A100 80GB — betreiben Sie Qwen2-72B oder Llama 3 70B vollständig in bf16 ohne Qualitätskompromisse durch Quantisierung; passt leicht in Multi-Instance-GPU-Serving.

***

## Fehlerbehebung

### Modell wird nicht geladen

```bash
# Überprüfen Sie, ob 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

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

### CUDA Out of Memory

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

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

### Port bereits in Gebrauch

```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:** Beim Ausführen in Docker stellen Sie sicher, dass der Container `--network host` oder korrektes Port-Mapping verwendet (`-p 23333:23333`) damit die API von außen erreichbar ist.
{% endhint %}

***

## Clore.ai GPU-Empfehlungen

LMDeploys TurboMind-Engine und W4A16-Quantisierung liefern branchenführenden Durchsatz — insbesondere auf Ampere-/Hopper-GPUs.

| GPU         | VRAM  | Clore.ai-Preis | Durchsatz Llama 3 8B               | Llama 3 70B Q4     |
| ----------- | ----- | -------------- | ---------------------------------- | ------------------ |
| RTX 3090    | 24 GB | \~$0.12/Stunde | \~120 tok/s (fp16)                 | ❌ Zu groß          |
| RTX 4090    | 24 GB | \~$0.70/Stunde | \~200 tok/s (fp16)                 | ❌ Zu groß          |
| A100 40GB   | 40 GB | \~$1.20/Stunde | \~160 tok/s (fp16)                 | \~55 tok/s (W4A16) |
| A100 80GB   | 80 GB | \~$2.00/Stunde | \~175 tok/s (fp16)                 | \~80 tok/s (fp16)  |
| 2× RTX 4090 | 48 GB | \~$1.40/std    | \~380 tok/s (Tensor-Parallellität) | \~60 tok/s         |

{% hint style="info" %}
**RTX 3090 bei \~$0.12/std** ist die beste Wahl für 7B–13B-Modelle. LMDeploys TurboMind-Engine holt nahezu maximalen Durchsatz aus Consumer-GPUs. Eine einzelne RTX 3090, die Llama 3 8B bedient, verarbeitet 120 tok/s — ausreichend für Produktions-APIs mit 10–20 gleichzeitigen Nutzern.

Für 70B-Modelle: A100 40GB (\~$1.20/std) mit W4A16-Quantisierung liefert \~55 tok/s — kosteneffektiver als zwei RTX 4090.
{% 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:

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

The question should be specific, self-contained, and written in natural language.
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.
