# Ollama

Der einfachste Weg, LLMs lokal auf CLORE.AI-GPUs auszuführen.

{% hint style="info" %}
**Aktuelle Version: v0.6+** — Dieser Leitfaden behandelt Ollama v0.6 und neuer. Wichtige neue Funktionen umfassen strukturierte Ausgaben (JSON-Schema-Erzwingung), OpenAI-kompatiblen Embeddings-Endpunkt (`/api/embed`), und gleichzeitiges Laden von Modellen (mehrere Modelle gleichzeitig ausführen, ohne zu tauschen). Siehe [Neu in v0.6+](#new-in-v06) für Details.
{% endhint %}

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

## Serveranforderungen

| Parameter | Minimum       | Empfohlen |
| --------- | ------------- | --------- |
| RAM       | 8GB           | 16GB+     |
| VRAM      | 6GB           | 8GB+      |
| Netzwerk  | 100Mbps       | 500Mbps+  |
| Startzeit | \~30 Sekunden | -         |

{% hint style="info" %}
Ollama ist leichtgewichtig und funktioniert auf den meisten GPU-Servern. Für größere Modelle (13B+) wählen Sie Server mit 16GB+ RAM und 12GB+ VRAM.
{% endhint %}

## Warum Ollama?

* **Ein-Kommando-Setup** - Kein Python, keine Abhängigkeiten
* **Modellbibliothek** - Modelle herunterladen mit `ollama pull`
* **OpenAI-kompatible API** - Drop-in-Ersatz
* **GPU-Beschleunigung** - Automatische CUDA-Erkennung
* **Multi-Modell** - Mehrere Modelle gleichzeitig ausführen (v0.6+)

## Schnelle Bereitstellung auf CLORE.AI

**Docker-Image:**

```
ollama/ollama
```

**Ports:**

```
22/tcp
11434/http
```

**Befehl:**

```bash
ollama serve
```

### Überprüfen, ob es funktioniert

Nach der Bereitstellung finden Sie Ihre `http_pub` URL in **Meine Bestellungen** und testen:

```bash
# Ersetzen Sie dies durch Ihre tatsächliche http_pub-URL
curl https://your-http-pub.clorecloud.net/

# Erwartete Antwort: "Ollama is running"
```

{% hint style="warning" %}
Wenn Sie HTTP 502 erhalten, warten Sie 30–60 Sekunden - der Dienst startet noch.
{% endhint %}

## Zugriff auf Ihren Dienst

Bei Bereitstellung auf CLORE.AI greifen Sie über das `http_pub` URL:

```bash
# Finden Sie Ihr http_pub in My Orders, dann:
curl https://your-http-pub.clorecloud.net/api/tags

# Für API-Aufrufe verwenden Sie Ihre http_pub-URL:
curl https://your-http-pub.clorecloud.net/api/chat -d '{
  "model": "llama3.2",
  "messages": [{"role": "user", "content": "Hello!"}],
  "stream": false
}'
```

{% hint style="info" %}
Alle `localhost:11434` Die untenstehenden Beispiele funktionieren, wenn über SSH verbunden. Für externen Zugriff ersetzen Sie durch Ihre `https://your-http-pub.clorecloud.net/` URL.
{% endhint %}

## Installation

### Verwendung von Docker (empfohlen)

```bash
docker run -d --gpus all -v ollama:/root/.ollama -p 11434:11434 --name ollama ollama/ollama
```

### Manuelle Installation

```bash
curl -fsSL https://ollama.com/install.sh | sh
```

Dieser einzelne Befehl installiert die neueste Version von Ollama, richtet den systemd-Dienst ein und konfiguriert die GPU-Erkennung automatisch. Funktioniert auf Ubuntu, Debian, Fedora und den meisten modernen Linux-Distributionen.

## Modelle ausführen

### Herunterladen und Ausführen

```bash
# Modell herunterladen
ollama pull llama3.2

# Interaktiven Chat ausführen
ollama run llama3.2

# Mit Prompt ausführen
ollama run llama3.2 "Erkläre Quantencomputing"
```

### Beliebte Modelle

| Modell              | Größe   | Einsatzgebiet                  |
| ------------------- | ------- | ------------------------------ |
| `llama3.2`          | 3B      | Schnell, für allgemeine Zwecke |
| `llama3.1`          | 8B      | Bessere Qualität               |
| `llama3.1:70b`      | 70B     | Beste Qualität                 |
| `mistral`           | 7B      | Schnell, gute Qualität         |
| `mixtral`           | 47B     | MoE, hohe Qualität             |
| `codellama`         | 7-34B   | Code-Generierung               |
| `deepseek-coder-v2` | 16B     | Am besten für Code             |
| `deepseek-r1`       | 7B-671B | Reasoning-Modell               |
| `deepseek-r1:32b`   | 32B     | Ausgewogenes Reasoning         |
| `qwen2.5`           | 7B      | Mehrsprachig                   |
| `qwen2.5:72b`       | 72B     | Beste Qwen-Qualität            |
| `phi4`              | 14B     | Microsofts neuestes            |
| `gemma2`            | 9B      | Googles Modell                 |

### Modellvarianten

```bash
# Quantisierungsvarianten
ollama pull llama3.1:8b-instruct-q4_K_M   # 4-Bit (kleiner, schneller)
ollama pull llama3.1:8b-instruct-q8_0     # 8-Bit (bessere Qualität)
ollama pull llama3.1:8b-instruct-fp16     # Volle Genauigkeit

# Größenvarianten
ollama pull llama3.1:8b    # 8 Milliarden Parameter
ollama pull llama3.1:70b   # 70 Milliarden Parameter

# Neue Modelle (v0.6+ Ära)
ollama pull deepseek-r1:7b      # Reasoning, budgetfreundlich
ollama pull deepseek-r1:14b     # Reasoning, effizient
ollama pull deepseek-r1:32b     # Reasoning, ausgewogen
ollama pull deepseek-r1:70b     # Reasoning, hohe Qualität
ollama pull qwen2.5:72b         # Größter Qwen, beste Qualität
ollama pull phi4                # Microsoft Phi-4 14B
```

## Neu in v0.6+

Ollama v0.6 führte mehrere wichtige Funktionen für Produktions-Workloads ein:

### Strukturierte Ausgaben (JSON-Schema)

Erzwingen, dass Modellantworten einem bestimmten JSON-Schema entsprechen. Nützlich zum Erstellen von Anwendungen, die zuverlässige, parsbare Ausgaben benötigen:

```bash
curl http://localhost:11434/api/chat -d '{
  "model": "llama3.2",
  "messages": [{"role": "user", "content": "Erzähl mir etwas über Kanada."}],
  "format": {
    "type": "object",
    "properties": {
      "name": {"type": "string"},
      "capital": {"type": "string"},
      "population": {"type": "integer"},
      "languages": {
        "type": "array",
        "items": {"type": "string"}
      }
    },
    "required": ["name", "capital", "population", "languages"]
  },
  "stream": false
}'
```

Python-Beispiel mit strukturierten Ausgaben:

```python
from openai import OpenAI
import json

client = OpenAI(base_url="http://localhost:11434/v1", api_key="ollama")

response = client.chat.completions.create(
    model="llama3.2",
    messages=[{"role": "user", "content": "Liste 3 Programmiersprachen mit ihren Hauptanwendungsfällen"}],
    response_format={
        "type": "json_schema",
        "json_schema": {
            "name": "languages",
            "schema": {
                "type": "object",
                "properties": {
                    "languages": {
                        "type": "array",
                        "items": {
                            "type": "object",
                            "properties": {
                                "name": {"type": "string"},
                                "use_case": {"type": "string"},
                                "popularity_rank": {"type": "integer"}
                            }
                        }
                    }
                }
            }
        }
    }
)

data = json.loads(response.choices[0].message.content)
print(data)
```

### OpenAI-kompatibler Embeddings-Endpunkt (`/api/embed`)

Neu in v0.6+: der `/api/embed` Endpunkt ist vollständig OpenAI-kompatibel und unterstützt Batch-Eingaben:

```bash
# Einzelnes Text-Embedding
curl http://localhost:11434/api/embed -d '{
  "model": "nomic-embed-text",
  "input": "Hello world"
}'

# Batch-Embeddings (neu in v0.6)
curl http://localhost:11434/api/embed -d '{
  "model": "nomic-embed-text",
  "input": ["First document", "Second document", "Third document"]
}'
```

Der OpenAI-Client funktioniert direkt mit `/v1/embeddings`:

```python
from openai import OpenAI
import numpy as np

client = OpenAI(base_url="http://localhost:11434/v1", api_key="ollama")

# Zuerst Embedding-Modell ziehen: ollama pull nomic-embed-text
response = client.embeddings.create(
    model="nomic-embed-text",
    input=["Hello world", "Goodbye world"]
)

emb1 = np.array(response.data[0].embedding)
emb2 = np.array(response.data[1].embedding)

# Kosinusähnlichkeit
similarity = np.dot(emb1, emb2) / (np.linalg.norm(emb1) * np.linalg.norm(emb2))
print(f"Similarity: {similarity:.4f}")
```

Beliebte Embedding-Modelle:

```bash
ollama pull nomic-embed-text      # 137M, schnell, gute Qualität
ollama pull mxbai-embed-large     # 335M, höhere Qualität
ollama pull all-minilm            # 23M, am schnellsten
```

### Gleichzeitiges Laden von Modellen

Vor v0.6 würde Ollama ein Modell entladen, um ein anderes zu laden. V0.6+ unterstützt das gleichzeitige Ausführen mehrerer Modelle, beschränkt nur durch verfügbaren VRAM:

```bash
# Zwei Modelle gleichzeitig laden
ollama run llama3.2 &
ollama run deepseek-r1:7b &

# Prüfen, was läuft
curl http://localhost:11434/api/ps
```

Konfigurieren Sie die Parallelität:

```bash
# Erlaube bis zu 4 gleichzeitig geladene Modelle
OLLAMA_MAX_LOADED_MODELS=4 ollama serve

# Jeder Runner in einem separaten Prozess (bessere Isolation)
OLLAMA_NUM_PARALLEL=2 ollama serve
```

Dies ist besonders nützlich für:

* A/B-Tests mit verschiedenen Modellen
* Spezialisierte Modelle für verschiedene Aufgaben (Coding + Chat)
* Häufig genutzte Modelle im VRAM warm halten

## API-Nutzung

### Chat Completion

```bash
# Über http_pub (externer Zugriff):
curl https://your-http-pub.clorecloud.net/api/chat -d '{
  "model": "llama3.2",
  "messages": [{"role": "user", "content": "Hello!"}],
  "stream": false
}'

# Über SSH-Tunnel (localhost):
curl http://localhost:11434/api/chat -d '{
  "model": "llama3.2",
  "messages": [{"role": "user", "content": "Hello!"}],
  "stream": false
}'
```

{% hint style="info" %}
Hinzufügen `"stream": false` um die vollständige Antwort auf einmal zu erhalten statt gestreamt.
{% endhint %}

### OpenAI-kompatibler Endpunkt

```python
from openai import OpenAI

# Für externen Zugriff verwenden Sie Ihre http_pub-URL:
client = OpenAI(
    base_url="https://your-http-pub.clorecloud.net/v1",
    api_key="ollama"  # beliebiger String funktioniert
)

# Oder über SSH-Tunnel:
# client = OpenAI(base_url="http://localhost:11434/v1", api_key="ollama")

response = client.chat.completions.create(
    model="llama3.2",
    messages=[
        {"role": "user", "content": "What is machine learning?"}
    ]
)

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

### Streaming

```python
stream = client.chat.completions.create(
    model="llama3.2",
    messages=[{"role": "user", "content": "Schreibe ein Gedicht"}],
    stream=True
)

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

### Embeddings

```bash
# Legacy-Endpunkt (funktioniert weiterhin)
curl http://localhost:11434/api/embeddings -d '{
  "model": "nomic-embed-text",
  "prompt": "Hello world"
}'

# Neuer v0.6+-Endpunkt (Batch-Unterstützung, OpenAI-kompatibel)
curl http://localhost:11434/api/embed -d '{
  "model": "nomic-embed-text",
  "input": ["Hello world", "Another text"]
}'
```

### Textgenerierung (Nicht-Chat)

```bash
curl https://your-http-pub.clorecloud.net/api/generate -d '{
  "model": "llama3.2",
  "prompt": "The meaning of life is",
  "stream": false
}'
```

## Vollständige API-Referenz

Alle Endpunkte funktionieren sowohl mit `http://localhost:11434` (über SSH) als auch `https://your-http-pub.clorecloud.net` (extern).

### Modellverwaltung

| Endpunkt       | Methode | Beschreibung                             |
| -------------- | ------- | ---------------------------------------- |
| `/api/tags`    | GET     | Alle heruntergeladenen Modelle auflisten |
| `/api/show`    | POST    | Modelldetails abrufen                    |
| `/api/pull`    | POST    | Ein Modell herunterladen                 |
| `/api/delete`  | DELETE  | Ein Modell entfernen                     |
| `/api/ps`      | GET     | Derzeit laufende Modelle auflisten       |
| `/api/version` | GET     | Ollama-Version abrufen                   |

#### Modelle auflisten

```bash
curl https://your-http-pub.clorecloud.net/api/tags
```

Antwort:

```json
{
  "models": [
    {"name": "llama3.2:latest", "size": 2019393189, "digest": "...", "modified_at": "..."}
  ]
}
```

#### Modelldetails anzeigen

```bash
curl https://your-http-pub.clorecloud.net/api/show -d '{"name": "llama3.2"}'
```

#### Modell per API ziehen

```bash
curl https://your-http-pub.clorecloud.net/api/pull -d '{
  "name": "mistral:7b",
  "stream": false
}'
```

Antwort:

```json
{"status": "success"}
```

{% hint style="warning" %}
Große Modelle können mehrere Minuten zum Herunterladen benötigen. Für sehr große Modelle (30GB+) ziehen Sie in Betracht, SSH und die CLI zu verwenden: `ollama pull model-name`
{% endhint %}

#### Modell löschen

```bash
curl -X DELETE https://your-http-pub.clorecloud.net/api/delete -d '{"name": "mistral:7b"}'
```

#### Laufende Modelle auflisten

```bash
curl https://your-http-pub.clorecloud.net/api/ps
```

Antwort:

```json
{
  "models": [
    {"name": "llama3.2:latest", "size": 2019393189, "expires_at": "2025-01-25T12:00:00Z"}
  ]
}
```

#### Version abrufen

```bash
curl https://your-http-pub.clorecloud.net/api/version
```

Antwort:

```json
{"version": "0.6.8"}
```

### Inference-Endpunkte

| Endpunkt               | Methode | Beschreibung                                         |
| ---------------------- | ------- | ---------------------------------------------------- |
| `/api/generate`        | POST    | Textvervollständigung                                |
| `/api/chat`            | POST    | Chat-Vervollständigung                               |
| `/api/embeddings`      | POST    | Embeddings erzeugen (Legacy)                         |
| `/api/embed`           | POST    | Embeddings erzeugen v0.6+ (Batch, OpenAI-kompatibel) |
| `/v1/chat/completions` | POST    | OpenAI-kompatibler Chat                              |
| `/v1/embeddings`       | POST    | OpenAI-kompatible Embeddings                         |

### Erstellung benutzerdefinierter Modelle

Erstellen Sie benutzerdefinierte Modelle mit spezifischen System-Prompts via API:

```bash
curl https://your-http-pub.clorecloud.net/api/create -d '{
  "name": "my-assistant",
  "modelfile": "FROM llama3.2\nSYSTEM You are a helpful coding assistant."
}'
```

## GPU-Konfiguration

### GPU-Auslastung prüfen

```bash
# Im Container oder auf dem Server
nvidia-smi

# Ollama zeigt GPU in den Logs an
ollama run llama3.2 --verbose
```

### Multi-GPU

Ollama verwendet automatisch verfügbare GPUs. Für eine spezifische GPU:

```bash
CUDA_VISIBLE_DEVICES=0 ollama serve
```

### Speicherverwaltung

```bash
# GPU-Speicherlimit setzen
OLLAMA_GPU_MEMORY=8GiB ollama serve

# Modell geladen halten
OLLAMA_KEEP_ALIVE=24h ollama serve

# Gleichzeitige Modelle erlauben (v0.6+)
OLLAMA_MAX_LOADED_MODELS=3 ollama serve
```

## Benutzerdefinierte Modelle (Modelfile)

Erstellen Sie benutzerdefinierte Modelle mit System-Prompts:

```dockerfile
# Modelfile
FROM llama3.2

SYSTEM You are a helpful coding assistant. Always provide code examples.

PARAMETER temperature 0.7
PARAMETER top_p 0.9
```

```bash
ollama create coding-assistant -f Modelfile
ollama run coding-assistant
```

## Als Dienst ausführen

### Systemd

```ini
# /etc/systemd/system/ollama.service
[Unit]
Description=Ollama Service
After=network.target

[Service]
Type=simple
ExecStart=/usr/local/bin/ollama serve
Restart=always
Environment="OLLAMA_HOST=0.0.0.0"

[Install]
WantedBy=multi-user.target
```

```bash
systemctl enable ollama
systemctl start ollama
```

## Performance-Tipps

1. **Verwenden Sie geeignete Quantisierung**
   * Q4\_K\_M für Geschwindigkeit
   * Q8\_0 für Qualität
   * fp16 für maximale Qualität
2. **Modell an VRAM anpassen**
   * 8GB: 7B-Modelle (Q4)
   * 16GB: 13B-Modelle oder 7B (Q8)
   * 24GB: 34B-Modelle (Q4)
   * 48GB+: 70B-Modelle
3. **Modell geladen halten**

   ```bash
   OLLAMA_KEEP_ALIVE=1h ollama serve
   ```
4. **Schnelle SSD verbessert die Leistung**
   * Modellladen und KV-Cache profitieren von schnellem Speicher
   * Server mit NVMe-SSD können 2–3x bessere Leistung erreichen

## Benchmarks

### Generierungsgeschwindigkeit (Token/Sekunde)

| Modell               | RTX 3060 | RTX 3090 | RTX 4090 | A100 40GB |
| -------------------- | -------- | -------- | -------- | --------- |
| Llama 3.2 3B (Q4)    | 120      | 160      | 200      | 220       |
| Llama 3.1 8B (Q4)    | 60       | 100      | 130      | 150       |
| Llama 3.1 8B (Q8)    | 45       | 80       | 110      | 130       |
| Mistral 7B (Q4)      | 70       | 110      | 140      | 160       |
| Mixtral 8x7B (Q4)    | -        | 35       | 55       | 75        |
| Llama 3.1 70B (Q4)   | -        | -        | 18       | 35        |
| DeepSeek-R1 7B (Q4)  | 65       | 105      | 135      | 155       |
| DeepSeek-R1 32B (Q4) | -        | -        | 22       | 42        |
| Qwen2.5 72B (Q4)     | -        | -        | 15       | 30        |
| Phi-4 14B (Q4)       | -        | 50       | 75       | 90        |

*Benchmarks aktualisiert Januar 2026. Tatsächliche Geschwindigkeiten können je nach Serverkonfiguration variieren.*

### Zeit bis zum ersten Token (ms)

| Modell | RTX 3090 | RTX 4090 | A100 |
| ------ | -------- | -------- | ---- |
| 3B     | 50       | 35       | 25   |
| 7-8B   | 120      | 80       | 60   |
| 13B    | 250      | 150      | 100  |
| 34B    | 600      | 350      | 200  |
| 70B    | -        | 1200     | 500  |

### Kontextlänge vs. VRAM (Q4)

| Modell | 2K ctx | 4K ctx | 8K ctx | 16K ctx |
| ------ | ------ | ------ | ------ | ------- |
| 7B     | 5GB    | 6GB    | 8GB    | 12GB    |
| 13B    | 8GB    | 10GB   | 14GB   | 22GB    |
| 34B    | 20GB   | 24GB   | 32GB   | 48GB    |
| 70B    | 40GB   | 48GB   | 64GB   | 96GB    |

## GPU-Anforderungen

| Modell | Q4 VRAM | Q8 VRAM |
| ------ | ------- | ------- |
| 3B     | 3GB     | 5GB     |
| 7-8B   | 5GB     | 9GB     |
| 13B    | 8GB     | 15GB    |
| 34B    | 20GB    | 38GB    |
| 70B    | 40GB    | 75GB    |

## Kostenabschätzung

Typische CLORE.AI-Marktplatzpreise:

| GPU      | VRAM | Preis/Tag  | Geeignet für         |
| -------- | ---- | ---------- | -------------------- |
| RTX 3060 | 12GB | $0.15–0.30 | 7B-Modelle           |
| RTX 3090 | 24GB | $0.30–1.00 | 13B-34B-Modelle      |
| RTX 4090 | 24GB | $0.50–2.00 | 34B-Modelle, schnell |
| A100     | 40GB | $1.50–3.00 | 70B-Modelle          |

*Preise in USD/Tag. Die Tarife variieren je nach Anbieter — prüfen Sie* [*CLORE.AI Marketplace*](https://clore.ai/marketplace) *auf aktuelle Preise.*

## Fehlerbehebung

### Modell lädt nicht

```bash
# Verfügbaren Speicher prüfen
nvidia-smi

# Kleinere Quantisierung versuchen
ollama pull llama3.1:8b-q4_0
```

### Langsame Generierung

```bash
# Prüfen, ob GPU verwendet wird
ollama run llama3.2 --verbose

# Sicherstellen, dass CUDA verfügbar ist
nvidia-smi
```

### Verbindung verweigert

```bash
# Sicherstellen, dass der Server läuft
ollama serve

# Prüfen, ob an alle Schnittstellen gebunden wird
OLLAMA_HOST=0.0.0.0 ollama serve
```

### HTTP 502 auf http\_pub-URL

Das bedeutet, dass der Dienst noch startet. Warten Sie 30–60 Sekunden und versuchen Sie es erneut:

```bash
# Prüfen, ob der Dienst bereit ist
curl https://your-http-pub.clorecloud.net/

# Erwartet: "Ollama is running"
# Wenn 502: warten und erneut versuchen
```

## Nächste Schritte

* [WebUI öffnen](https://docs.clore.ai/guides/guides_v2-de/sprachmodelle/open-webui) - Wunderschöne Chat-Oberfläche für Ollama
* [vLLM](https://docs.clore.ai/guides/guides_v2-de/sprachmodelle/vllm) - Hochdurchsatz-Produktions-Serving
* [DeepSeek-R1](https://docs.clore.ai/guides/guides_v2-de/sprachmodelle/deepseek-r1) - Reasoning-Modell
* [DeepSeek-V3](https://docs.clore.ai/guides/guides_v2-de/sprachmodelle/deepseek-v3) - Bestes allgemeines Modell
* [Qwen2.5](https://docs.clore.ai/guides/guides_v2-de/sprachmodelle/qwen25) - Mehrsprachige Alternative
* [Text Generation WebUI](https://docs.clore.ai/guides/guides_v2-de/sprachmodelle/text-generation-webui) - Erweiterte Funktionen
