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

# Llama 4 (Scout & Maverick)

Führe Metas Llama-4-Scout-&-Maverick-MoE-Modelle auf Clore.ai-GPUs aus

Metas Llama 4, veröffentlicht im April 2025, markiert einen grundlegenden Wechsel zu **Mischung aus Experten (MoE)** Architektur. Statt alle Parameter für jedes Token zu aktivieren, leitet Llama 4 jedes Token an spezialisierte „Experten“-Subnetzwerke weiter — und liefert Spitzenleistung zu einem Bruchteil der Rechenkosten. Zwei Modelle mit offenen Gewichten sind verfügbar: **Scout** (ideal für eine einzelne GPU) und **Maverick** (Multi-GPU-Kraftpaket).

## Hauptfunktionen

* **MoE-Architektur**: Nur 17B Parameter pro Token aktiv (von insgesamt 109B/400B)
* **Riesige Kontextfenster**: Scout unterstützt 10M Tokens, Maverick unterstützt 1M Tokens
* **Nativ multimodal**: Versteht Text und Bilder sofort
* **Zwei Modelle**: Scout (16 Experten, für eine einzelne GPU geeignet) und Maverick (128 Experten, Multi-GPU)
* **Wettbewerbsfähige Leistung**: Scout erreicht das Niveau von Gemma 3 27B; Maverick konkurriert mit Modellen der GPT-4o-Klasse
* **Offene Gewichte**: Llama Community License (für die meisten kommerziellen Anwendungen kostenlos)

## Modellvarianten

| Modell       | Gesamtparameter | Aktive Parameter | Experten | Kontext | Mindest-VRAM (Q4) | Mindest-VRAM (FP16) |
| ------------ | --------------- | ---------------- | -------- | ------- | ----------------- | ------------------- |
| **Scout**    | 109B            | 17B              | 16       | 10M     | 12 GB             | 80 GB               |
| **Maverick** | 400B            | 17B              | 128      | 1M      | 48GB (multi)      | 320GB (multi)       |

## Anforderungen

| Komponente | Scout (Q4)  | Scout (FP16) | Maverick (Q4) |
| ---------- | ----------- | ------------ | ------------- |
| GPU        | 1× RTX 4090 | 1× H100      | 4× RTX 4090   |
| VRAM       | 24 GB       | 80 GB        | 4×24GB        |
| RAM        | 32 GB       | 64 GB        | 128 GB        |
| Festplatte | 50GB        | 120GB        | 250 GB        |
| CUDA       | 12.8+       | 12.8+        | 12.8+         |

**Empfohlene Clore.ai-GPU**: RTX 4090 24GB ($0.14–0.42/Stunde) für Scout — bestes Preis-Leistungs-Verhältnis

## Schnellstart mit Ollama

Der schnellste Weg, Llama 4 zum Laufen zu bringen:

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

# Scout ausführen (quantisiert, ~12GB VRAM)
ollama run llama4-scout

# Für längeren Kontext (verbraucht mehr VRAM)
ollama run llama4-scout --ctx-size 32768
```

### Ollama als API-Server

```bash
# Server im Hintergrund starten
ollama serve &

# Modell herunterladen
ollama pull llama4-scout

# Über die OpenAI-kompatible API abfragen
curl http://localhost:11434/v1/chat/completions \
  -H "Content-Type: application/json" \\
  -d '{
    "model": "llama4-scout",
    "messages": [{"role": "user", "content": "Erkläre die MoE-Architektur in 3 Sätzen"}]
  }'
```

## vLLM-Einrichtung (Produktion)

Für Produktions-Workloads mit höherem Durchsatz:

```bash
# vLLM installieren
pip install vllm

# Scout auf einer einzelnen GPU bereitstellen (quantisiert)
vllm serve meta-llama/Llama-4-Scout-17B-16E-Instruct \
  --max-model-len 32768 \
  --gpu-memory-utilization 0.90

# Scout auf 2 GPUs bereitstellen (längerer Kontext)
vllm serve meta-llama/Llama-4-Scout-17B-16E-Instruct \
  --tensor-parallel-size 2 \
  --max-model-len 128000 \
  --gpu-memory-utilization 0.90

# Maverick auf 4 GPUs bereitstellen
vllm serve meta-llama/Llama-4-Maverick-17B-128E-Instruct \
  --tensor-parallel-size 4 \
  --max-model-len 65536
```

### vLLM-Server abfragen

```python
from openai import OpenAI

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

response = client.chat.completions.create(
    model="meta-llama/Llama-4-Scout-17B-16E-Instruct",
    messages=[
        {"role": "system", "content": "Du bist ein hilfreicher Assistent."},
        {"role": "user", "content": "Schreibe eine Python-Funktion zur Berechnung von Fibonacci-Zahlen"}
    ],
    temperature=0.7,
    max_tokens=1024
)
print(response.choices[0].message.content)
```

## HuggingFace Transformers

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

model_name = "meta-llama/Llama-4-Scout-17B-16E-Instruct"

tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForCausalLM.from_pretrained(
    model_name,
    torch_dtype=torch.bfloat16,
    device_map="auto",
    load_in_4bit=True  # 4-Bit-Quantisierung für 24GB-GPUs
)

messages = [
    {"role": "system", "content": "Du bist ein hilfreicher Coding-Assistent."},
    {"role": "user", "content": "Schreibe eine REST-API mit FastAPI, die eine Todo-Liste verwaltet"}
]

input_ids = tokenizer.apply_chat_template(messages, return_tensors="pt").to(model.device)
output = model.generate(input_ids, max_new_tokens=2048, temperature=0.7, do_sample=True)
print(tokenizer.decode(output[0][input_ids.shape[-1]:], skip_special_tokens=True))
```

## Docker-Schnellstart

```bash
# Verwendung des vLLM-Docker-Images
docker run --gpus all -p 8000:8000 \
  -v ~/.cache/huggingface:/root/.cache/huggingface \
  vllm/vllm-openai:latest \
  --model meta-llama/Llama-4-Scout-17B-16E-Instruct \
  --max-model-len 32768
```

## Warum MoE auf Clore.ai wichtig ist

Traditionelle dichte Modelle (wie Llama 3.3 70B) benötigen enorm viel VRAM, weil alle 70B Parameter aktiv sind. Llama 4 Scout hat insgesamt 109B, aktiviert aber pro Token nur 17B — das bedeutet:

* **Gleiche Qualität wie dichte Modelle mit 70B+** zu einem Bruchteil der VRAM-Kosten
* **Passt auf eine einzelne RTX 4090** im quantisierten Modus
* **10M-Token-Kontext** — verarbeite gesamte Codebasen, lange Dokumente, Bücher
* **Günstiger zu mieten** — eine RTX 4090 für $0.14–0.42/Stunde statt eines Multi-GPU-Setups für 70B-Modelle

## Tipps für Clore.ai-Nutzer

* **Starte mit Scout Q4**: Beste Preis-Leistung auf der RTX 4090 — $0.14–0.42/Stunde, deckt 95% der Anwendungsfälle ab
* **Verwende `--max-model-len` mit Bedacht**: Setze den Kontext nicht höher als nötig — er reserviert VRAM. Beginne mit 8192 und erhöhe bei Bedarf
* **Tensor Parallel für Maverick**: Miete für Maverick Maschinen mit 4× RTX 4090; verwende `--tensor-parallel-size 4`
* **HuggingFace-Login erforderlich**: `huggingface-cli login` — du musst zuerst die Llama-Lizenz auf HF akzeptieren
* **Ollama für schnelle Tests, vLLM für die Produktion**: Ollama ist schneller einzurichten; vLLM bietet höheren Durchsatz für das Bereitstellen von APIs
* **GPU-Speicher überwachen**: `beobachte nvidia-smi` — MoE-Modelle können bei langen Sequenzen den VRAM in die Höhe treiben

## Fehlerbehebung

| Problem                            | Lösung                                                                                          |
| ---------------------------------- | ----------------------------------------------------------------------------------------------- |
| `OutOfMemoryError`                 | Reduziere `--max-model-len`, verwende Q4-Quantisierung oder rüste die GPU auf                   |
| Modell-Download schlägt fehl       | Ausführen `huggingface-cli login` und akzeptiere die Llama-4-Lizenz auf hf.co                   |
| Langsame Generierung               | Stelle sicher, dass die GPU verwendet wird (`nvidia-smi`); überprüfe `--gpu-memory-utilization` |
| vLLM stürzt beim Start ab          | Reduziere die Kontextlänge; stelle sicher, dass CUDA 11.8+ installiert ist                      |
| Ollama zeigt das falsche Modell an | Ausführen `ollama list` zur Überprüfung; `ollama rm` + `ollama pull` erneut herunterladen       |

## Weiterführende Lektüre

* [Meta-Llama-4-Blogbeitrag](https://llama.meta.com/)
* [HuggingFace-Modellkarte](https://huggingface.co/meta-llama/Llama-4-Scout-17B-16E-Instruct)
* [vLLM-Dokumentation](https://docs.vllm.ai/)
* [Ollama-Modellbibliothek](https://ollama.com/library/llama4-scout)


---

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