> 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/mistral-rs.md).

# Mistral.rs

**Blitzschnelle LLM-Inferenz in Rust geschrieben** — produktionsreifer Server mit GGUF-, GGML-, SafeTensors-Unterstützung und OpenAI-kompatibler API.

> 🦀 **In Rust entwickelt** für maximale Leistung | GGUF- & Vision-Modellunterstützung | Apache-2.0-Lizenz

***

## Was ist Mistral.rs?

Mistral.rs ist eine leistungsstarke LLM-Inferenz-Engine, die vollständig in **Rust**geschrieben ist. Ursprünglich auf Mistral-Modelle ausgerichtet, unterstützt sie jetzt die gesamte Landschaft moderner LLMs. Das Rust-Ökosystem bietet:

* **Kostenlose Abstraktionen** — keine Garbage-Collection-Pausen während der Inferenz
* **Speichersicherheit** — keine Nullzeiger-Ausnahmen oder Speicherlecks
* **Deterministische Leistung** — konsistente Latenz ohne JVM-/Python-Overhead
* **Kompilierungszeit-Optimierungen** — SIMD-, Threading- und GPU-Kerne zur Build-Zeit optimiert

### Hauptfunktionen

* **GGUF-Unterstützung** — führe jedes quantisierte Modell aus (Q4\_K\_M, Q8\_0, usw.)
* **ISQ (In-Situ-Quantisierung)** — quantisiere on-the-fly beim Laden
* **PagedAttention** — effizienter KV-Cache mit kontinuierlichem Batching
* **Vision Language Models** — LLaVA-, Phi-3 Vision-, Idefics-Unterstützung
* **Spekulatives Decoding** — schnellere Inferenz mit Draft-Modellen
* **X-LoRA** — skalierbare Unterstützung für feinabgestimmte Adapter
* **OpenAI-kompatible REST-API** — Drop-in-Ersatz

### Unterstützte Modellfamilien

| Familie         | Format            | Engine    |
| --------------- | ----------------- | --------- |
| Llama 2/3       | GGUF, SafeTensors | Rust CUDA |
| Mistral/Mixtral | GGUF, SafeTensors | Rust CUDA |
| Phi-2/3         | GGUF, SafeTensors | Rust CUDA |
| Gemma           | GGUF, SafeTensors | Rust CUDA |
| Qwen 2          | GGUF, SafeTensors | Rust CUDA |
| Starcoder 2     | GGUF              | Rust CUDA |
| LLaVA 1.5/1.6   | SafeTensors       | Vision    |
| Phi-3 Vision    | SafeTensors       | Vision    |

***

## Schnellstart auf Clore.ai

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

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

* **Minimum:** 8GB VRAM (für 7B Q4-Modelle)
* **Empfohlen:** RTX 3090/4090 (24GB) für größere Modelle
* CUDA 11.8+ erforderlich

### Schritt 2: Mistral.rs Docker bereitstellen

```
Docker-Image: ghcr.io/ericlbuehler/mistral.rs:cuda
```

**Port-Mappings:**

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

**Verfügbare Image-Varianten:**

```bash
# CUDA (die meisten Clore.ai-Server)
ghcr.io/ericlbuehler/mistral.rs:cuda

# Nur CPU
ghcr.io/ericlbuehler/mistral.rs:cpu

# Metal (Apple Silicon - nicht für Clore.ai)
ghcr.io/ericlbuehler/mistral.rs:metal
```

### Schritt 3: Verbinden und Überprüfen

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

# Überprüfe die mistral.rs-Binärdatei
mistralrs-server --help
```

***

## Den Server starten

### Schnellstart mit GGUF-Modell

```bash
# Diene ein GGUF-Modell direkt von HuggingFace aus
mistralrs-server \
  --port 8080 \
  --log info \
  gguf \
  -m TheBloke/Llama-2-7B-Chat-GGUF \
  -f llama-2-7b-chat.Q4_K_M.gguf
```

### Mistral 7B bereitstellen (SafeTensors)

```bash
mistralrs-server \
  --port 8080 \
  plain \
  -m mistralai/Mistral-7B-Instruct-v0.3 \
  --isq Q4K
```

### Mit In-Situ-Quantisierung (ISQ) bereitstellen

ISQ quantisiert das Modell zur Ladezeit — kein vorquantisiertes Modell erforderlich:

```bash
# Llama 3 8B laden und on-the-fly zu Q4K quantisieren
mistralrs-server \
  --port 8080 \
  plain \
  -m meta-llama/Meta-Llama-3-8B-Instruct \
  --isq Q4K

# Verfügbare ISQ-Optionen:
# Q4_0, Q4_1, Q5_0, Q5_1, Q8_0
# Q2K, Q3K, Q4K, Q5K, Q6K, Q8K
# HQQ4, HQQ8 (Half-Quadratic Quantization)
```

### Vision Language Model

```bash
mistralrs-server \
  --port 8080 \
  vision-plain \
  -m llava-hf/llava-1.5-7b-hf \
  --isq Q4K
```

### Spekulatives Decoding

```bash
# Verwende ein kleines Draft-Modell, um die Generierung zu beschleunigen
mistralrs-server \
  --port 8080 \
  speculative \
  -m meta-llama/Meta-Llama-3-8B-Instruct \
  --isq Q4K \
  -d meta-llama/Meta-Llama-3-1B-Instruct \
  --draft-isq Q4K \
  -n 5  # Spekulative Tokens
```

{% hint style="success" %}
**Spekulatives Decoding** kann eine **2–3× Beschleunigung** für die meisten konversationellen Workloads bieten, bei denen das kleine Draft-Modell die nächsten Tokens genau vorhersagt.
{% endhint %}

***

## API-Nutzung

### OpenAI-kompatible Endpunkte

| Endpunkt                 | Methode | Beschreibung                     |
| ------------------------ | ------- | -------------------------------- |
| `/v1/chat/completions`   | POST    | Chat-Vervollständigungen         |
| `/v1/completions`        | POST    | Textvervollständigungen          |
| `/v1/models`             | GET     | Modelle auflisten                |
| `/v1/images/generations` | POST    | Bildgenerierung (VLMs)           |
| `/v1/re_isq`             | POST    | Geladenes Modell re-quantisieren |
| `/health`                | GET     | Health-Check                     |

### Python-Beispiel

```python
from openai import OpenAI

client = OpenAI(
    base_url="http://<clore-node-ip>:<api-port>/v1",
    api_key="none"  # Standardmäßig keine Authentifizierung erforderlich
)

# Chat-Completion
response = client.chat.completions.create(
    model="llama-3-8b",  # Modellname ist flexibel
    messages=[
        {"role": "system", "content": "You are a helpful coding assistant."},
        {"role": "user", "content": "Schreibe eine Python-Funktion, um eine einfach verkettete Liste umzukehren"}
    ],
    temperature=0.1,  # Niedrige Temperatur für Codegenerierung
    max_tokens=1024
)
print(response.choices[0].message.content)
```

### Streaming-Antwort

```python
with client.chat.completions.create(
    model="llama-3-8b",
    messages=[{"role": "user", "content": "Erzähl mir eine Geschichte über einen Roboter."}],
    stream=True,
    max_tokens=512
) als Stream:
    for chunk in stream:
        delta = chunk.choices[0].delta
        if hasattr(delta, 'content') and delta.content:
            print(delta.content, end="", flush=True)
print()
```

### Vision-/Bild-Eingabe

```python
import base64
from pathlib import Path

# Bild laden
image_data = base64.b64encode(Path("photo.jpg").read_bytes()).decode()

response = client.chat.completions.create(
    model="llava-1.5-7b",
    messages=[
        {
            "role": "user",
            "content": [
                {
                    "type": "image_url",
                    "image_url": {
                        "url": f"data:image/jpeg;base64,{image_data}"
                    }
                },
                {
                    "type": "text",
                    "text": "Was siehst du auf diesem Bild?"
                }
            ]
        }
    ]
)
print(response.choices[0].message.content)
```

### cURL-Beispiele

```bash
# Basis-Chat
curl http://localhost:8080/v1/chat/completions \\
  -H "Content-Type: application/json" \
  -d '{
    "model": "mistral-7b",
    "messages": [{"role": "user", "content": "Was ist Rust?"}],
    "temperature": 0.7,
    "max_tokens": 256
  }'

# Modelle auflisten
curl http://localhost:8080/v1/models

# Health-Check
curl http://localhost:8080/health
```

***

## Konfigurationsoptionen

### Server-Flags

```bash
mistralrs-server \
  --port 8080 \                    # API-Port (Standard: 1234)
  --host 0.0.0.0 \                 # Bind-Adresse
  --log info \                     # Log-Level: off/error/warn/info/debug/trace
  --token-source env:HF_TOKEN \    # HuggingFace Token-Quelle
  --max-seqs 16 \                  # Maximale gleichzeitige Sequenzen
  --no-paged-attn \                # Deaktiviere PagedAttention (für Debugging verwenden)
  --prefix-cache-n 16 \            # Prefix-Cache-Einträge
  plain \                          # Modelltyp-Subbefehl
  -m meta-llama/Meta-Llama-3-8B-Instruct \
  --isq Q4K
```

### ISQ-Quantisierungsreferenz

| ISQ-Option | Bits | Qualität | VRAM (7B) |
| ---------- | ---- | -------- | --------- |
| `Q2K`      | 2    | ★★☆☆☆    | \~2,5GB   |
| `Q3K`      | 3    | ★★★☆☆    | \~3,5GB   |
| `Q4_0`     | 4    | ★★★★☆    | \~4,5GB   |
| `Q4K`      | 4    | ★★★★☆    | \~4,5GB   |
| `Q5K`      | 5    | ★★★★★    | \~5,5GB   |
| `Q6K`      | 6    | ★★★★★    | \~6,5GB   |
| `Q8_0`     | 8    | ★★★★★    | \~8GB     |
| `HQQ4`     | 4    | ★★★★☆    | \~4,5GB   |
| `HQQ8`     | 8    | ★★★★★    | \~8GB     |

{% hint style="info" %}
**HQQ (Half-Quadratic Quantization)** erzielt oft bessere Qualität als GGUF Q4 auf demselben Bit-Level, insbesondere bei auf Anweisungen folgenden Aufgaben.
{% endhint %}

***

## Erweiterte Funktionen

### X-LoRA (Mixture of LoRA Adapters)

Führe mehrere feinabgestimmte Adapter aus, die dynamisch pro Token ausgewählt werden:

```bash
mistralrs-server \
  --port 8080 \
  x-lora-plain \
  -m meta-llama/Meta-Llama-3-8B-Instruct \
  --isq Q4K \
  -x ./xlora-config.json
```

### Re-Quantisierung zur Laufzeit

```bash
# Quantisierung ändern, ohne neu zu starten
curl http://localhost:8080/v1/re_isq \
  -H "Content-Type: application/json" \
  -d '{"isq_type": "Q8_0"}'
```

### Anfrageprotokollierung

```bash
# Anfrageprotokollierung in Datei aktivieren
mistralrs-server \
  --port 8080 \
  --log info \
  --request-logging-file ./requests.jsonl \
  plain \
  -m meta-llama/Meta-Llama-3-8B-Instruct \
  --isq Q4K
```

***

## Performance-Tuning

### Für Durchsatz optimieren

```bash
# Höhere max-seqs für gleichzeitige Anfragen
mistralrs-server \
  --port 8080 \
  --max-seqs 32 \
  plain \
  -m meta-llama/Meta-Llama-3-8B-Instruct \
  --isq Q4K
```

### Für niedrige Latenz optimieren

```bash
# Niedrigere max-seqs, Prefix-Cache-Sharing deaktivieren
mistralrs-server \
  --port 8080 \
  --max-seqs 4 \
  --prefix-cache-n 0 \
  plain \
  -m meta-llama/Meta-Llama-3-8B-Instruct \
  --isq Q4K
```

### Leistung überwachen

```bash
# GPU-Auslastung während der Inferenz beobachten
watch -n 1 nvidia-smi

# Mit nvtop profilieren
apt-get install nvtop && nvtop
```

***

## Docker Compose

```yaml
version: '3.8'
services:
  mistral-rs:
    image: ghcr.io/ericlbuehler/mistral.rs:cuda
    runtime: nvidia
    environment:
      - NVIDIA_VISIBLE_DEVICES=all
      - HF_TOKEN=${HUGGING_FACE_HUB_TOKEN}
    ports:
      - "8080:8080"
    volumes:
      - hf-cache:/root/.cache/huggingface
    command: >
      mistralrs-server
      --port 8080
      --host 0.0.0.0
      --log info
      --max-seqs 16
      --token-source env:HF_TOKEN
      plain
      -m meta-llama/Meta-Llama-3-8B-Instruct
      --isq Q4K
    restart: unless-stopped

volumes:
  hf-cache:
```

***

## Vom Quellcode bauen

Falls das Docker-Image nicht zu deiner CUDA-Version passt:

```bash
# Rust installieren
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
source ~/.cargo/env

# Klonen und bauen
git clone https://github.com/EricLBuehler/mistral.rs.git
cd mistral.rs

# Baue mit CUDA-Unterstützung
cargo build --release --features cuda

# Speicherort der Binärdatei
./target/release/mistralrs-server --help
```

{% hint style="warning" %}
**Build-Zeit:** Rust-Kompilierung ist langsam. Rechne mit 10–20 Minuten für einen kompletten Build. Verwende `sccache` um inkrementelle Builds zu beschleunigen: `cargo install sccache && RUSTC_WRAPPER=sccache cargo build --release --features cuda`
{% endhint %}

***

## Fehlerbehebung

### CUDA-Bibliothek nicht gefunden

```bash
# Überprüfe CUDA-Bibliotheken
ldconfig -p | grep libcuda
ls /usr/local/cuda/lib64/

# Bibliothekspfad setzen
export LD_LIBRARY_PATH=/usr/local/cuda/lib64:$LD_LIBRARY_PATH
```

### Modell-Download schlägt fehl

```bash
# HuggingFace-Token setzen
export HF_TOKEN=dein_token_hier

# Oder verwende das --token-source-Flag
mistralrs-server \
  --token-source env:HF_TOKEN \
  ...

# Oder zuerst manuell herunterladen
huggingface-cli download meta-llama/Meta-Llama-3-8B-Instruct --local-dir ./llama3-8b
mistralrs-server ... plain -m ./llama3-8b --isq Q4K
```

### Port 8080 in Benutzung

```bash
# Prozess finden und beenden
fuser -k 8080/tcp

# Anderen Port verwenden
mistralrs-server --port 9090 ...
```

### Während der Quantisierung kein Speicher mehr

```bash
# ISQ quantisiert auf der GPU — reduziere zuerst andere GPU-Auslastung
# Oder wechsle zu GGUF (vorquantisiert, geringerer Spitzenverbrauch)
mistralrs-server \
  gguf \
  -m TheBloke/Llama-2-7B-Chat-GGUF \
  -f llama-2-7b-chat.Q4_K_M.gguf
```

{% hint style="danger" %}
**ISQ vs GGUF:** ISQ quantisiert zur Ladezeit unter Verwendung von GPU-Speicher (vorübergehender Spitzenverbrauch). Wenn du wenig VRAM hast, verwende vorquantisierte GGUF-Dateien von TheBloke oder ähnlichen — sie benötigen während des Ladens weniger Spitzenmemory.
{% endhint %}

***

## Clore.ai GPU-Empfehlungen

Mistral.rs ist eine native Rust-Engine — ihr geringer Overhead bedeutet, dass du mehr Durchsatz pro GPU-Dollar im Vergleich zu Python-basierten Servern erhältst.

| GPU       | VRAM  | Clore.ai-Preis | Empfohlene Verwendung                          | Durchsatz (Mistral 7B Q4) |
| --------- | ----- | -------------- | ---------------------------------------------- | ------------------------- |
| RTX 3090  | 24 GB | \~$0.12/Stunde | Beste Budget-Option — 7B Q4/Q8, Vision-Modelle | \~120 tok/s               |
| RTX 4090  | 24 GB | \~$0.70/Stunde | Hoher Durchsatz 7B–34B, spekulatives Decoding  | \~200 tok/s               |
| A100 40GB | 40 GB | \~$1.20/Stunde | Produktionsbetrieb 34B–70B Q4-Serving          | \~160 tok/s               |
| A100 80GB | 80 GB | \~$2.00/Stunde | Volle Präzision 70B, Multi-Modell              | \~185 tok/s               |

**Warum die RTX 3090 hier glänzt:** Die Rust CUDA-Kerne von Mistral.rs vermeiden Python-GIL-Overhead und Garbage-Collection-Pausen, die Python-Server beeinträchtigen. Eine RTX 3090, die Mistral 7B Q4\_K\_M ausführt, liefert \~\~120 tok/s — vergleichbar mit vLLM auf derselben Hardware zu einem Bruchteil der Kosten (\~\~0,12 $/Std. vs. Cloud-Anbieter, die 1–2 $/Std. berechnen).

**Spekulatives Decoding:** Kombiniere ein großes Modell (34B) mit einem kleinen Draft-Modell (3B) für 2–3× Beschleunigung ohne Qualitätsverlust. Die RTX 4090 ist ideal für dieses Muster.

***

## Ressourcen

* 🐙 **GitHub:** [github.com/EricLBuehler/mistral.rs](https://github.com/EricLBuehler/mistral.rs)
* 📦 **Container-Registry:** [ghcr.io/ericlbuehler/mistral.rs](https://ghcr.io/ericlbuehler/mistral.rs)
* 📚 **Dokumentation:** [ericlbuehler.github.io/mistral.rs](https://ericlbuehler.github.io/mistral.rs/mistralrs/)
* 💬 **Discord:** [discord.gg/SZrecqK8qw](https://discord.gg/SZrecqK8qw)
* 🤗 **GGUF-Modelle:** [huggingface.co/TheBloke](https://huggingface.co/TheBloke)


---

# 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/mistral-rs.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.
