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

# PowerInfer

**CPU/GPU-hybride LLM-Inferenz, die Aktivierungs-Lokalität ausnutzt** — Führe 70B-Parameter-Modelle auf einer einzigen Consumer-GPU aus, indem die Berechnung intelligent zwischen CPU und GPU aufgeteilt wird.

> 🌟 **8.000+ GitHub-Sterne** | Entwickelt an der SJTU IPADS | MIT-Lizenz

***

## Was ist PowerInfer?

PowerInfer ist eine leistungsstarke Inferenz-Engine für Large Language Models, die eine zentrale Erkenntnis ausnutzt: **LLMs zeigen starke Aktivierungs-Lokalität** — eine kleine Teilmenge von Neuronen ("heiße Neuronen") wird konsistent über die meisten Inferenzschritte hinweg aktiviert, während die Mehrheit inaktiv bleibt.

PowerInfer nutzt diese Eigenschaft um:

1. **Halte heiße Neuronen auf der GPU** für schnelle Berechnung
2. **Verlagere kalte Neuronen auf CPU/RAM** ohne nennenswerten Qualitätsverlust
3. **Routiere dynamisch** Berechnung zwischen CPU und GPU basierend auf Aktivierungsmustern

Das Ergebnis: Du kannst ein 70B-Modell mit nur **16GB VRAM** statt mehr als 140GB ausschließlich auf GPU ausführen.

### Wesentliche Fähigkeiten

* **Unterstützung für Consumer-GPUs** — RTX 3090/4090 können 70B-Modelle ausführen
* **Neuronen-bewusste Planung** — ein Prädiktor bestimmt pro Inferenz CPU- vs. GPU-Routing
* **Minimale Qualitätsverschlechterung** — erhält >95% der Full-Precision-Qualität
* **Kompatibilität mit llama.cpp** — Unterstützung des GGUF-Formats
* **NUMA-bewusstes CPU-Offloading** — optimiert für CPUs mit hoher Kernzahl

### Warum PowerInfer auf Clore.ai verwenden?

Clore.ai vermietet GPUs zu deutlich niedrigeren Kosten als Cloud-Alternativen. Mit PowerInfer:

* Führe aus **Llama 2 70B** auf einer **einzigen RTX 4090** (24GB VRAM)
* Reduziere GPU-Mietkosten im Vergleich zu Multi-GPU-Setups
* Verarbeite lange Kontextfenster mit CPU-RAM als Überlauf
* Führe Modelle aus, die früher teure A100/H100-Instanzen erforderten

***

## Hardwareanforderungen

| Modellgröße | Min. VRAM | Empfohlenes RAM | Leistung      |
| ----------- | --------- | --------------- | ------------- |
| 7B          | 4GB       | 16GB            | Ausgezeichnet |
| 13B         | 6GB       | 32GB            | Sehr gut      |
| 34B         | 12GB      | 64GB            | Gut           |
| 70B         | 16GB      | 128GB           | Mäßig         |

{% hint style="info" %}
**CPU ist wichtig:** PowerInfer verlagert kalte Neuronen auf die CPU. Eine CPU mit hoher Kernzahl (AMD EPYC, Intel Xeon) und schneller Speicherbandbreite verbessert die Durchsatzrate für große Modelle erheblich.
{% endhint %}

***

## Schnellstart auf Clore.ai

### Schritt 1: Wähle deinen Server

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

* **NVIDIA GPU** mit 16GB+ VRAM (RTX 3090, RTX 4090, A100)
* **Hohe CPU-Kernanzahl** (idealerweise 16+ Kerne)
* **64GB+ RAM** für 70B-Modelle, 32GB für 13B-Modelle

### Schritt 2: Erstelle ein benutzerdefiniertes Docker-Image

PowerInfer benötigt ein benutzerdefiniertes Docker-Setup. Verwende dieses `Dockerfile`:

```dockerfile
FROM nvidia/cuda:12.1.0-devel-ubuntu22.04

# Installiere Abhängigkeiten
RUN apt-get update && apt-get install -y \
    git \
    cmake \
    build-essential \
    python3 \
    python3-pip \
    curl \
    wget \
    openssh-server \
    && rm -rf /var/lib/apt/lists/*

# Konfiguriere SSH
RUN mkdir /var/run/sshd && \
    echo 'root:powerinfer' | chpasswd && \
    sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config

# Klone und baue PowerInfer
RUN git clone https://github.com/SJTU-IPADS/PowerInfer.git /app/PowerInfer
WORKDIR /app/PowerInfer

RUN mkdir build && cd build && \
    cmake .. -DLLAMA_CUBLAS=ON && \
    cmake --build . --config Release -j$(nproc)

# Installiere Python-Abhängigkeiten für den Solver
RUN pip3 install torch numpy scipy

EXPOSE 22

CMD ["/bin/bash", "-c", "service ssh start && tail -f /dev/null"]
```

Baue und pushe zu Docker Hub oder verwende inline mit Clore.ai:

```bash
docker build -t deinname/powerinfer:latest .
docker push deinname/powerinfer:latest
```

### Schritt 3: Bereitstellung auf Clore.ai

Setze in deiner Clore.ai-Bestellung:

* **Docker-Image:** `deinname/powerinfer:latest`
* **Ports:** `22` (SSH)
* **Umgebung:** `NVIDIA_VISIBLE_DEVICES=all`

***

## PowerInfer aus dem Quellcode bauen

Wenn du es vorziehst, im Container zu bauen:

```bash
# SSH in deinen Clore.ai-Server
ssh root@<clore-node-ip> -p <ssh-port>

# Installiere Voraussetzungen
apt-get update && apt-get install -y git cmake build-essential python3 python3-pip

# Klone PowerInfer
git clone https://github.com/SJTU-IPADS/PowerInfer.git
cd PowerInfer

# Baue mit CUDA-Unterstützung
mkdir build && cd build
cmake .. -DLLAMA_CUBLAS=ON -DCMAKE_BUILD_TYPE=Release
cmake --build . --config Release -j$(nproc)

echo "Build abgeschlossen!"
ls -la bin/
```

### Build überprüfen

```bash
./build/bin/main --help
# Sollte die PowerInfer-CLI-Hilfe ausgeben
```

***

## Modelle beschaffen

### GGUF-Modelle herunterladen

PowerInfer verwendet das GGUF-Format (wie llama.cpp):

```bash
# Installiere HuggingFace CLI
pip3 install huggingface_hub

# Lade Llama 2 7B Q4 herunter (empfohlen für Tests)
huggingface-cli download TheBloke/Llama-2-7B-Chat-GGUF \
  llama-2-7b-chat.Q4_K_M.gguf \
  --local-dir ./models

# Lade Llama 2 70B Q4 herunter (erfordert 16GB+ VRAM)  
huggingface-cli download TheBloke/Llama-2-70B-Chat-GGUF \
  llama-2-70b-chat.Q4_K_M.gguf \
  --local-dir ./models
```

### Neuron-Prädiktor erzeugen (erforderlich für PowerInfer)

PowerInfer benötigt für jedes Modell einen Neuron-Aktivierungs-Prädiktor. Das ist der entscheidende Unterschied zu llama.cpp:

```bash
# Installiere Python-Dependencies für den Solver
pip3 install torch numpy scipy

# Erzeuge den Prädiktor für dein Modell
python3 PowerInfer/solver/solve.py \
  --model ./models/llama-2-7b-chat.Q4_K_M.gguf \
  --output ./predictors/llama-2-7b-chat \
  --target-gpu-layers 20 \
  --gpu-memory-gb 16

# Dies erstellt Prädiktor-Dateien in ./predictors/
ls ./predictors/llama-2-7b-chat/
```

{% hint style="warning" %}
**Prädiktor-Generierungszeit:** Das Erstellen eines Neuron-Prädiktors kann je nach Modellgröße 30–60 Minuten dauern. Dies ist eine einmalige Operation — der Prädiktor wird bei späteren Läufen wiederverwendet.
{% endhint %}

***

## Inferenz ausführen

### Einfache Inferenz (kein Prädiktor)

Zum Testen ohne Prädiktor-Generierung (standardmäßige GPU/CPU-Aufteilung):

```bash
./build/bin/main \
  -m ./models/llama-2-7b-chat.Q4_K_M.gguf \
  --gpu-layers 20 \
  -p "Erzähle mir etwas über Quantencomputing" \
  -n 256
```

### PowerInfer-Modus (mit Prädiktor)

Voller PowerInfer-Modus mit neuronenbewusstem Routing:

```bash
./build/bin/main \
  -m ./models/llama-2-7b-chat.Q4_K_M.gguf \
  --predictor-path ./predictors/llama-2-7b-chat \
  --gpu-layers 20 \
  --n-gpu-layers 20 \
  -p "Was ist der Sinn des Lebens?" \
  -n 512 \
  --ctx-size 4096
```

### Interaktiver Chat-Modus

```bash
./build/bin/main \
  -m ./models/llama-2-7b-chat.Q4_K_M.gguf \
  --predictor-path ./predictors/llama-2-7b-chat \
  --gpu-layers 20 \
  -i \
  --ctx-size 4096 \
  --temp 0.7 \
  --top-p 0.9 \
  --repeat-penalty 1.1 \
  --color
```

### Server-Modus (OpenAI-kompatible API)

```bash
./build/bin/server \
  -m ./models/llama-2-7b-chat.Q4_K_M.gguf \
  --predictor-path ./predictors/llama-2-7b-chat \
  --gpu-layers 20 \
  --host 0.0.0.0 \
  --port 8080 \
  --ctx-size 4096
```

***

## Optimierung der GPU-Layer-Aufteilung

Der `--gpu-layers` Parameter bestimmt, wie viele Transformer-Layers auf der GPU verbleiben sollen. Passe dies anhand deines VRAM an:

```bash
# Verfügbaren VRAM prüfen
nvidia-smi --query-gpu=memory.free,memory.total --format=csv

# Faustregel für Q4-Modelle:
# 7B:  ~0.13GB pro Layer  → 24GB-Karte = ~184 Layers (alle)
# 13B: ~0.18GB pro Layer  → 24GB-Karte = ~133 Layers
# 70B: ~0.23GB pro Layer  → 24GB-Karte = ~104 Layers (von 80 insgesamt)
```

**Layer-Zuweisungsleitfaden:**

| GPU-VRAM | 7B-Modell | 13B-Modell | 34B-Modell | 70B-Modell |
| -------- | --------- | ---------- | ---------- | ---------- |
| 8GB      | Alle (32) | 20 Layers  | 10 Layers  | 4 Layers   |
| 16GB     | Alle (32) | Alle (40)  | 25 Layers  | 10 Layers  |
| 24GB     | Alle (32) | Alle (40)  | Alle (60)  | 20 Layers  |
| 48GB     | Alle (32) | Alle (40)  | Alle (60)  | Alle (80)  |

***

## Leistungs-Benchmarks

### Durchsatzvergleich (Llama 2 70B, RTX 3090)

| Engine              | GPU-Layers            | Tokens/Sek   |
| ------------------- | --------------------- | ------------ |
| llama.cpp (nur GPU) | 20/80                 | \~4 t/s      |
| llama.cpp (nur CPU) | 0/80                  | \~1 t/s      |
| **PowerInfer**      | **20/80 + Prädiktor** | **\~12 t/s** |

{% hint style="success" %}
**3x Beschleunigung** gegenüber Standard-llama.cpp für große Modellinferenz auf Consumer-GPUs ist mit PowerInfers neuronenbewusster Planung typisch.
{% endhint %}

***

## Als Dienst betreiben

Erstelle einen systemd-Service für persistentes API-Serving:

```bash
cat > /etc/systemd/system/powerinfer.service << 'EOF'
[Unit]
Description=PowerInfer LLM Server
After=network.target

[Service]
Type=simple
WorkingDirectory=/app/PowerInfer
ExecStart=/app/PowerInfer/build/bin/server \
  -m /models/llama-2-13b-chat.Q4_K_M.gguf \
  --predictor-path /predictors/llama-2-13b-chat \
  --gpu-layers 30 \
  --host 0.0.0.0 \
  --port 8080 \
  --ctx-size 4096
Restart=always
RestartSec=5

[Install]
WantedBy=multi-user.target
EOF

systemctl daemon-reload
systemctl enable powerinfer
systemctl start powerinfer
systemctl status powerinfer
```

***

## API-Nutzung

Sobald der Server läuft, verwende jeden OpenAI-kompatiblen Client:

```python
from openai import OpenAI

client = OpenAI(
    base_url="http://<clore-node-ip>:<port>/v1",
    api_key="none"
)

response = client.chat.completions.create(
    model="local-model",
    messages=[
        {"role": "user", "content": "Erkläre neuronale Netze einfach"}
    ],
    max_tokens=256
)
print(response.choices[0].message.content)
```

***

## Fehlerbehebung

### CUDA: zu wenig Speicher

```bash
# GPU-Layers reduzieren
./build/bin/main -m model.gguf --gpu-layers 10  # Reduziere von 20

# Prüfe, was VRAM verwendet
nvidia-smi

# GPU-Speicher freigeben
sudo fuser -v /dev/nvidia*  # Prozesse anzeigen
```

### Langsame CPU-Inferenz

```bash
# CPU-Threading-Optimierung aktivieren
./build/bin/main -m model.gguf --threads $(nproc) --gpu-layers 20

# NUMA-Topologie prüfen
numactl --hardware

# An NUMA-Knoten nahe der GPU binden
numactl --cpunodebind=0 --membind=0 ./build/bin/main -m model.gguf
```

### Build schlägt fehl

```bash
# Stelle sicher, dass das CUDA-Toolkit installiert ist
nvcc --version

# Prüfe CMake-Version (benötigt 3.14+)
cmake --version

# Sauberer Build
rm -rf build && mkdir build
cd build && cmake .. -DLLAMA_CUBLAS=ON -DCUDA_TOOLKIT_ROOT_DIR=/usr/local/cuda
```

{% hint style="danger" %}
**Häufiges Problem:** Wenn `cmake` CUDA nicht finden kann, setze `CUDA_HOME` Umgebungsvariable: `export CUDA_HOME=/usr/local/cuda` bevor du cmake ausführst.
{% endhint %}

***

## Clore.ai GPU-Empfehlungen

Das CPU/GPU-hybride Design von PowerInfer verändert die Wirtschaftlichkeit des Betriebs großer Modelle. Clore.ai-Server mit GPUs mit hohem VRAM UND schnellen CPUs sind ideal.

| GPU       | VRAM  | Clore.ai-Preis | Max. Modell (Q4)              | Durchsatz (Llama 2 70B Q4) |
| --------- | ----- | -------------- | ----------------------------- | -------------------------- |
| RTX 3090  | 24 GB | \~$0.12/Stunde | 70B (mit 64GB+ RAM)           | \~8–12 tok/s               |
| RTX 4090  | 24 GB | \~$0.70/Stunde | 70B (schnelleres CPU-Offload) | \~12–18 tok/s              |
| A100 40GB | 40 GB | \~$1.20/Stunde | 70B (minimales Offload)       | \~35–45 tok/s              |
| A100 80GB | 80 GB | \~$2.00/Stunde | 70B Full-Precision            | \~50–60 tok/s              |

{% hint style="info" %}
**PowerInfer Sweet Spot:** Die RTX 3090 für \~$0.12/Stunde, die Llama 2 70B Q4 ausführt, ist ein Durchbruch für preisbewusste Nutzer. Du erhältst ein 70B-Modell für 10–12× weniger als die Miete einer A100. Der Durchsatz ist geringer (\~10 tok/s), aber für Forschung oder geringen Traffic unschlagbar im Preis-Leistungs-Verhältnis.
{% endhint %}

**CPU ist genauso wichtig wie GPU:** PowerInfer verlagert "kalte" Neuronen auf die CPU. Clore.ai-Server mit AMD EPYC- oder Intel Xeon-CPUs (viele Kerne, hohe Speicherbandbreite) übertreffen Single-Socket-Consumer-CPUs deutlich. Prüfe die Server-Spezifikationen vor der Miete für große Modellaufgaben.

**Speicherbandbreiten-Engpass:** Bei 70B-Modellen ist die CPU-RAM-Bandbreite der begrenzende Faktor während der Berechnung kalter Neuronen. Server mit DDR5 ECC-RAM oder HBM-nahen Architekturen erzielen besseren Durchsatz.

***

## Ressourcen

* 🐙 **GitHub:** [github.com/SJTU-IPADS/PowerInfer](https://github.com/SJTU-IPADS/PowerInfer)
* 📄 **Fachartikel:** [PowerInfer: Schnelles Serving großer Sprachmodelle mit einer Consumer-GPU](https://arxiv.org/abs/2312.12456)
* 🤗 **GGUF-Modelle:** [huggingface.co/TheBloke](https://huggingface.co/TheBloke)
* 🧩 **SJTU IPADS Labor:** [ipads.se.sjtu.edu.cn](https://ipads.se.sjtu.edu.cn)


---

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