> 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/exllamav2-fast.md).

# ExLlamaV2

Maximale Geschwindigkeit bei der LLM-Inferenz mit ExLlamaV2 auf Clore.ai-GPUs

Führe LLMs mit ExLlamaV2 in Höchstgeschwindigkeit 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>`

## Was ist ExLlamaV2?

ExLlamaV2 ist die schnellste Inferenz-Engine für große Sprachmodelle:

* 2-3x schneller als andere Engines
* Hervorragende Quantisierung (EXL2)
* Geringer VRAM-Verbrauch
* Unterstützt spekulatives Decoding

## Anforderungen

| Modellgröße | Min. VRAM | Empfohlen |
| ----------- | --------- | --------- |
| 7B          | 6 GB      | RTX 3060  |
| 13B         | 10 GB     | RTX 3090  |
| 34B         | 20 GB     | RTX 4090  |
| 70B         | 40 GB     | A100      |

## Schnell bereitstellen

**Docker-Image:**

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

**Ports:**

```
22/tcp
8080/http
```

**Befehl:**

```bash
pip install exllamav2 && \\
huggingface-cli download turboderp/Llama2-7B-exl2 --local-dir ./model && \\
python -m exllamav2.server --model_dir ./model --host 0.0.0.0 --port 8080
```

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

## Installation

```bash

# Installation von PyPI
pip install exllamav2

# Oder aus dem Quellcode (neueste Funktionen)
git clone https://github.com/turboderp/exllamav2
cd exllamav2
pip install .
```

## Modelle herunterladen

### EXL2-quantisierte Modelle

```bash

# Llama 3.1 8B (4.0 bpw)
huggingface-cli download turboderp/Llama2-7B-exl2 \\
    --revision 4.0bpw \\
    --local-dir ./llama2-7b-exl2

# Llama 3.1 8B (4.0 bpw)
huggingface-cli download turboderp/Llama2-13B-exl2 \\
    --revision 4.0bpw \\
    --local-dir ./llama2-13b-exl2

# Mistral 7B (4.0 bpw)
huggingface-cli download turboderp/Mistral-7B-instruct-exl2 \\
    --revision 4.0bpw \\
    --local-dir ./mistral-7b-exl2

# Mixtral 8x7B
huggingface-cli download turboderp/Mixtral-8x7B-instruct-exl2 \\
    --revision 4.0bpw \\
    --local-dir ./mixtral-exl2
```

### Bits pro Gewicht (bpw)

| BPW | Qualität     | VRAM (7B) |
| --- | ------------ | --------- |
| 2.0 | Niedrig      | \~3GB     |
| 3.0 | Gut          | \~4 GB    |
| 4.0 | Großartig    | \~5GB     |
| 5.0 | Hervorragend | \~6GB     |
| 6.0 | Nahezu FP16  | \~7GB     |

## Python-API

### Grundlegende Generierung

```python
from exllamav2 import ExLlamaV2, ExLlamaV2Config, ExLlamaV2Cache, ExLlamaV2Tokenizer
from exllamav2.generator import ExLlamaV2StreamingGenerator, ExLlamaV2Sampler

# Modell laden
config = ExLlamaV2Config()
config.model_dir = "./llama2-7b-exl2"
config.prepare()

model = ExLlamaV2(config)
model.load()

tokenizer = ExLlamaV2Tokenizer(config)
cache = ExLlamaV2Cache(model, lazy=True)

# Generator erstellen
generator = ExLlamaV2StreamingGenerator(model, cache, tokenizer)

# Sampling-Einstellungen festlegen
settings = ExLlamaV2Sampler.Settings()
settings.temperature = 0.7
settings.top_k = 50
settings.top_p = 0.9

# Generieren
prompt = "Die Zukunft der künstlichen Intelligenz ist"
output = generator.generate_simple(prompt, settings, num_tokens=200)
print(output)
```

### Streaming-Generierung

```python
from exllamav2.generator import ExLlamaV2StreamingGenerator

generator = ExLlamaV2StreamingGenerator(model, cache, tokenizer)

prompt = "Schreibe eine Kurzgeschichte über einen Roboter:"
input_ids = tokenizer.encode(prompt)

generator.set_stop_conditions([tokenizer.eos_token_id])
generator.begin_stream(input_ids, settings)

while True:
    chunk, eos, _ = generator.stream()
    if eos:
        break
    print(chunk, end="", flush=True)
```

### Chat-Format

```python
def format_chat(messages):
    text = ""
    for msg in messages:
        role = msg["role"]
        content = msg["content"]
        if role == "system":
            text += f"[INST] <<SYS>>\n{content}\n<</SYS>>\n\n"
        elif role == "user":
            text += f"{content} [/INST]"
        elif role == "assistant":
            text += f" {content}</s><s>[INST] "
    return text

messages = [
    {"role": "system", "content": "Du bist ein hilfreicher Assistent."},
    {"role": "user", "content": "Was ist Python?"}
]

prompt = format_chat(messages)
output = generator.generate_simple(prompt, settings, num_tokens=300)
```

## Server-Modus

### Server starten

```bash
python -m exllamav2.server \\
    --model_dir ./llama2-7b-exl2 \\
    --host 0.0.0.0 \
    --port 8080 \
    --max_seq_len 4096 \\
    --cache_size 4096
```

### API-Nutzung

```python
import requests

response = requests.post(
    "http://localhost:8080/v1/completions",
    json={
        "prompt": "Hallo, wie geht es dir?",
        "max_tokens": 100,
        "temperature": 0.7
    }
)

print(response.json()["choices"][0]["text"] )
```

### Chat-Vervollständigungen

```python
import openai

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

response = client.chat.completions.create(
    model="llama2-7b",
    messages=[{"role": "user", "content": "Hallo!"}],
    temperature=0.7
)

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

## TabbyAPI (empfohlener Server)

TabbyAPI bietet einen funktionsreichen ExLlamaV2-Server:

```bash

# TabbyAPI klonen
git clone https://github.com/theroyallab/tabbyAPI
cd tabbyAPI

# Installieren
pip install -r requirements.txt

# Konfigurieren

# Bearbeite config.yml mit deinem Modellpfad

# Ausführen
python main.py
```

### TabbyAPI-Funktionen

* OpenAI-kompatible API
* Unterstützung für mehrere Modelle
* LoRA-Hot-Swapping
* Streaming
* Funktionsaufrufe
* Admin-API

## Spekulatives Decoding

Verwende ein kleineres Modell, um die Generierung zu beschleunigen:

```python
from exllamav2 import ExLlamaV2, ExLlamaV2Config, ExLlamaV2Cache

# Hauptmodell laden (13B)
main_config = ExLlamaV2Config()
main_config.model_dir = "./llama2-13b-exl2"
main_config.prepare()
main_model = ExLlamaV2(main_config)
main_model.load()

# Draft-Modell laden (7B)
draft_config = ExLlamaV2Config()
draft_config.model_dir = "./llama2-7b-exl2"
draft_config.prepare()
draft_model = ExLlamaV2(draft_config)
draft_model.load()

# Spekulativen Generator erstellen
from exllamav2.generator import ExLlamaV2DraftGenerator

generator = ExLlamaV2DraftGenerator(
    main_model, draft_model,
    cache_main, cache_draft,
    tokenizer
)

# Generieren (schneller mit Spekulation)
output = generator.generate_simple(prompt, settings, num_tokens=500)
```

## Quantisiere deine eigenen Modelle

### In EXL2 konvertieren

```python
from exllamav2 import ExLlamaV2, ExLlamaV2Config
from exllamav2.conversion import convert_model

# Quelle: HuggingFace-Modell

# Ziel: EXL2-quantisiert

convert_model(
    input_dir="./llama-3.1-8b-hf",
    output_dir="./llama-3.1-8b-exl2-4bpw",
    cal_dataset="wikitext",  # Kalibrierungsdatensatz
    bits=4.0,  # Bits pro Gewicht
    head_bits=6,  # Höhere Präzision für Attention
)
```

### Kommandozeile

```bash
python convert.py \\
    -i ./llama-3.1-8b-hf \\
    -o ./llama-3.1-8b-exl2 \\
    -cf ./llama-3.1-8b-exl2 \\
    -b 4.0 \\
    -hb 6
```

## Speicherverwaltung

### Cache-Zuweisung

```python

# Feste Cache-Größe
cache = ExLlamaV2Cache(model, max_seq_len=4096)

# Dynamischer Cache
cache = ExLlamaV2Cache(model, lazy=True)
cache.current_seq_len = 0  # Wächst bei Bedarf
```

### Multi-GPU

```python
config = ExLlamaV2Config()
config.model_dir = "./large-model"

# Auf GPUs aufteilen
config.set_auto_split([0.5, 0.5])  # 50 % pro GPU

model = ExLlamaV2(config)
model.load()
```

## Leistungsvergleich

| Modell       | Engine    | GPU      | Tokens/Sek. |
| ------------ | --------- | -------- | ----------- |
| Llama 3.1 8B | ExLlamaV2 | RTX 3090 | \~150       |
| Llama 3.1 8B | llama.cpp | RTX 3090 | \~100       |
| Llama 3.1 8B | vLLM      | RTX 3090 | \~120       |
| Llama 3.1 8B | ExLlamaV2 | RTX 3090 | \~90        |
| Mixtral 8x7B | ExLlamaV2 | A100     | \~70        |

## Erweiterte Einstellungen

### Sampling-Parameter

```python
settings = ExLlamaV2Sampler.Settings()
settings.temperature = 0.7
settings.top_k = 50
settings.top_p = 0.9
settings.token_repetition_penalty = 1.1
settings.token_frequency_penalty = 0.0
settings.token_presence_penalty = 0.0
settings.mirostat = False
settings.mirostat_tau = 5.0
settings.mirostat_eta = 0.1
```

### Batch-Generierung

```python
prompts = [
    "Der Sinn des Lebens ist",
    "Künstliche Intelligenz wird",
    "Der Klimawandel ist"
]

outputs = []
for prompt in prompts:
    output = generator.generate_simple(prompt, settings, num_tokens=100)
    outputs.append(output)
```

## Fehlerbehebung

### CUDA Out of Memory

```python

# Kleineren Cache verwenden
cache = ExLlamaV2Cache(model, max_seq_len=2048)

# Oder Modell mit niedrigerem bpw (3.0 statt 4.0)
```

### Langsames Laden

```python

# Schnelles Laden aktivieren
config.fasttensors = True
```

### Modell nicht gefunden

```bash

# Prüfen, ob Modelldateien vorhanden sind
ls ./model/

# Sollte enthalten: config.json, *.safetensors, tokenizer.json
```

## Integration mit LangChain

```python
from langchain.llms.base import LLM
from typing import Optional, List

class ExLlamaV2LLM(LLM):
    model: ExLlamaV2
    tokenizer: ExLlamaV2Tokenizer
    generator: ExLlamaV2StreamingGenerator
    settings: ExLlamaV2Sampler.Settings

    @property
    def _llm_type(self) -> str:
        return "exllamav2"

    def _call(self, prompt: str, stop: Optional[List[str]] = None) -> str:
        return self.generator.generate_simple(prompt, self.settings, num_tokens=500)

# Verwendung
llm = ExLlamaV2LLM(model=model, tokenizer=tokenizer, generator=generator, settings=settings)
result = llm("Was ist Quantencomputing?")
```

## 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-Inferenz - Serving mit hohem Durchsatz
* [llama.cpp-Server](/guides/guides_v2-de/sprachmodelle/llamacpp-server.md) - Plattformübergreifend
* [Text Generation WebUI](/guides/guides_v2-de/sprachmodelle/text-generation-webui.md) - Weboberfläche


---

# 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/exllamav2-fast.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.
