> 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, geschrieben in Rust** — produktionsreifer Server mit Unterstützung für GGUF, GGML, SafeTensors und OpenAI-kompatible API.

> 🦀 **In Rust entwickelt** für maximale Leistung | Unterstützung für GGUF- und Vision-Modelle | Apache-2.0-Lizenz

***

## Was ist Mistral.rs?

Mistral.rs ist eine Hochleistungs-LLM-Inferenz-Engine, die vollständig in **Rust**geschrieben ist. Ursprünglich auf Mistral-Modelle fokussiert, unterstützt es heute die gesamte Landschaft moderner LLMs. Die Rust-Basis bietet:

* **Zero-Cost-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-Kernels werden zur Build-Zeit optimiert

### Hauptfunktionen

* **GGUF-Unterstützung** — führe jedes quantisierte Modell aus (Q4\_K\_M, Q8\_0 usw.)
* **ISQ (In-Situ-Quantisierung)** — quantisiert beim Laden on the fly
* **PagedAttention** — effizienter KV-Cache mit kontinuierlichem Batching
* **Vision-Sprachmodelle** — Unterstützung für LLaVA, Phi-3 Vision, Idefics
* **Spekulatives Decodieren** — schnellere Inferenz mit Entwurfsmodellen
* **X-LoRA** — skalierbare Unterstützung für feinabgestimmte Adapter
* **OpenAI-kompatible REST-API** — direkter 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: Finde einen GPU-Server

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

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

### Schritt 2: Mistral.rs-Docker bereitstellen

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

**Portzuordnungen:**

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

# mistral.rs-Binärdatei prüfen
mistralrs-server --help
```

***

## Server ausführen

### Schnellstart mit GGUF-Modell

```bash
# Stelle ein GGUF-Modell direkt von HuggingFace bereit
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 beim Laden — kein vorquantisiertes Modell erforderlich:

```bash
# Lade Llama 3 8B und quantisiere on the fly zu Q4K
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 Quantisierung)
```

### Vision-Sprachmodell

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

### Spekulatives Decodieren

```bash
# Verwende ein kleines Entwurfsmodell, 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 Decodieren** kann bieten **2–3-fache Beschleunigung** für die meisten dialogorientierten Workloads, bei denen das kleine Entwurfsmodell 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    | Text-Vervollständigungen          |
| `/v1/models`             | GET     | Modelle auflisten                 |
| `/v1/images/generations` | POST    | Bildgenerierung (VLMs)            |
| `/v1/re_isq`             | POST    | Geladenes Modell neu 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-Vervollständigung
response = client.chat.completions.create(
    model="llama-3-8b",  # Der Modellname ist flexibel
    messages=[
        {"role": "system", "content": "Du bist ein hilfreicher Coding-Assistent."},
        {"role": "user", "content": "Schreibe eine Python-Funktion, um eine 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
) as 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-/Bildeingabe

```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 in diesem Bild?"
                }
            ]
        }
    ]
)
print(response.choices[0].message.content)
```

### cURL-Beispiele

```bash
# Einfacher 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

# Gesundheitsprüfung
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 \\                     # Protokollierungsstufe: off/error/warn/info/debug/trace
  --token-source env:HF_TOKEN \\    # HuggingFace-Token-Quelle
  --max-seqs 16 \\                  # Maximale gleichzeitige Sequenzen
  --no-paged-attn \\                # PagedAttention deaktivieren (für Debugging verwenden)
  --prefix-cache-n 16 \\            # Prefix-Cache-Einträge
  plain \\                          # Unterbefehl für den Modelltyp
  -m meta-llama/Meta-Llama-3-8B-Instruct \\
  --isq Q4K
```

### ISQ-Quantisierungsreferenz

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

{% hint style="info" %}
**HQQ (Half-Quadratic Quantisierung)** erreicht oft bessere Qualität als GGUF Q4 auf demselben Bitniveau, insbesondere bei Aufgaben zum Befolgen von Anweisungen.
{% endhint %}

***

## Erweiterte Funktionen

### X-LoRA (Mischung aus LoRA-Adaptern)

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

### Zur Laufzeit neu quantisieren

```bash
# Quantisierung ohne Neustart ändern
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
```

***

## Leistungsoptimierung

### 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 geringe Latenz optimieren

```bash
# Niedrigere max-seqs, Freigabe des Prefix-Caches 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:
```

***

## Aus dem Quellcode bauen

Wenn das Docker-Image nicht zu Ihrer 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

# Mit CUDA-Unterstützung bauen
cargo build --release --features cuda

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

{% hint style="warning" %}
**Build-Zeit:** Die Rust-Kompilierung ist langsam. Rechne mit 10–20 Minuten für einen vollständigen 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
# CUDA-Bibliotheken prüfen
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=your_token_here

# Oder das --token-source-Flag verwenden
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 wird verwendet

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

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

### Nicht genügend Speicher während der Quantisierung

```bash
# ISQ quantisiert auf der GPU — reduziere zuerst die andere GPU-Nutzung
# Oder zu GGUF wechseln (vorquantisiert, geringerer Spitzenarbeitsspeicher)
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 beim Laden mithilfe von GPU-Speicher (kurzer Spitzenwert). Wenn dir VRAM knapp ist, verwende vorquantisierte GGUF-Dateien von TheBloke oder ähnlichen Quellen — sie benötigen beim Laden weniger Spitzenarbeitsspeicher.
{% endhint %}

***

## GPU-Empfehlungen für Clore.ai

Mistral.rs ist eine Rust-native Engine — der geringe Overhead bedeutet, dass du mehr Durchsatz pro GPU-Euro erhältst als bei Python-basierten Servern.

| GPU       | VRAM  | Clore.ai-Preis                            | Empfohlene Verwendung                           | Durchsatz (Mistral 7B Q4) |
| --------- | ----- | ----------------------------------------- | ----------------------------------------------- | ------------------------- |
| RTX 3090  | 24 GB | ca. 0,07–0,21 $/h                         | Beste Budget-Option — 7B Q4/Q8, Vision-Modelle  | \~120 Tok/s               |
| RTX 4090  | 24 GB | ca. 0,14–0,42 $/h                         | Hoher Durchsatz 7B–34B, spekulatives Decodieren | \~200 tok/s               |
| A100 40GB | 40 GB | [Bare Metal](https://clore.ai/bare-metal) | Produktiver 34B–70B Q4-Betrieb                  | \~160 tok/s               |
| A100 80GB | 80 GB | [Bare Metal](https://clore.ai/bare-metal) | 70B in Vollpräzision, Multi-Modell              | \~185 tok/s               |

**Warum die RTX 3090 hier glänzt:** Die Rust-CUDA-Kernels von Mistral.rs vermeiden den Python-GIL-Overhead und die Garbage-Collection-Pausen, die Python-Server ausbremsen. Eine RTX 3090, die Mistral 7B Q4\_K\_M ausführt, erreicht etwa \~120 tok/s — vergleichbar mit vLLM auf derselben Hardware zu einem Bruchteil der Kosten ($0.07–0.21/hr vs. Cloud-Anbieter, die $0.07–0.21/hr verlangen).

**Spekulatives Decodieren:** Kombiniere ein großes Modell (34B) mit einem kleinen Entwurfsmodell (3B) für eine 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, and the optional `goal` query parameter:

```
GET https://docs.clore.ai/guides/guides_v2-de/sprachmodelle/mistral-rs.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.
