> 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/mlc-llm.md).

# MLC-LLM

**Universelle LLM-Bereitstellung durch ML-Kompilierung** — Führen Sie jedes große Sprachmodell auf jeder Hardware mit maximaler Leistung mithilfe von Machine-Learning-Kompilierung aus.

> 🌟 **20.000+ GitHub-Sterne** | Wird vom MLC AI Team gewartet | Apache-2.0-Lizenz

***

## Was ist MLC-LLM?

MLC-LLM (Machine Learning Compilation for Large Language Models) ist ein universelles Framework, das die effiziente Bereitstellung großer Sprachmodelle über verschiedene Hardware-Backends ermöglicht. Durch die Nutzung von **TVM (Tensor Virtual Machine)** als Kompilierungs-Backend kompiliert MLC-LLM LLM-Modelle direkt in nativen Hardware-Code — und erreicht dabei nahezu optimale Leistung ohne hardware-spezifische Entwicklung.

### Wesentliche Fähigkeiten

* **Universelle Hardware-Unterstützung** — NVIDIA CUDA, AMD ROCm, Apple Metal, Vulkan, WebGPU
* **OpenAI-kompatible REST-API** — Drop-in-Ersatz für bestehende Workflows
* **Mehrere Modellformate** — Llama, Mistral, Gemma, Phi, Qwen, Falcon und mehr
* **4-Bit- / 8-Bit-Quantisierung** — Führen Sie große Modelle auf Consumer-GPUs aus
* **Chat-Oberfläche** — Eingebaute Web-UI für sofortige Tests
* **Python- & CLI-Tools** — Flexible Integrationsmöglichkeiten

### Warum MLC-LLM auf Clore.ai verwenden?

Der Clore.ai GPU-Marktplatz bietet Zugriff auf leistungsstarke NVIDIA-GPUs zu wettbewerbsfähigen Mietpreisen. Der Kompilierungsansatz von MLC-LLM maximiert den Durchsatz jeder GPU — ideal für:

* Produktive API-Inferenz in großem Maßstab
* Forschung und Benchmarking über Modellgrößen hinweg
* Kosteneffizientes Serving mit quantisierten Modellen
* Bereitstellung mehrerer Modelle auf einer einzigen GPU-Instanz

***

## Schnellstart auf Clore.ai

### Schritt 1: Finden Sie einen GPU-Server

1. Gehe zu [clore.ai](https://clore.ai) Marktplatz
2. Server filtern: **NVIDIA GPU**, Mindest- **8 GB VRAM** (16 GB+ empfohlen für 7B+ Modelle)
3. Für optimale Leistung: RTX 3090, RTX 4090, A100 oder H100

### Schritt 2: MLC-LLM bereitstellen

{% hint style="info" %}
**Hinweis:** MLC-LLM veröffentlicht kein offizielles vorkompiliertes Docker-Image auf Docker Hub. Der empfohlene Bereitstellungsansatz besteht darin, ein NVIDIA CUDA-Basisimage zu verwenden und MLC-LLM über pip zu installieren. Verwenden Sie `nvidia/cuda:12.1.0-devel-ubuntu22.04` als Ihr Basisimage auf Clore.ai.
{% endhint %}

Verwenden Sie ein NVIDIA CUDA-Basisimage in Ihrer Clore.ai-Bestellkonfiguration:

```
Docker-Image: nvidia/cuda:12.1.0-devel-ubuntu22.04
```

**Port-Mappings:**

| Container-Port | Zweck           |
| -------------- | --------------- |
| `22`           | SSH-Zugriff     |
| `8000`         | REST-API-Server |

**Empfohlene Umgebungsvariablen:**

```
MLC_MODEL=HF://mlc-ai/Llama-3-8B-Instruct-q4f16_1-MLC
MLC_HOST=0.0.0.0
MLC_PORT=8000
```

**Startskript** (nach SSH ausführen):

```bash
pip install --pre -U -f https://mlc.ai/wheels mlc-llm-nightly-cu121 mlc-ai-nightly-cu121
```

### Schritt 3: Verbindung per SSH herstellen

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

***

## Installation & Einrichtung

### Option A: Verwenden Sie vorkompilierte Modelle (am schnellsten)

MLC-AI pflegt eine Bibliothek vorkompilierter Modelle auf Hugging Face. Keine Kompilierung erforderlich:

```bash
# Ziehen und starten Sie ein vorkompiliertes Llama 3 8B (4-Bit quantisiert)
python -m mlc_llm serve HF://mlc-ai/Llama-3-8B-Instruct-q4f16_1-MLC \
  --host 0.0.0.0 \
  --port 8000
```

### Option B: Kompilieren Sie Ihr eigenes Modell

Für benutzerdefinierte Modelle oder spezifische Quantisierungsanforderungen:

```bash
# Schritt 1: Modellgewichte konvertieren
python -m mlc_llm convert_weight \
  ./path/to/model \
  --quantization q4f16_1 \
  --output ./compiled/model-q4f16_1

# Schritt 2: Modellkonfiguration erzeugen
python -m mlc_llm gen_config \
  ./path/to/model \
  --quantization q4f16_1 \
  --conv-template llama-3 \
  --output ./compiled/model-q4f16_1

# Schritt 3: Das Modell kompilieren
python -m mlc_llm compile \
  ./compiled/model-q4f16_1/mlc-chat-config.json \
  --device cuda \
  --output ./compiled/model-q4f16_1/lib.so
```

{% hint style="info" %}
**Kompilierungszeit:** Das Kompilieren eines 7B-Modells dauert typischerweise beim ersten Lauf 10–30 Minuten. Kompilierte Artefakte werden zwischengespeichert und bei nachfolgenden Starts wiederverwendet.
{% endhint %}

***

## Den API-Server betreiben

### Starten Sie den OpenAI-kompatiblen Server

```bash
python -m mlc_llm serve \
  HF://mlc-ai/Llama-3-8B-Instruct-q4f16_1-MLC \
  --host 0.0.0.0 \
  --port 8000 \
  --max-batch-size 4 \
  --max-total-sequence-length 8192
```

### Server-Startausgabe

```
[2024-01-01 12:00:00] INFO: Lädt Modell von HF://mlc-ai/Llama-3-8B-Instruct-q4f16_1-MLC
[2024-01-01 12:00:15] INFO: Modell erfolgreich geladen
[2024-01-01 12:00:15] INFO: Starte Server auf 0.0.0.0:8000
[2024-01-01 12:00:15] INFO: OpenAI-kompatible API verfügbar unter http://0.0.0.0:8000/v1
```

### Verfügbare API-Endpunkte

| Endpunkt                     | Methode | Beschreibung                     |
| ---------------------------- | ------- | -------------------------------- |
| `/v1/chat/completions`       | POST    | Chat-Completions (OpenAI-Format) |
| `/v1/completions`            | POST    | Textvervollständigungen          |
| `/v1/models`                 | GET     | Liste verfügbarer Modelle        |
| `/v1/debug/dump_event_trace` | GET     | Performance-Debugging            |

***

## API-Nutzungsbeispiele

### Chat-Completions (Python)

```python
from openai import OpenAI

# Auf Ihren Clore.ai-Server verweisen
client = OpenAI(
    base_url="http://<clore-node-ip>:<api-port>/v1",
    api_key="none"  # MLC-LLM erfordert standardmäßig keine Authentifizierung
)

response = client.chat.completions.create(
    model="Llama-3-8B-Instruct-q4f16_1-MLC",
    messages=[
        {"role": "system", "content": "You are a helpful assistant."},
        {"role": "user", "content": "Erkläre Quantencomputing in einfachen Worten."}
    ],
    temperature=0.7,
    max_tokens=512
)

print(response.choices[0].message.content)
```

### Streaming-Antwort

```python
stream = client.chat.completions.create(
    model="Llama-3-8B-Instruct-q4f16_1-MLC",
    messages=[{"role": "user", "content": "Schreibe eine kurze Geschichte über KI."}],
    stream=True,
    max_tokens=1024
)

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

### cURL-Beispiel

```bash
curl http://<clore-node-ip>:<api-port>/v1/chat/completions \
  -H "Content-Type: application/json" \
  -d '{
    "model": "Llama-3-8B-Instruct-q4f16_1-MLC",
    "messages": [
      {"role": "user", "content": "Was ist 2+2?"}
    ],
    "temperature": 0.7,
    "max_tokens": 100
  }'
```

***

## Verfügbare vorkompilierte Modelle

MLC-AI stellt gebrauchsfertige kompilierte Modelle auf Hugging Face bereit:

### Llama 3-Serie

```bash
# 8B Instruct (für die meisten Anwendungsfälle empfohlen)
HF://mlc-ai/Llama-3-8B-Instruct-q4f16_1-MLC

# 70B Instruct (erfordert 40GB+ VRAM oder Multi-GPU)
HF://mlc-ai/Llama-3-70B-Instruct-q4f16_1-MLC
```

### Mistral / Mixtral

```bash
HF://mlc-ai/Mistral-7B-Instruct-v0.3-q4f16_1-MLC
HF://mlc-ai/Mixtral-8x7B-Instruct-v0.1-q4f16_1-MLC
```

### Gemma

```bash
HF://mlc-ai/gemma-2b-it-q4f16_1-MLC
HF://mlc-ai/gemma-7b-it-q4f16_1-MLC
```

### Phi

```bash
HF://mlc-ai/phi-2-q4f16_1-MLC
HF://mlc-ai/Phi-3-mini-4k-instruct-q4f16_1-MLC
```

{% hint style="success" %}
**Vollständige Modellliste:** Durchsuchen Sie alle vorkompilierten Modelle unter [huggingface.co/mlc-ai](https://huggingface.co/mlc-ai)
{% endhint %}

***

## Quantisierungsoptionen

MLC-LLM unterstützt mehrere Quantisierungsschemata. Wählen Sie entsprechend Ihrem VRAM-Budget:

| Quantisierung | Bits                         | Qualität | VRAM (7B) | VRAM (13B) |
| ------------- | ---------------------------- | -------- | --------- | ---------- |
| `q4f16_1`     | 4-Bit                        | ★★★★☆    | \~4GB     | \~7GB      |
| `q4f32_1`     | 4-Bit (f32 Akkumulation)     | ★★★★☆    | \~4GB     | \~7GB      |
| `q8f16_1`     | 8-Bit                        | ★★★★★    | \~8GB     | \~14GB     |
| `q0f16`       | 16-Bit (keine Quantisierung) | ★★★★★    | \~14GB    | \~26GB     |
| `q0f32`       | 32-Bit (keine Quantisierung) | ★★★★★    | \~28GB    | \~52GB     |

{% hint style="warning" %}
**VRAM-Empfehlung:** Lassen Sie immer 2–3 GB Puffer für CUDA-Overhead und KV-Cache. Ein 7B-Modell mit `q4f16_1` benötigt bei typischer Arbeitslast insgesamt \~6–7 GB.
{% endhint %}

***

## Multi-GPU-Bereitstellung

Für große Modelle (70B+), die mehrere GPUs erfordern:

```bash
# Aktivieren Sie Tensor-Parallelismus über 2 GPUs
python -m mlc_llm serve \
  HF://mlc-ai/Llama-3-70B-Instruct-q4f16_1-MLC \
  --host 0.0.0.0 \
  --port 8000 \
  --tensor-parallel-shards 2
```

Überprüfen Sie die GPU-Topologie vor der Bereitstellung:

```bash
nvidia-smi topo -m  # Überprüfen Sie NVLink/PCIe-Konnektivität
```

{% hint style="info" %}
**Beste Leistung:** Multi-GPU funktioniert am besten mit NVLink-verbundenen Karten (z. B. A100 80GB SXM-Paare). PCIe-verbundene GPUs zeigen bei großen Modellen Engpässe.
{% endhint %}

***

## Web-Chat-Oberfläche

MLC-LLM enthält eine eingebaute Web-UI, die zugänglich ist, sobald der Server läuft:

```bash
# Server mit aktivierter Web-UI starten
python -m mlc_llm serve \
  HF://mlc-ai/Llama-3-8B-Instruct-q4f16_1-MLC \
  --host 0.0.0.0 \
  --port 8000 \
  --enable-debug  # Optional: aktiviert Debug-Endpunkt
```

Greifen Sie auf die UI zu unter: `http://<clore-node-ip>:<api-port>`

***

## Performance-Tuning

### Optimieren Sie die Batch-Größe

```bash
# Erhöhen Sie die Batch-Größe für höheren Durchsatz (erfordert mehr VRAM)
python -m mlc_llm serve \
  HF://mlc-ai/Llama-3-8B-Instruct-q4f16_1-MLC \
  --host 0.0.0.0 \
  --port 8000 \
  --max-batch-size 8 \
  --max-total-sequence-length 16384 \
  --prefill-chunk-size 2048
```

### Überwachen Sie die GPU-Auslastung

```bash
# In einem separaten Terminal
watch -n 1 nvidia-smi

# Detailliertere Überwachung
nvidia-smi dmon -s u  # Streaming-Auslastungsmetriken
```

### Benchmark-Durchsatz

```python
import time
from openai import OpenAI

client = OpenAI(base_url="http://localhost:8000/v1", api_key="none")

start = time.time()
response = client.chat.completions.create(
    model="Llama-3-8B-Instruct-q4f16_1-MLC",
    messages=[{"role": "user", "content": "Zähle von 1 bis 100"}],
    max_tokens=512
)
elapsed = time.time() - start

tokens = response.usage.completion_tokens
print(f"Durchsatz: {tokens/elapsed:.1f} tokens/sec")
```

***

## Docker-Compose-Setup

Für eine produktionsbereite Bereitstellung auf Clore.ai unter Verwendung eines NVIDIA CUDA-Basisimages mit über pip installiertem MLC-LLM:

```yaml
version: '3.8'
services:
  mlc-llm:
    image: nvidia/cuda:12.1.0-devel-ubuntu22.04
    runtime: nvidia
    environment:
      - NVIDIA_VISIBLE_DEVICES=all
    ports:
      - "8000:8000"
    volumes:
      - ./models:/root/models
      - mlc-cache:/root/.cache/mlc_llm
    command: >
      bash -c "pip install --pre -U -f https://mlc.ai/wheels mlc-llm-nightly-cu121 mlc-ai-nightly-cu121 &&
      python -m mlc_llm serve
      HF://mlc-ai/Llama-3-8B-Instruct-q4f16_1-MLC
      --host 0.0.0.0
      --port 8000
      --max-batch-size 4"
    restart: unless-stopped

volumes:
  mlc-cache:
```

***

## Fehlerbehebung

### Modell-Download schlägt fehl

```bash
# Überprüfen Sie die Internetverbindung
curl -I https://huggingface.co

# Manuelles Herunterladen mit huggingface-cli
pip install huggingface_hub
huggingface-cli download mlc-ai/Llama-3-8B-Instruct-q4f16_1-MLC
```

### Nicht genügend Speicher (OOM)

```bash
# Reduzieren Sie die Kontextlänge
python -m mlc_llm serve MODEL \
  --max-total-sequence-length 4096  # Reduzieren gegenüber dem Standard

# Verwenden Sie aggressivere Quantisierung
# Wechseln Sie von q8f16_1 zu q4f16_1
```

### CUDA-Version stimmt nicht überein

```bash
# Überprüfen Sie die CUDA-Version
nvcc --version
nvidia-smi | grep CUDA

# Für CUDA 12.1-Server installieren:
pip install --pre -U -f https://mlc.ai/wheels mlc-llm-nightly-cu121 mlc-ai-nightly-cu121

# Für CUDA 12.2+-Server installieren:
pip install --pre -U -f https://mlc.ai/wheels mlc-llm-nightly-cu122 mlc-ai-nightly-cu122
```

{% hint style="danger" %}
**Häufiger Stolperstein:** MLC-LLM pip-Wheels sind CUDA-Versionsspezifisch. Stellen Sie sicher, dass Sie die korrekte Variante installieren, die zur CUDA-Version Ihres Servers passt. Prüfen Sie verfügbare Wheels auf [mlc.ai/wheels](https://mlc.ai/wheels).
{% endhint %}

### Server nicht erreichbar

```bash
# Prüfen Sie, ob der Port lauscht
ss -tlnp | grep 8000

# Prüfen Sie die Firewall
iptables -L -n | grep 8000

# Testen Sie zuerst lokal
curl http://localhost:8000/v1/models
```

***

## Clore.ai GPU-Empfehlungen

Der Kompilierungsansatz von MLC-LLM liefert nahezu optimalen Durchsatz auf jeder GPU-Klasse. Wählen Sie entsprechend Modellgröße und Budget:

| GPU       | VRAM  | Clore.ai-Preis | Am besten für                              | Durchsatz (Llama 3 8B Q4) |
| --------- | ----- | -------------- | ------------------------------------------ | ------------------------- |
| RTX 3090  | 24 GB | \~$0.12/Stunde | 7B–13B Modelle, budgetorientiertes Serving | \~85 tok/s                |
| RTX 4090  | 24 GB | \~$0.70/Stunde | 7B–34B Modelle, schnelles Serving          | \~140 tok/s               |
| A100 40GB | 40 GB | \~$1.20/Stunde | 34B–70B, Produktions-API                   | \~110 tok/s               |
| A100 80GB | 80 GB | \~$2.00/Stunde | 70B+, Multi-Model-Serving                  | \~130 tok/s               |
| H100 SXM  | 80 GB | \~$3.50/Stunde | Maximaler Durchsatz, FP8                   | \~280 tok/s               |

**Empfohlener Ausgangspunkt:** Die RTX 3090 zu etwa \~$0.12/Stunde bietet das beste Preis-Leistungs-Verhältnis für Llama 3 8B und Mistral 7B-Serving via MLC-LLM. Die kompilierten Kernel entziehen Consumer-GPUs nahezu maximale Auslastung.

Für 70B-Modelle (z. B. Llama 3 70B Q4): verwenden Sie A100 40GB (\~$1.20/Stunde) oder zwei RTX 3090s über Tensor-Parallelismus.

***

## Ressourcen

* 📦 **Pip-Wheels:** [mlc.ai/wheels](https://mlc.ai/wheels) (Installation via pip, kein Docker-Hub-Image verfügbar)
* 🐙 **GitHub:** [github.com/mlc-ai/mlc-llm](https://github.com/mlc-ai/mlc-llm)
* 📚 **Dokumentation:** [llm.mlc.ai/docs](https://llm.mlc.ai/docs)
* 🤗 **Vorkompilierte Modelle:** [huggingface.co/mlc-ai](https://huggingface.co/mlc-ai)
* 💬 **Discord:** [discord.gg/9Xpy2HGBuD](https://discord.gg/9Xpy2HGBuD)


---

# 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/mlc-llm.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.
