Llama.cpp: Unterschied zwischen den Versionen

Aus XccesS Wiki
Zur Navigation springen Zur Suche springen
KKeine Bearbeitungszusammenfassung
KKeine Bearbeitungszusammenfassung
 
(22 dazwischenliegende Versionen desselben Benutzers werden nicht angezeigt)
Zeile 1: Zeile 1:
=== Beschreibung ===
'''Hinweis:''' Alle Pfade beziehen sich auf <code>/home/hendrik/Programme/llama.cpp/</code> als Installationsverzeichnis. Bitte entsprechend anpassen.
llama.cpp ist eine C/C++ Implementierung für Inference von Large Language Models (LLMs). Es unterstützt verschiedene Backends (CPU, Vulkan, ROCm, CUDA) und ermöglicht das Ausführen von quantisierten Modellen im GGUF-Format.
 
== Beschreibung ==
 
'''llama.cpp''' ist eine C/C++ Implementierung für Inference von Large Language Models (LLMs). Es unterstützt verschiedene Backends (CPU, Vulkan, ROCm, CUDA) und ermöglicht das Ausführen von quantisierten Modellen im GGUF-Format.
 
'''ik_llama.cpp''' ist ein optimierter Fork von llama.cpp mit zusätzlichen Performance-Verbesserungen und Unterstützung für neuere GPU-Architekturen (z.B. gfx1151 / Strix Halo).
 
== Download ==
 
'''llama.cpp:'''
 
<syntaxhighlight lang="bash" line="1">
git clone https://github.com/ggml-org/llama.cpp ~/Programme/llama.cpp
cd ~/Programme/llama.cpp
</syntaxhighlight>
 
'''ik_llama.cpp:'''
 
<syntaxhighlight lang="bash" line="1">
git clone https://github.com/ikawrakow/ik_llama.cpp ~/Programme/llama.cpp
cd ~/Programme/llama.cpp
</syntaxhighlight>
 
== Installation ==
 
=== Voraussetzungen ===


=== Download ===
<syntaxhighlight lang="bash" line="1">
<syntaxhighlight lang="bash" line="1">
git clone https://github.com/ggml-org/llama.cpp
sudo dnf install libcurl-devel -y
cd llama.cpp
</syntaxhighlight>
</syntaxhighlight>


=== Installation ===
{| class="wikitable"
==== Vulkan Build ====
|-
[https://vulkan.lunarg.com/sdk/home Vulkan SDK] herunterladen
! GPU !! Architektur !! Standard-Target
entpacken, ins Verzeichnis wechseln und source setup-env.sh ausführen. Dann ins Verzeichnis wechseln wo llama.cpp installiert werden soll.
|-
Dort dann
| RX 7900 XTX || gfx1100 || '''ja'''
|-
| Strix Halo || gfx1151 || '''ja'''
|-
| MI50 / MI60 || gfx906 || separater Build (siehe unten)
|}
 
=== Vulkan Build ===
 
''Gilt für llama.cpp und ik_llama.cpp.''
 
[https://vulkan.lunarg.com/sdk/home Vulkan SDK] herunterladen, entpacken, ins Verzeichnis wechseln und <code>source setup-env.sh</code> ausführen. Dann ins llama.cpp-Verzeichnis wechseln:
 
<syntaxhighlight lang="bash" line="1">
<syntaxhighlight lang="bash" line="1">
git clone https://github.com/ggml-org/llama.cpp
source ~/Programme/Vulkan_SDK/1.4.335.0/setup-env.sh
cd llama.cpp
cd ~/Programme/llama.cpp/
cmake -B build -DGGML_VULKAN=1
rm -R build-vulkan
cmake --build build --config Release -- -j $(nproc)
cmake -B build-vulkan -DGGML_VULKAN=1 -DGGML_RPC=ON        # llama.cpp
# cmake -B build-vulkan -DLLAMA_VULKAN=on -DGGML_RPC=ON    # ik_llama.cpp
cmake --build build-vulkan --config Release -- -j $(nproc)
</syntaxhighlight>
</syntaxhighlight>


==== ROCm Build ====
=== ROCm Build (getestet mit ROCm 6.4.3 und 7.1.0) ===
gfx906 = Mi 50 Support<br>
 
gfx1100 = 7900 XTX Support
==== ROCm Quick-Install ====
 
Alle Befehle von der [https://rocm.docs.amd.com/projects/install-on-linux/en/latest/install/quick-start.html ROCm Quick-Start Seite] ausführen.
 
'''Wichtig für MI50 (gfx906) mit ROCm 6.4:'''<br>
Vor dem Reboot die rocblas-Bibliothek aus dem AUR ergänzen:
 
# [https://archlinux.org/packages/extra/x86_64/rocblas/ rocblas aus dem AUR] herunterladen (Version 6.4)
# Entpacken
# Alle Tensor-Dateien mit <code>gfx906</code> im Namen von <code>rocblas-…/opt/rocm/lib/rocblas/library</code> nach <code>/opt/rocm/lib/rocblas/library</code> kopieren
# Reboot
# Prüfen: <code>sudo update-alternatives --display rocm</code>
 
==== ROCm Umgebung einrichten (optional, bei Fehlern) ====


<syntaxhighlight lang="bash" line="1">
<syntaxhighlight lang="bash" line="1">
# ROCm Umgebung einrichten
echo 'export LD_LIBRARY_PATH=/opt/rocm/lib:$LD_LIBRARY_PATH' >> ~/.bashrc
echo 'export LD_LIBRARY_PATH=/opt/rocm/lib:$LD_LIBRARY_PATH' >> ~/.bashrc
echo 'export HSA_OVERRIDE_GFX_VERSION=9.0.6' >> ~/.bashrc  # Für MI50/MI60
echo 'export HSA_OVERRIDE_GFX_VERSION=9.0.6' >> ~/.bashrc  # Für MI50/MI60
source ~/.bashrc
source ~/.bashrc
sudo dnf install rocwmma-devel -y
</syntaxhighlight>


# llama.cpp kompilieren
==== llama.cpp kompilieren (ROCm) ====
git clone https://github.com/ggml-org/llama.cpp
cd llama.cpp
HIPCXX="$(hipconfig -l)/clang" HIP_PATH="$(hipconfig -R)" \
    cmake -S . -B build -DGGML_HIP=ON -DAMDGPU_TARGETS=gfx906 \
    -DCMAKE_BUILD_TYPE=Release && \
    cmake --build build --config Release -- -j 8
</syntaxhighlight>


Für mehrere GPU-Architekturen gleichzeitig:
<syntaxhighlight lang="bash" line="1">
<syntaxhighlight lang="bash" line="1">
# Für MI50 (gfx906) und RX 7900 XTX (gfx1100)
cd ~/Programme/llama.cpp/ && git pull && rm -R build-rocm-old && cp -R build-rocm build-rocm-old
HIPCXX="$(hipconfig -l)/clang" HIP_PATH="$(hipconfig -R)" \
HIPCXX="$(hipconfig -l)/clang" HIP_PATH="$(hipconfig -R)" cmake -B build-rocm -DGGML_HIP=ON -DGGML_RPC=ON -DAMDGPU_TARGETS=gfx1100,gfx1151 -DCMAKE_BUILD_TYPE=Release
    cmake -S . -B build -DGGML_HIP=ON -DAMDGPU_TARGETS="gfx906;gfx1100" \
cmake --build build-rocm --config Release -- -j 16
    -DCMAKE_BUILD_TYPE=Release && \
    cmake --build build --config Release -- -j 8
</syntaxhighlight>
</syntaxhighlight>


=== Konfiguration ===
'''Für MI50 (gfx906) — separater Build:'''


==== llama-server als systemd Service einrichten ====
'''Service-Datei erstellen:'''
<syntaxhighlight lang="bash" line="1">
<syntaxhighlight lang="bash" line="1">
sudo nano /etc/systemd/system/llama-server.service
cd ~/Programme/llama.cpp/ && rm -R build-rocm-old && cp -R build-rocm build-rocm-old
HIPCXX="$(hipconfig -l)/clang" HIP_PATH="$(hipconfig -R)" cmake -B build-rocm -DGGML_HIP=ON -DGGML_RPC=ON -DAMDGPU_TARGETS=gfx906 -DCMAKE_BUILD_TYPE=Release
cmake --build build-rocm --config Release -- -j 16
</syntaxhighlight>
</syntaxhighlight>


'''Service-Datei Inhalt (Single GPU):'''
==== ik_llama.cpp kompilieren (ROCm) ====
<syntaxhighlight lang="ini" line="1">
[Unit]
Description=Llama.cpp Server - Text Generation
After=network.target


[Service]
<syntaxhighlight lang="bash" line="1">
Type=simple
cd ~/Programme/llama.cpp/ && rm -R build-rocm-old && cp -R build-rocm build-rocm-old
User=username
HIPCXX="$(hipconfig -l)/clang" HIP_PATH="$(hipconfig -R)" cmake -B build-rocm -DGGML_HIP=ON -DGGML_RPC=ON -DAMDGPU_TARGETS=gfx1100,gfx1151 -DCMAKE_BUILD_TYPE=Release
Group=username
cmake --build build-rocm --config Release -- -j 16
WorkingDirectory=/home/username/llama.cpp/build/bin
</syntaxhighlight>


# ROCm/HIP Umgebungsvariablen
=== Build prüfen ===
Environment="HIP_VISIBLE_DEVICES=0"
Environment="HSA_OVERRIDE_GFX_VERSION=9.0.6"
Environment="PATH=/opt/rocm/bin:/usr/local/bin:/usr/bin:/bin"
Environment="LD_LIBRARY_PATH=/opt/rocm/lib"


# Server starten
<syntaxhighlight lang="bash" line="1">
ExecStart=/home/username/llama.cpp/build/bin/llama-server \
./build/bin/llama-server --version
  -m /home/username/models/model.gguf \
</syntaxhighlight>
  -ngl 99 \
  --host 0.0.0.0 \
  --port 8080 \
  -c 4096 \
  -b 512 \
  --threads 8


# Neustart bei Fehler
== Konfiguration ==
Restart=always
RestartSec=10


# Limits
=== llama-server als systemd Service einrichten ===
LimitNOFILE=65535
LimitMEMLOCK=infinity


# Logging
'''Service-Datei erstellen:'''
StandardOutput=journal
StandardError=journal
SyslogIdentifier=llama-server


[Install]
<syntaxhighlight lang="bash" line="1">
WantedBy=multi-user.target
sudo nano /etc/systemd/system/llama-server.service
</syntaxhighlight>
</syntaxhighlight>


'''Service-Datei Inhalt (Multi-GPU mit ROCm):'''
'''Service-Datei Inhalt (Multi-GPU mit ROCm):'''
<syntaxhighlight lang="ini" line="1">
<syntaxhighlight lang="ini" line="1">
[Unit]
[Unit]
Zeile 110: Zeile 130:
[Service]
[Service]
Type=simple
Type=simple
User=username
User=hendrik
Group=username
Group=hendrik
WorkingDirectory=/home/username/llama.cpp/build/bin
WorkingDirectory=/home/hendrik/Programme/llama.cpp/build/bin


# Multi-GPU Konfiguration
# Multi-GPU Konfiguration
Zeile 121: Zeile 141:


# Server mit optimalen Multi-GPU Einstellungen
# Server mit optimalen Multi-GPU Einstellungen
ExecStart=/home/username/llama.cpp/build/bin/llama-server \
ExecStart=/home/hendrik/Programme/llama.cpp/build/bin/llama-server \
   -m /home/username/models/model.gguf \
   -m /home/hendrik/models/model.gguf \
   --split-mode row \
   --split-mode row \
   --tensor-split 0.5,0.5 \
   --tensor-split 0.5,0.5 \
Zeile 149: Zeile 169:


'''Service aktivieren und starten:'''
'''Service aktivieren und starten:'''
<syntaxhighlight lang="bash" line="1">
<syntaxhighlight lang="bash" line="1">
# Service neu laden
sudo systemctl daemon-reload
sudo systemctl daemon-reload
 
sudo systemctl enable llama-server     # Auto-Start beim Boot
# Service aktivieren (Auto-Start beim Boot)
sudo systemctl enable llama-server
 
# Service starten
sudo systemctl start llama-server
sudo systemctl start llama-server
 
sudo systemctl status llama-server     # Status prüfen
# Status prüfen
sudo journalctl -u llama-server -f     # Logs verfolgen
sudo systemctl status llama-server
 
# Logs anzeigen
sudo journalctl -u llama-server -f
</syntaxhighlight>
</syntaxhighlight>


'''Service Management:'''
'''Service verwalten:'''
<syntaxhighlight lang="bash" line="1">
# Service stoppen
sudo systemctl stop llama-server
 
# Service neustarten
sudo systemctl restart llama-server
 
# Service deaktivieren
sudo systemctl disable llama-server
 
# Logs der letzten Stunde
sudo journalctl -u llama-server --since "1 hour ago"
</syntaxhighlight>
 
==== Mehrere Services für verschiedene Modelle ====


<syntaxhighlight lang="bash" line="1">
<syntaxhighlight lang="bash" line="1">
# Service für 20B Modell auf Port 8080
sudo systemctl stop llama-server       # Stoppen
sudo nano /etc/systemd/system/llama-server-20b.service
sudo systemctl restart llama-server   # Neustarten
 
sudo systemctl disable llama-server   # Autostart deaktivieren
# Service für 120B Modell auf Port 8086
sudo nano /etc/systemd/system/llama-server-120b.service
 
# Service für Embeddings auf Port 8081
sudo nano /etc/systemd/system/llama-server-embeddings.service
 
# Alle Services aktivieren
sudo systemctl daemon-reload
sudo systemctl enable llama-server-20b llama-server-120b llama-server-embeddings
sudo systemctl start llama-server-20b llama-server-120b llama-server-embeddings
</syntaxhighlight>
</syntaxhighlight>


==== Manuelle Server-Starts ====
=== Manuelle Server-Starts ===


'''Single GPU (Vulkan):'''
'''Multi-GPU (ROCm) — optimal:'''
<syntaxhighlight lang="bash" line="1">
cd ~/llama.cpp/build/bin
./llama-server \
  -m ~/models/model.gguf \
  --device Vulkan0 \
  -ngl 99 \
  --host 0.0.0.0 \
  --port 8080
</syntaxhighlight>


'''Single GPU (ROCm):'''
<syntaxhighlight lang="bash" line="1">
HIP_VISIBLE_DEVICES=0 ./llama-server \
  -m ~/models/model.gguf \
  -ngl 99 \
  --host 0.0.0.0 \
  --port 8080 \
  -c 4096 \
  -b 512 \
  --threads 8
</syntaxhighlight>
'''Multi-GPU (ROCm) - Optimal:'''
<syntaxhighlight lang="bash" line="1">
<syntaxhighlight lang="bash" line="1">
HIP_VISIBLE_DEVICES=0,1 ./llama-server \
HIP_VISIBLE_DEVICES=0,1 ./llama-server \
Zeile 242: Zeile 207:
</syntaxhighlight>
</syntaxhighlight>


'''Split-GGUF Modelle (mehrteilige Dateien):'''
=== RPC — Verteiltes Inference über mehrere Hosts ===
<syntaxhighlight lang="bash" line="1">
# Nur die erste Datei angeben - Rest wird automatisch geladen
HIP_VISIBLE_DEVICES=0,1 ./llama-server \
  -m ~/models/model-00001-of-00002.gguf \
  --split-mode row \
  --tensor-split 0.5,0.5 \
  -ngl 99 \
  --host 0.0.0.0 \
  --port 8086
</syntaxhighlight>


==== Wichtige Parameter ====
Mit <code>-DGGML_RPC=ON</code> wird der <code>rpc-server</code> mitgebaut, der es ermöglicht, die Inferenz über das Netzwerk auf mehrere Maschinen zu verteilen. Jeder Remote-Host stellt seine GPU(s) über einen rpc-server zur Verfügung; der Main-Host verbindet sich darüber mit <code>--rpc</code>.


{| class="wikitable"
'''Voraussetzung:''' Auf '''allen''' Hosts muss llama.cpp mit <code>-DGGML_RPC=ON</code> kompiliert sein (siehe Build-Abschnitte oben). Die Netzwerkverbindung zwischen den Hosts muss bestehen.
|-
! Parameter !! Beschreibung
|-
| <code>-m</code> || Modell-Pfad
|-
| <code>-ngl N</code> || Anzahl Layer auf GPU (99 = alle)
|-
| <code>-c N</code> || Context-Größe (Standard: 512)
|-
| <code>-b N</code> || Batch-Größe (Standard: 512)
|-
| <code>-ub N</code> || Micro-Batch-Größe (physisch)
|-
| <code>--threads N</code> || CPU Threads
|-
| <code>--split-mode row</code> || Multi-GPU: Row-Split (empfohlen)
|-
| <code>--tensor-split X,Y</code> || Multi-GPU: Verteilung (0.5,0.5 = 50/50)
|-
| <code>-fa 1</code> || Flash Attention aktivieren
|-
| <code>--parallel N</code> || Anzahl paralleler Anfragen
|-
| <code>--jinja</code> || Jinja-Template Unterstützung
|-
| <code>--host IP</code> || Bind-Adresse (0.0.0.0 = alle)
|-
| <code>--port N</code> || Port (Standard: 8080)
|}


=== Update ===
==== 1. RPC-Server auf allen Remote-Hosts starten ====
<syntaxhighlight lang="bash" line="1">
cd ~/llama.cpp
git pull
cmake --build build --config Release -- -j $(nproc)


# Service neu starten falls aktiv
Auf jedem Host, der seine GPU zur Verfügung stellen soll:
sudo systemctl restart llama-server
</syntaxhighlight>


=== Test ===
==== Server testen ====
<syntaxhighlight lang="bash" line="1">
<syntaxhighlight lang="bash" line="1">
# Health Check
cd ~/Programme/llama.cpp/
curl http://localhost:8080/health
./build/bin/rpc-server --host 0.0.0.0
</syntaxhighlight>


# Verfügbare Modelle
Standardmäßig lauscht der rpc-server auf Port '''50052'''. Mit <code>--port</code> kann ein anderer Port gewählt werden.
curl http://localhost:8080/v1/models


# Test-Anfrage
==== 2. llama-server auf dem Main-Host starten ====
curl http://localhost:8080/v1/chat/completions \
  -H "Content-Type: application/json" \
  -d '{
    "model": "model",
    "messages": [{"role": "user", "content": "Hello!"}],
    "max_tokens": 50
  }'
</syntaxhighlight>


==== Benchmarking ====
Auf dem Host, der die Inferenz koordiniert:


'''Single GPU Benchmark:'''
<syntaxhighlight lang="bash" line="1">
<syntaxhighlight lang="bash" line="1">
cd ~/llama.cpp/build/bin
./llama-server \
HIP_VISIBLE_DEVICES=0 ./llama-bench \
   --model ~/.lmstudio/models/unsloth/Step-3.7-Flash-GGUF/Step-3.7-Flash-UD-IQ4_XS-00001-of-00003.gguf \
   -m ~/models/model.gguf \
  -ngl 99
</syntaxhighlight>
 
'''Multi-GPU Benchmark (optimal):'''
<syntaxhighlight lang="bash" line="1">
HIP_VISIBLE_DEVICES=0,1 ./llama-bench \
  -m ~/models/model.gguf \
  --split-mode row \
  --tensor-split 0.5,0.5 \
   -ngl 99 \
   -ngl 99 \
   -b 512 \
   --rpc localhost:50052,192.168.1.19:50052
  --threads 8
</syntaxhighlight>
</syntaxhighlight>


'''Performance-Vergleich Script:'''
Dabei ist <code>localhost:50052</code> die lokale GPU und <code>192.168.1.19:50052</code> die Remote-GPU.
<syntaxhighlight lang="bash" line="1">
#!/bin/bash
cd ~/llama.cpp/build/bin


echo "=== GPU 0 only ==="
==== rpc-server als systemd Service (Remote-Host) ====
HIP_VISIBLE_DEVICES=0 ./llama-bench -m ~/models/model.gguf -ngl 99


echo -e "\n=== GPU 1 only ==="
'''Service-Datei erstellen:'''
HIP_VISIBLE_DEVICES=1 ./llama-bench -m ~/models/model.gguf -ngl 99


echo -e "\n=== Multi-GPU optimiert ==="
HIP_VISIBLE_DEVICES=0,1 ./llama-bench \
  -m ~/models/model.gguf \
  --split-mode row \
  --tensor-split 0.5,0.5 \
  -ngl 99
</syntaxhighlight>
=== Fehlerbehebung ===
====Server startet nicht====
=====Lösung 1: Logs prüfen=====
<syntaxhighlight lang="bash" line="1">
<syntaxhighlight lang="bash" line="1">
# Logs anzeigen
sudo nano /etc/systemd/system/llama-rpc.service
sudo journalctl -u llama-server -n 50
 
# Live-Logs
sudo journalctl -u llama-server -f
</syntaxhighlight>
</syntaxhighlight>


=====Lösung 2: Permissions prüfen=====
'''Service-Datei Inhalt:'''
<syntaxhighlight lang="bash" line="1">
# Binary ausführbar machen
chmod +x ~/llama.cpp/build/bin/llama-server


# Modell-Datei lesbar prüfen
<syntaxhighlight lang="ini" line="1">
ls -la ~/models/model.gguf
[Unit]
</syntaxhighlight>
Description=Llama.cpp RPC Server (Remote GPU)
After=network.target


=====Lösung 3: ROCm Umgebung prüfen=====
[Service]
<syntaxhighlight lang="bash" line="1">
Type=simple
# ROCm Info
User=hendrik
rocminfo
Group=hendrik
WorkingDirectory=/home/hendrik/Programme/llama.cpp/build/bin


# GPU Status
Environment="HIP_VISIBLE_DEVICES=0"
rocm-smi
Environment="PATH=/opt/rocm/bin:/usr/local/bin:/usr/bin:/bin"
Environment="LD_LIBRARY_PATH=/opt/rocm/lib"


# Umgebungsvariablen prüfen
ExecStart=/home/hendrik/Programme/llama.cpp/build/bin/rpc-server --host 0.0.0.0
echo $LD_LIBRARY_PATH
echo $HSA_OVERRIDE_GFX_VERSION
</syntaxhighlight>


====Multi-GPU Performance schlecht====
Restart=always
=====Lösung: Row-Split mit explizitem Tensor-Split verwenden=====
RestartSec=10
<syntaxhighlight lang="bash" line="1">
StandardOutput=journal
# FALSCH - schlechte Performance:
StandardError=journal
HIP_VISIBLE_DEVICES=0,1 ./llama-server -m model.gguf -ngl 99
SyslogIdentifier=llama-rpc


# RICHTIG - gute Performance:
[Install]
HIP_VISIBLE_DEVICES=0,1 ./llama-server \
WantedBy=multi-user.target
  -m model.gguf \
  --split-mode row \
  --tensor-split 0.5,0.5 \
  -ngl 99
</syntaxhighlight>
</syntaxhighlight>


====Split-GGUF lädt nicht====
'''Aktivieren:'''
=====Lösung: Nur erste Datei angeben=====
<syntaxhighlight lang="bash" line="1">
# llama.cpp lädt automatisch alle Teile
./llama-server -m ~/models/model-00001-of-00002.gguf -ngl 99
 
# Prüfe ob alle Dateien vorhanden sind:
ls -lh ~/models/model-*.gguf
</syntaxhighlight>


====Port bereits belegt====
=====Lösung: Anderen Port verwenden=====
<syntaxhighlight lang="bash" line="1">
<syntaxhighlight lang="bash" line="1">
# Prüfe welcher Prozess Port 8080 nutzt
sudo systemctl daemon-reload
sudo lsof -i :8080
sudo systemctl enable --now llama-rpc
 
# Nutze anderen Port
./llama-server -m model.gguf --port 8081
</syntaxhighlight>
</syntaxhighlight>


=== Integration mit Open-WebUI ===
== Update ==


'''Docker-Compose Konfiguration:'''
<syntaxhighlight lang="yaml" line="1">
services:
  open-webui:
    image: ghcr.io/open-webui/open-webui:main
    container_name: open-webui
    volumes:
      - /var/lib/docker/volumes/aichat_open-webui/_data:/app/backend/data
    ports:
      - 8087:8087
    environment:
      # Ollama
      - OLLAMA_BASE_URL=http://localhost:11434
     
      # Llama.cpp Server (OpenAI-kompatibel)
      - OPENAI_API_BASE_URLS=http://localhost:8080/v1;http://localhost:8086/v1
      - OPENAI_API_KEYS=sk-no-key-required;sk-no-key-required
     
      - WEBUI_SECRET_KEY
      - PORT=8087
    network_mode: host
    restart: unless-stopped
volumes:
  open-webui:
</syntaxhighlight>
=== Codeschnipsel ===
'''GPU Monitoring während Inference:'''
<syntaxhighlight lang="bash" line="1">
<syntaxhighlight lang="bash" line="1">
# ROCm GPU Monitoring
cd ~/Programme/llama.cpp
watch -n 1 rocm-smi
git pull
cmake --build build --config Release -- -j $(nproc)


# Oder detailliert
# Services neu starten falls aktiv
watch -n 1 'rocm-smi --showtemp --showmeminfo --showuse'
sudo systemctl restart llama-server
sudo systemctl restart llama-rpc    # falls RPC-Service läuft
</syntaxhighlight>
</syntaxhighlight>


'''Automatischer Service-Restart bei OOM:'''
== Parameter-Referenz ==
<syntaxhighlight lang="bash" line="1">
# In Service-Datei ergänzen:
[Service]
# ...
Restart=always
RestartSec=10
# Memory Limit setzen (optional)
MemoryMax=60G
</syntaxhighlight>


'''Health Check Script:'''
{| class="wikitable"
<syntaxhighlight lang="bash" line="1">
|-
#!/bin/bash
! Parameter !! Beschreibung
# /usr/local/bin/llama-health-check.sh
|-
 
| <code>-ngl 99</code> || Alle Layer auf GPU auslagern (Langform: <code>--gpu-layers</code>)
if ! curl -s http://localhost:8080/health > /dev/null; then
|-
    echo "Llama server not responding, restarting..."
| <code>-fa 1</code> || Flash Attention aktivieren
    systemctl restart llama-server
|-
fi
| <code>-c 32768</code> || Kontextfenster-Größe
</syntaxhighlight>
|-
 
| <code>-b 2048</code> || Batch-Size
Cron Job für Health Check:
|-
<syntaxhighlight lang="bash" line="1">
| <code>-ub 2048</code> || Physical USB batch size
# Alle 5 Minuten prüfen
|-
sudo crontab -e
| <code>--split-mode row</code> || Tensor-Split-Modus (Multi-GPU)
# Hinzufügen:
|-
*/5 * * * * /usr/local/bin/llama-health-check.sh
| <code>--tensor-split 0.5,0.5</code> || Gleichmäßige Aufteilung auf 2 GPUs
</syntaxhighlight>
|-
 
| <code>--parallel 1</code> || Anzahl paralleler Sequenzen
=== Nützliche Links ===
|-
* [https://github.com/ggml-org/llama.cpp Offizielles llama.cpp Repository]
| <code>--jinja</code> || Jinja-Template-Support für Chat
* [https://github.com/ggml-org/llama.cpp/blob/master/examples/server/README.md llama-server Dokumentation]
|-
* [https://github.com/ggml-org/llama.cpp/discussions llama.cpp Discussions]
| <code>--rpc host:port,…</code> || RPC-Backends für verteiltes Inference
* [https://huggingface.co/models?library=gguf GGUF Modelle auf Hugging Face]
|-
* [https://docs.rocm.com/ ROCm Dokumentation]
| <code>-DGGML_RPC=ON</code> || CMake-Flag: RPC-Support einkompilieren
* [https://vulkan.lunarg.com/doc/sdk Vulkan SDK Dokumentation]
|}

Aktuelle Version vom 3. Juni 2026, 14:43 Uhr

Hinweis: Alle Pfade beziehen sich auf /home/hendrik/Programme/llama.cpp/ als Installationsverzeichnis. Bitte entsprechend anpassen.

Beschreibung

llama.cpp ist eine C/C++ Implementierung für Inference von Large Language Models (LLMs). Es unterstützt verschiedene Backends (CPU, Vulkan, ROCm, CUDA) und ermöglicht das Ausführen von quantisierten Modellen im GGUF-Format.

ik_llama.cpp ist ein optimierter Fork von llama.cpp mit zusätzlichen Performance-Verbesserungen und Unterstützung für neuere GPU-Architekturen (z.B. gfx1151 / Strix Halo).

Download

llama.cpp:

git clone https://github.com/ggml-org/llama.cpp ~/Programme/llama.cpp
cd ~/Programme/llama.cpp

ik_llama.cpp:

git clone https://github.com/ikawrakow/ik_llama.cpp ~/Programme/llama.cpp
cd ~/Programme/llama.cpp

Installation

Voraussetzungen

sudo dnf install libcurl-devel -y
GPU Architektur Standard-Target
RX 7900 XTX gfx1100 ja
Strix Halo gfx1151 ja
MI50 / MI60 gfx906 separater Build (siehe unten)

Vulkan Build

Gilt für llama.cpp und ik_llama.cpp.

Vulkan SDK herunterladen, entpacken, ins Verzeichnis wechseln und source setup-env.sh ausführen. Dann ins llama.cpp-Verzeichnis wechseln:

source ~/Programme/Vulkan_SDK/1.4.335.0/setup-env.sh
cd ~/Programme/llama.cpp/
rm -R build-vulkan
cmake -B build-vulkan -DGGML_VULKAN=1 -DGGML_RPC=ON        # llama.cpp
# cmake -B build-vulkan -DLLAMA_VULKAN=on -DGGML_RPC=ON     # ik_llama.cpp
cmake --build build-vulkan --config Release -- -j $(nproc)

ROCm Build (getestet mit ROCm 6.4.3 und 7.1.0)

ROCm Quick-Install

Alle Befehle von der ROCm Quick-Start Seite ausführen.

Wichtig für MI50 (gfx906) mit ROCm 6.4:
Vor dem Reboot die rocblas-Bibliothek aus dem AUR ergänzen:

  1. rocblas aus dem AUR herunterladen (Version 6.4)
  2. Entpacken
  3. Alle Tensor-Dateien mit gfx906 im Namen von rocblas-…/opt/rocm/lib/rocblas/library nach /opt/rocm/lib/rocblas/library kopieren
  4. Reboot
  5. Prüfen: sudo update-alternatives --display rocm

ROCm Umgebung einrichten (optional, bei Fehlern)

echo 'export LD_LIBRARY_PATH=/opt/rocm/lib:$LD_LIBRARY_PATH' >> ~/.bashrc
echo 'export HSA_OVERRIDE_GFX_VERSION=9.0.6' >> ~/.bashrc  # Für MI50/MI60
source ~/.bashrc
sudo dnf install rocwmma-devel -y

llama.cpp kompilieren (ROCm)

cd ~/Programme/llama.cpp/ && git pull && rm -R build-rocm-old && cp -R build-rocm build-rocm-old
HIPCXX="$(hipconfig -l)/clang" HIP_PATH="$(hipconfig -R)" cmake -B build-rocm -DGGML_HIP=ON -DGGML_RPC=ON -DAMDGPU_TARGETS=gfx1100,gfx1151 -DCMAKE_BUILD_TYPE=Release
cmake --build build-rocm --config Release -- -j 16

Für MI50 (gfx906) — separater Build:

cd ~/Programme/llama.cpp/ && rm -R build-rocm-old && cp -R build-rocm build-rocm-old
HIPCXX="$(hipconfig -l)/clang" HIP_PATH="$(hipconfig -R)" cmake -B build-rocm -DGGML_HIP=ON -DGGML_RPC=ON -DAMDGPU_TARGETS=gfx906 -DCMAKE_BUILD_TYPE=Release
cmake --build build-rocm --config Release -- -j 16

ik_llama.cpp kompilieren (ROCm)

cd ~/Programme/llama.cpp/ && rm -R build-rocm-old && cp -R build-rocm build-rocm-old
HIPCXX="$(hipconfig -l)/clang" HIP_PATH="$(hipconfig -R)" cmake -B build-rocm -DGGML_HIP=ON -DGGML_RPC=ON -DAMDGPU_TARGETS=gfx1100,gfx1151 -DCMAKE_BUILD_TYPE=Release
cmake --build build-rocm --config Release -- -j 16

Build prüfen

./build/bin/llama-server --version

Konfiguration

llama-server als systemd Service einrichten

Service-Datei erstellen:

sudo nano /etc/systemd/system/llama-server.service

Service-Datei Inhalt (Multi-GPU mit ROCm):

[Unit]
Description=Llama.cpp ROCm Multi-GPU Server
After=network.target

[Service]
Type=simple
User=hendrik
Group=hendrik
WorkingDirectory=/home/hendrik/Programme/llama.cpp/build/bin

# Multi-GPU Konfiguration
Environment="HIP_VISIBLE_DEVICES=0,1"
Environment="HSA_OVERRIDE_GFX_VERSION=9.0.6"
Environment="PATH=/opt/rocm/bin:/usr/local/bin:/usr/bin:/bin"
Environment="LD_LIBRARY_PATH=/opt/rocm/lib"

# Server mit optimalen Multi-GPU Einstellungen
ExecStart=/home/hendrik/Programme/llama.cpp/build/bin/llama-server \
  -m /home/hendrik/models/model.gguf \
  --split-mode row \
  --tensor-split 0.5,0.5 \
  -ngl 99 \
  -fa 1 \
  --host 0.0.0.0 \
  --port 8080 \
  -c 32768 \
  -b 2048 \
  -ub 2048 \
  --threads 8 \
  --parallel 1 \
  --jinja

Restart=always
RestartSec=10
LimitNOFILE=65535
LimitMEMLOCK=infinity
StandardOutput=journal
StandardError=journal
SyslogIdentifier=llama-server

[Install]
WantedBy=multi-user.target

Service aktivieren und starten:

sudo systemctl daemon-reload
sudo systemctl enable llama-server     # Auto-Start beim Boot
sudo systemctl start llama-server
sudo systemctl status llama-server     # Status prüfen
sudo journalctl -u llama-server -f     # Logs verfolgen

Service verwalten:

sudo systemctl stop llama-server       # Stoppen
sudo systemctl restart llama-server    # Neustarten
sudo systemctl disable llama-server    # Autostart deaktivieren

Manuelle Server-Starts

Multi-GPU (ROCm) — optimal:

HIP_VISIBLE_DEVICES=0,1 ./llama-server \
  -m ~/models/model.gguf \
  --split-mode row \
  --tensor-split 0.5,0.5 \
  -ngl 99 \
  -fa 1 \
  --host 0.0.0.0 \
  --port 8080 \
  -c 32768 \
  -b 2048 \
  -ub 2048 \
  --threads 8 \
  --parallel 1 \
  --jinja

RPC — Verteiltes Inference über mehrere Hosts

Mit -DGGML_RPC=ON wird der rpc-server mitgebaut, der es ermöglicht, die Inferenz über das Netzwerk auf mehrere Maschinen zu verteilen. Jeder Remote-Host stellt seine GPU(s) über einen rpc-server zur Verfügung; der Main-Host verbindet sich darüber mit --rpc.

Voraussetzung: Auf allen Hosts muss llama.cpp mit -DGGML_RPC=ON kompiliert sein (siehe Build-Abschnitte oben). Die Netzwerkverbindung zwischen den Hosts muss bestehen.

1. RPC-Server auf allen Remote-Hosts starten

Auf jedem Host, der seine GPU zur Verfügung stellen soll:

cd ~/Programme/llama.cpp/
./build/bin/rpc-server --host 0.0.0.0

Standardmäßig lauscht der rpc-server auf Port 50052. Mit --port kann ein anderer Port gewählt werden.

2. llama-server auf dem Main-Host starten

Auf dem Host, der die Inferenz koordiniert:

./llama-server \
  --model ~/.lmstudio/models/unsloth/Step-3.7-Flash-GGUF/Step-3.7-Flash-UD-IQ4_XS-00001-of-00003.gguf \
  -ngl 99 \
  --rpc localhost:50052,192.168.1.19:50052

Dabei ist localhost:50052 die lokale GPU und 192.168.1.19:50052 die Remote-GPU.

rpc-server als systemd Service (Remote-Host)

Service-Datei erstellen:

sudo nano /etc/systemd/system/llama-rpc.service

Service-Datei Inhalt:

[Unit]
Description=Llama.cpp RPC Server (Remote GPU)
After=network.target

[Service]
Type=simple
User=hendrik
Group=hendrik
WorkingDirectory=/home/hendrik/Programme/llama.cpp/build/bin

Environment="HIP_VISIBLE_DEVICES=0"
Environment="PATH=/opt/rocm/bin:/usr/local/bin:/usr/bin:/bin"
Environment="LD_LIBRARY_PATH=/opt/rocm/lib"

ExecStart=/home/hendrik/Programme/llama.cpp/build/bin/rpc-server --host 0.0.0.0

Restart=always
RestartSec=10
StandardOutput=journal
StandardError=journal
SyslogIdentifier=llama-rpc

[Install]
WantedBy=multi-user.target

Aktivieren:

sudo systemctl daemon-reload
sudo systemctl enable --now llama-rpc

Update

cd ~/Programme/llama.cpp
git pull
cmake --build build --config Release -- -j $(nproc)

# Services neu starten falls aktiv
sudo systemctl restart llama-server
sudo systemctl restart llama-rpc    # falls RPC-Service läuft

Parameter-Referenz

Parameter Beschreibung
-ngl 99 Alle Layer auf GPU auslagern (Langform: --gpu-layers)
-fa 1 Flash Attention aktivieren
-c 32768 Kontextfenster-Größe
-b 2048 Batch-Size
-ub 2048 Physical USB batch size
--split-mode row Tensor-Split-Modus (Multi-GPU)
--tensor-split 0.5,0.5 Gleichmäßige Aufteilung auf 2 GPUs
--parallel 1 Anzahl paralleler Sequenzen
--jinja Jinja-Template-Support für Chat
--rpc host:port,… RPC-Backends für verteiltes Inference
-DGGML_RPC=ON CMake-Flag: RPC-Support einkompilieren