> 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/fortgeschritten/multi-gpu-setup.md).

# Multi-GPU-Einrichtung

Führe große KI-Modelle über mehrere GPUs auf Clore.ai aus

Führe große KI-Modelle über mehrere GPUs auf CLORE.AI aus.

{% hint style="success" %}
Finde Multi-GPU-Server bei [CLORE.AI-Marktplatz](https://clore.ai/marketplace).
{% endhint %}

## Wann benötigst du Multi-GPU?

{% hint style="warning" %}
**Multi-GPU-Rigs der 80GB-Klasse sind auf dem Clore.ai-Marktplatz nicht gelistet.** Die größten heute gelisteten Systeme sind 4× RTX PRO 6000 Blackwell (je 96 GB, 380 GB gesamt) und 8–11× RTX 5090 (je 32 GB). Kapazitäten für A100 / H200 / B200 werden als [Bare Metal](https://clore.ai/bare-metal) auf Anfrage verkauft. Prüfe [GPU-Preise & Verfügbarkeit](/guides/guides_v2-de/erste-schritte/pricing.md) bevor du eine Bereitstellung dimensionierst.
{% endhint %}

| Modellgröße | Option mit einer GPU | Option mit mehreren GPUs |
| ----------- | -------------------- | ------------------------ |
| ≤13B        | RTX 3090 (Q4)        | Nicht erforderlich       |
| 30B         | RTX 4090 (Q4)        | 2x RTX 3090              |
| 70B         | A100 40 GB (Q4)      | 2x RTX 4090              |
| 70B FP16    | -                    | 2x A100 80 GB            |
| 100B+       | -                    | 4x A100 80 GB            |
| 405B        | -                    | 8x A100 80 GB            |

***

## Multi-GPU-Konzepte

### Tensor-Parallelismus (TP)

Modellschichten über GPUs aufteilen. Am besten für die Inferenz.

```
GPU 0: Schichten 1-20
GPU 1: Schichten 21-40
```

**Vorteile:** Geringere Latenz, einfache Einrichtung **Nachteile:** Erfordert eine Hochgeschwindigkeitsverbindung

### Pipeline-Parallelismus (PP)

Unterschiedliche Batches auf verschiedenen GPUs verarbeiten.

```
GPU 0: Batch 1 → GPU 1: Batch 1
GPU 0: Batch 2 → GPU 1: Batch 2
```

**Vorteile:** Höherer Durchsatz **Nachteile:** Höhere Latenz, komplexer

### Datenparallelismus (DP)

Dasselbe Modell auf mehreren GPUs, unterschiedliche Daten.

```
GPU 0: Batch A verarbeiten
GPU 1: Batch B verarbeiten
```

**Vorteile:** Einfaches, lineares Skalieren **Nachteile:** Jede GPU benötigt das vollständige Modell

***

## LLM-Multi-GPU-Setup

### vLLM (empfohlen)

**2 GPUs:**

```bash
python -m vllm.entrypoints.openai.api_server \
    --model meta-llama/Llama-3.1-70B-Instruct \
    --tensor-parallel-size 2 \
    --host 0.0.0.0
```

**4 GPUs:**

```bash
python -m vllm.entrypoints.openai.api_server \
    --model meta-llama/Llama-3.1-70B-Instruct \
    --tensor-parallel-size 4 \
    --host 0.0.0.0
```

**8 GPUs (für 405B):**

```bash
python -m vllm.entrypoints.openai.api_server \
    --model meta-llama/Llama-3.1-405B-Instruct \
    --tensor-parallel-size 8 \
    --host 0.0.0.0
```

### Ollama mit mehreren GPUs

Ollama verwendet automatisch mehrere GPUs, wenn verfügbar:

```bash
# Verfügbare GPUs prüfen
nvidia-smi

# Ollama erkennt automatisch alle GPUs und nutzt sie
ollama run llama3.1:70b
```

**Auf bestimmte GPUs beschränken:**

```bash
CUDA_VISIBLE_DEVICES=0,1 ollama run llama3.1:70b
```

### Text Generation Inference (TGI)

```bash
docker run --gpus all -p 8080:80 \\
    ghcr.io/huggingface/text-generation-inference:latest \\
    --model-id meta-llama/Llama-3.1-70B-Instruct \
    --num-shard 2
```

### llama.cpp

```bash
# GPU-Layer pro Gerät angeben
./llama-server \
    -m llama-3.1-70b-q4.gguf \
    -ngl 999 \
    --split-mode layer \
    --tensor-split 0.5,0.5
```

***

## Multi-GPU für Bildgenerierung

### ComfyUI

ComfyUI kann verschiedene Modelle auf verschiedene GPUs auslagern:

```python
# Im ComfyUI-Workflow
# Verwende "Load Checkpoint" mit device-Parameter
# device: "cuda:0" für die erste GPU
# device: "cuda:1" für die zweite GPU
```

**VAE auf separater GPU ausführen:**

```python
# Hauptmodell auf GPU 0
# VAE auf GPU 1
# Reduziert den VRAM-Druck
```

### Stable Diffusion WebUI

**Multi-GPU in webui-user.sh aktivieren:**

```bash
export COMMANDLINE_ARGS="--device-id 0"
# Oder für bestimmte Modelle:
export COMMANDLINE_ARGS="--lowvram --device-id 0,1"
```

### FLUX mit mehreren GPUs

```python
from diffusers import FluxPipeline
import torch

pipe = FluxPipeline.from_pretrained(
    "black-forest-labs/FLUX.1-dev",
    torch_dtype=torch.bfloat16
)

# Über GPUs verteilen
pipe.enable_model_cpu_offload()  # oder
pipe.to("cuda:0")  # Explizite GPU-Auswahl
```

***

## Multi-GPU-Training

### Verteiltes PyTorch

```python
import torch
import torch.distributed as dist
from torch.nn.parallel import DistributedDataParallel as DDP

# Initialisieren
dist.init_process_group("nccl")
local_rank = int(os.environ["LOCAL_RANK"])
torch.cuda.set_device(local_rank)

# Modell einpacken
model = YourModel().to(local_rank)
model = DDP(model, device_ids=[local_rank])

# Trainingsschleife wie gewohnt
```

**Starten:**

```bash
torchrun --nproc_per_node=2 train.py
```

### DeepSpeed

```python
import deepspeed

model, optimizer, _, _ = deepspeed.initialize(
    model=model,
    config={
        "train_batch_size": 32,
        "fp16": {"enabled": True},
        "zero_optimization": {"stage": 2}
    }
)
```

**Starten:**

```bash
deepspeed --num_gpus=2 train.py
```

### Accelerate (HuggingFace)

```python
from accelerate import Accelerator

accelerator = Accelerator()
model, optimizer, dataloader = accelerator.prepare(
    model, optimizer, dataloader
)
```

**Konfigurieren:**

```bash
accelerate config  # Interaktive Einrichtung
accelerate launch train.py
```

### Kohya-Training (LoRA)

```bash
# Multi-GPU-LoRA-Training
accelerate launch --num_processes=2 train_network.py \
    --pretrained_model_name_or_path="model.safetensors" \
    --train_data_dir="./images" \
    --output_dir="./output"
```

***

## GPU-Auswahl

### Verfügbare GPUs prüfen

```bash
# Alle GPUs auflisten
nvidia-smi

# Detaillierte Informationen
nvidia-smi -L

# Speichernutzung
nvidia-smi --query-gpu=index,memory.used,memory.total --format=csv
```

### Bestimmte GPUs auswählen

**Umgebungsvariable:**

```bash
# Verwende nur GPU 0 und 1
export CUDA_VISIBLE_DEVICES=0,1
python your_script.py

# Verwende nur GPU 2
export CUDA_VISIBLE_DEVICES=2
python your_script.py
```

**In Python:**

```python
import os
os.environ["CUDA_VISIBLE_DEVICES"] = "0,1"

# Oder mit torch
import torch
device = torch.device("cuda:0")  # Erste sichtbare GPU
device = torch.device("cuda:1")  # Zweite sichtbare GPU
```

***

## Leistungsoptimierung

### NVLink vs PCIe

| Verbindung | Bandbreite | Am besten geeignet für |
| ---------- | ---------- | ---------------------- |
| NVLink     | 600 GB/s   | Tensor-Parallelismus   |
| PCIe 4.0   | 32 GB/s    | Datenparallelismus     |
| PCIe 5.0   | 64 GB/s    | Gemischte Workloads    |

**NVLink-Status prüfen:**

```bash
nvidia-smi nvlink --status
```

### Optimale Konfiguration

| GPUs | TP-Größe | PP-Größe | Hinweise                           |
| ---- | -------- | -------- | ---------------------------------- |
| 2    | 2        | 1        | Einfacher Tensor-Parallelismus     |
| 4    | 4        | 1        | Erfordert NVLink                   |
| 4    | 2        | 2        | PCIe-freundlich                    |
| 8    | 8        | 1        | Vollständiger Tensor-Parallelismus |
| 8    | 4        | 2        | Gemischter Parallelismus           |

### Speicherausgleich

**Gleichmäßige Aufteilung (Standard):**

```bash
--tensor-parallel-size 2
```

**Benutzerdefinierte Aufteilung (ungleiche GPUs):**

```bash
# vLLM unterstützt keine ungleiche Aufteilung, verwende llama.cpp:
./llama-server --tensor-split 0.6,0.4
```

***

## Fehlerbehebung

### "NCCL-Fehler"

```bash
# NCCL-Debug setzen
export NCCL_DEBUG=INFO

# Verschiedene NCCL-Algorithmen ausprobieren
export NCCL_ALGO=Ring
```

### "Kein Speicher mehr auf GPU X"

```bash
# Speicher pro GPU prüfen
nvidia-smi

# Batch-Größe reduzieren
--max-batch-size 1

# Gradient Checkpointing aktivieren (Training)
--gradient-checkpointing
```

### "Langsame Multi-GPU-Leistung"

1. NVLink-Konnektivität prüfen
2. Tensor-Parallel-Größe reduzieren
3. Verwende stattdessen Pipeline-Parallelismus
4. CPU-Engpass prüfen

### "GPUs nicht erkannt"

```bash
# CUDA überprüfen
nvidia-smi

# Prüfen, ob PyTorch GPUs sieht
python -c "import torch; print(torch.cuda.device_count())"

# Falls nötig, CUDA-Treiber neu installieren
```

***

## Kostenoptimierung

### Wann sich Multi-GPU lohnt

| Szenario                  | Einzelne GPU                                           | Multi-GPU                                                 | Gewinner              |
| ------------------------- | ------------------------------------------------------ | --------------------------------------------------------- | --------------------- |
| 70B gelegentliche Nutzung | A100 80 GB ([Bare Metal](https://clore.ai/bare-metal)) | 2x RTX 4090 ($0.28–0.84/Std.)                             | Mehrere GPUs          |
| 70B-Produktion            | A100 40 GB ([Bare Metal](https://clore.ai/bare-metal)) | 2x A100 40 GB ([Bare Metal](https://clore.ai/bare-metal)) | Einzeln (Q4)          |
| Training 7B               | RTX 4090 ($0.14–0.42/Std.)                             | 2x RTX 4090 ($0.28–0.84/Std.)                             | Hängt von der Zeit ab |

### Kosteneffiziente Konfigurationen

| Anwendungsfall      | Konfiguration | \~Kosten/Std. |
| ------------------- | ------------- | ------------- |
| 70B-Inferenz        | 2x RTX 3090   | $0.12         |
| 70B-Schnellinferenz | 2x A100 40 GB | $0.34         |
| 70B FP16            | 2x A100 80 GB | $0.50         |
| Training 13B        | 2x RTX 4090   | $0.20         |

***

## Beispielkonfigurationen

### 70B-Chat-Server

```bash
# 2x A100 40 GB-Setup
python -m vllm.entrypoints.openai.api_server \
    --model meta-llama/Llama-3.1-70B-Instruct \
    --tensor-parallel-size 2 \
    --max-model-len 8192 \
    --host 0.0.0.0 \
    --port 8000
```

### DeepSeek-V3 (671B)

```bash
# 8x A100 80 GB erforderlich
python -m vllm.entrypoints.openai.api_server \
    --model deepseek-ai/DeepSeek-V3 \
    --tensor-parallel-size 8 \
    --trust-remote-code \
    --host 0.0.0.0
```

### Bild + LLM-Pipeline

```bash
# GPU 0: Stable Diffusion
CUDA_VISIBLE_DEVICES=0 python comfyui/main.py --port 8188 &

# GPU 1: LLM für Prompts
CUDA_VISIBLE_DEVICES=1 python -m vllm.entrypoints.openai.api_server \
    --model meta-llama/Llama-3.1-8B-Instruct --port 8000
```

***

## Nächste Schritte

* [vLLM-Anleitung](/guides/guides_v2-de/sprachmodelle/vllm.md) - Produktions-LLM-Serving
* [GPU-Vergleich](/guides/guides_v2-de/erste-schritte/gpu-comparison.md) - Wähle deine GPUs
* [API-Integration](/guides/guides_v2-de/fortgeschritten/api-integration.md) - Anwendungen erstellen
* [Kostenrechner](/guides/guides_v2-de/erste-schritte/cost-calculator.md) - Kosten schätzen


---

# 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/fortgeschritten/multi-gpu-setup.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.
