> 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-mixtral.md).

# Mistral & Mixtral

Führe Mistral- und Mixtral-Modelle auf Clore.ai-GPUs aus

{% hint style="info" %}
**Neuere Versionen verfügbar!** Schau dir das an [**Mistral Small 3.1**](/guides/guides_v2-de/sprachmodelle/mistral-small.md) (24B, Apache 2.0, passt auf RTX 4090) und [**Mistral Large 3**](/guides/guides_v2-de/sprachmodelle/mistral-large3.md) (675B MoE, Spitzenklasse).
{% endhint %}

Führe Mistral- und Mixtral-Modelle für hochwertige Textgenerierung aus.

{% hint style="success" %}
Alle Beispiele können auf GPU-Servern ausgeführt werden, die gemietet wurden über [CLORE.AI-Marktplatz](https://clore.ai/marketplace).
{% endhint %}

## Mieten auf CLORE.AI

1. Besuchen [CLORE.AI-Marktplatz](https://clore.ai/marketplace)
2. Filtern nach GPU-Typ, VRAM und Preis
3. Wähle **On-Demand** (Festpreis) oder **Spot** (Gebotspreis)
4. Konfiguriere deine Bestellung:
   * Docker-Image auswählen
   * Ports festlegen (TCP für SSH, HTTP für Web-UIs)
   * Bei Bedarf Umgebungsvariablen hinzufügen
   * Startbefehl eingeben
5. Zahlung auswählen: **CLORE**, **BTC**, oder **USDT/USDC**
6. Bestellung erstellen und auf die Bereitstellung warten

### Greife auf deinen Server zu

* Verbindungsdetails finden in **Meine Bestellungen**
* Web-Oberflächen: Verwende die HTTP-Port-URL
* SSH: `ssh -p <port> root@<proxy-address>`

## Modellübersicht

| Modell              | Parameter           | VRAM   | Spezialgebiet       |
| ------------------- | ------------------- | ------ | ------------------- |
| Mistral-7B          | 7B                  | 8 GB   | Allgemeiner Zweck   |
| Mistral-7B-Instruct | 7B                  | 8 GB   | Chat/Anweisung      |
| Mixtral-8x7B        | 46,7B (12,9B aktiv) | 24 GB  | MoE, beste Qualität |
| Mixtral-8x22B       | 141B                | 80 GB+ | Größtes MoE         |

## Schnell bereitstellen

**Docker-Image:**

```
pytorch/pytorch:2.11.0-cuda12.8-cudnn9-runtime
```

**Ports:**

```
22/tcp
8000/http
```

**Befehl:**

```bash
pip install vllm && \\
python -m vllm.entrypoints.openai.api_server \
    --model mistralai/Mistral-7B-Instruct-v0.2 \\
    --port 8000
```

## Auf deinen Dienst zugreifen

Nach der Bereitstellung findest du deine `http_pub` URL in **Meine Bestellungen**:

1. Gehe zu **Meine Bestellungen** Seite
2. Klicke auf deine Bestellung
3. Finde die `http_pub` URL (z. B. `abc123.clorecloud.net`)

Verwende `https://YOUR_HTTP_PUB_URL` anstelle von `localhost` in den folgenden Beispielen.

## Installationsoptionen

### Mit Ollama (am einfachsten)

```bash

# Ollama installieren
curl -fsSL https://ollama.com/install.sh | sh

# Mistral ausführen
ollama run mistral

# Mixtral ausführen
ollama run mixtral
```

### Mit vLLM

```bash
pip install vllm

# Server starten
python -m vllm.entrypoints.openai.api_server \
    --model mistralai/Mistral-7B-Instruct-v0.2 \\
    --dtype float16
```

### Mit Transformers

```bash
pip install transformers accelerate
```

## Mistral-7B mit Transformers

```python
from transformers import AutoModelForCausalLM, AutoTokenizer
import torch

model_id = "mistralai/Mistral-7B-Instruct-v0.2"

tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForCausalLM.from_pretrained(
    model_id,
    torch_dtype=torch.float16,
    device_map="auto"
)

messages = [
    {"role": "user", "content": "Erkläre Quantencomputing in einfachen Worten"}
]

inputs = tokenizer.apply_chat_template(
    messages,
    return_tensors="pt"
).to("cuda")

outputs = model.generate(
    inputs,
    max_new_tokens=500,
    do_sample=True,
    temperature=0.7,
    top_p=0.95
)

response = tokenizer.decode(outputs[0], skip_special_tokens=True)
print(response)
```

## Mixtral-8x7B

```python
from transformers import AutoModelForCausalLM, AutoTokenizer
import torch

model_id = "mistralai/Mixtral-8x7B-Instruct-v0.1"

tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForCausalLM.from_pretrained(
    model_id,
    torch_dtype=torch.float16,
    device_map="auto"
)

messages = [
    {"role": "user", "content": "Schreibe eine Python-Funktion zur Berechnung von Fibonacci-Zahlen"}
]

inputs = tokenizer.apply_chat_template(messages, return_tensors="pt").to("cuda")

outputs = model.generate(
    inputs,
    max_new_tokens=1000,
    do_sample=True,
    temperature=0.7
)

print(tokenizer.decode(outputs[0], skip_special_tokens=True))
```

## Quantisierte Modelle (weniger VRAM)

### 4-Bit-Quantisierung

```python
from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig
import torch

quantization_config = BitsAndBytesConfig(
    load_in_4bit=True,
    bnb_4bit_compute_dtype=torch.float16,
    bnb_4bit_quant_type="nf4"
)

model = AutoModelForCausalLM.from_pretrained(
    "mistralai/Mixtral-8x7B-Instruct-v0.1",
    quantization_config=quantization_config,
    device_map="auto"
)
```

### GGUF mit llama.cpp

```bash

# GGUF-Modell herunterladen
wget https://huggingface.co/bartowski/Mistral-7B-Instruct-v0.3-GGUF/resolve/main/Mistral-7B-Instruct-v0.3-Q4_K_M.gguf

# Mit llama.cpp ausführen
./main -m Mistral-7B-Instruct-v0.3-Q4_K_M.gguf \
    -p "Erkläre maschinelles Lernen" \
    -n 500
```

## vLLM-Server (Produktion)

```bash
python -m vllm.entrypoints.openai.api_server \
    --model mistralai/Mistral-7B-Instruct-v0.2 \\
    --dtype float16 \\
    --max-model-len 8192 \
    --gpu-memory-utilization 0.9
```

### OpenAI-kompatible API

```python
from openai import OpenAI

client = OpenAI(
    base_url="http://localhost:8000/v1",
    api_key="not-needed"
)

response = client.chat.completions.create(
    model="mistralai/Mistral-7B-Instruct-v0.2",
    messages=[
        {"role": "user", "content": "Was ist die Hauptstadt von Frankreich?"}
    ],
    temperature=0.7,
    max_tokens=500
)

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

## Streaming

```python
from openai import OpenAI

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

stream = client.chat.completions.create(
    model="mistralai/Mistral-7B-Instruct-v0.2",
    messages=[{"role": "user", "content": "Schreibe eine Geschichte über einen Roboter"}],
    stream=True
)

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

## Funktionsaufrufe

Mistral unterstützt Funktionsaufrufe:

```python
from openai import OpenAI

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

tools = [
    {
        "type": "function",
        "function": {
            "name": "get_weather",
            "description": "Wetter für einen Ort abrufen",
            "parameters": {
                "type": "object",
                "properties": {
                    "location": {"type": "string"},
                    "unit": {"type": "string", "enum": ["celsius", "fahrenheit"]}
                },
                "required": ["location"]
            }
        }
    }
]

response = client.chat.completions.create(
    model="mistralai/Mistral-7B-Instruct-v0.2",
    messages=[{"role": "user", "content": "Wie ist das Wetter in Paris?"}],
    tools=tools
)

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

## Gradio-Oberfläche

```python
import gradio as gr
from transformers import AutoModelForCausalLM, AutoTokenizer
import torch

model_id = "mistralai/Mistral-7B-Instruct-v0.2"
tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForCausalLM.from_pretrained(
    model_id,
    torch_dtype=torch.float16,
    device_map="auto"
)

def chat(message, history, temperature, max_tokens):
    messages = []
    for h in history:
        messages.append({"role": "user", "content": h[0]})
        messages.append({"role": "assistant", "content": h[1]})
    messages.append({"role": "user", "content": message})

    inputs = tokenizer.apply_chat_template(messages, return_tensors="pt").to("cuda")

    outputs = model.generate(
        inputs,
        max_new_tokens=max_tokens,
        temperature=temperature,
        do_sample=True
    )

    response = tokenizer.decode(outputs[0], skip_special_tokens=True)
    # Assistentenantwort extrahieren
    return response.split("[/INST]")[-1].strip()

demo = gr.ChatInterface(
    fn=chat,
    additional_inputs=[
        gr.Slider(0.1, 2.0, value=0.7, label="Temperatur"),
        gr.Slider(100, 2000, value=500, step=100, label="Maximale Token")
    ],
    title="Mistral-7B Chat"
)

demo.launch(server_name="0.0.0.0", server_port=7860)
```

## Leistungsvergleich

### Durchsatz (Tokens/Sek.)

| Modell            | RTX 3060 | RTX 3090 | RTX 4090 | A100 40GB |
| ----------------- | -------- | -------- | -------- | --------- |
| Mistral-7B FP16   | 45       | 80       | 120      | 150       |
| Mistral-7B Q4     | 70       | 110      | 160      | 200       |
| Mixtral-8x7B FP16 | -        | -        | 30       | 60        |
| Mixtral-8x7B Q4   | -        | 25       | 50       | 80        |
| Mixtral-8x22B Q4  | -        | -        | -        | 25        |

### Zeit bis zum ersten Token (TTFT)

| Modell        | RTX 3090 | RTX 4090 | A100  |
| ------------- | -------- | -------- | ----- |
| Mistral-7B    | 80ms     | 50ms     | 35 ms |
| Mixtral-8x7B  | -        | 150ms    | 90ms  |
| Mixtral-8x22B | -        | -        | 200ms |

### Kontextlänge vs. VRAM (Mistral-7B)

| Kontext | FP16  | Q8    | Q4   |
| ------- | ----- | ----- | ---- |
| 4K      | 15 GB | 9GB   | 5GB  |
| 8K      | 18 GB | 11GB  | 7 GB |
| 16K     | 24 GB | 15 GB | 9GB  |
| 32K     | 36GB  | 22 GB | 14GB |

## VRAM-Anforderungen

| Modell        | FP16  | 8-Bit | 4-Bit |
| ------------- | ----- | ----- | ----- |
| Mistral-7B    | 14GB  | 8 GB  | 5GB   |
| Mixtral-8x7B  | 90GB  | 45GB  | 24 GB |
| Mixtral-8x22B | 180GB | 90GB  | 48GB  |

## Anwendungsfälle

### Codegenerierung

```python
prompt = """
Schreibe eine Python-Klasse für einen REST-API-Client mit:
- Authentifizierungsbehandlung
- Wiederholungslogik
- Fehlerbehandlung
"""
```

### Datenanalyse

```python
prompt = """
Analysiere diese Daten und gib Erkenntnisse:
Umsatz Q1: 100 Tsd. $
Umsatz Q2: 150 Tsd. $
Umsatz Q3: 120 Tsd. $
Umsatz Q4: 200 Tsd. $
"""
```

### Kreatives Schreiben

```python
prompt = """
Schreibe eine Kurzgeschichte über eine KI, die sich ihrer selbst bewusst wird,
im Stil von Isaac Asimov.
"""
```

## Fehlerbehebung

### Speicher erschöpft

* Verwende 4-Bit-Quantisierung
* Verwende Mistral-7B statt Mixtral
* max\_model\_len reduzieren

### Langsame Generierung

* Verwende vLLM für die Produktion
* Flash Attention aktivieren
* Verwende Tensor-Parallelismus für Multi-GPU

### Schlechte Ausgabequalität

* Temperatur anpassen (0.1-0.9)
* Instruct-Variante verwenden
* Bessere System-Prompts

## Kostenschätzung

Übliche CLORE.AI-Marktplatzpreise (Stand 2024):

| GPU       | Stundensatz | Tagessatz | 4-Stunden-Sitzung |
| --------- | ----------- | --------- | ----------------- |
| RTX 3060  | \~$0.03     | \~$0.70   | \~$0.12           |
| RTX 3090  | \~$0.06     | \~$1.50   | \~$0.25           |
| RTX 4090  | \~$0.10     | \~$2.30   | \~$0.40           |
| A100 40GB | \~$0.17     | \~$4.00   | \~$0.70           |
| A100 80GB | \~$0.25     | \~$6.00   | \~$1.00           |

*Die Preise variieren je nach Anbieter und Nachfrage. Prüfen Sie* [*CLORE.AI-Marktplatz*](https://clore.ai/marketplace) *für aktuelle Preise.*

**Geld sparen:**

* Nutzen Sie den **Spot** Markt für unterbrechbare Arbeit — etwa ein Drittel der Server bietet Spot-Preise unter dem On-Demand-Preis (Median ca. 13 % Rabatt), der Rest ist gleichauf
* Bezahlen Sie mit **CLORE** Tokens
* Vergleichen Sie Preise zwischen verschiedenen Anbietern

## Nächste Schritte

* [vLLM](/guides/guides_v2-de/sprachmodelle/vllm.md) - Bereitstellung in der Produktion
* [Ollama](/guides/guides_v2-de/sprachmodelle/ollama.md) - Einfache Bereitstellung
* [DeepSeek-V3](/guides/guides_v2-de/sprachmodelle/deepseek-v3.md) - Bestes Schlussfolgerungsmodell
* [Qwen2.5](/guides/guides_v2-de/sprachmodelle/qwen25.md) - Mehrsprachige Alternative


---

# 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-mixtral.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.
