Llama.cpp: Unterschied zwischen den Versionen

Aus XccesS Wiki
Zur Navigation springen Zur Suche springen
KKeine Bearbeitungszusammenfassung
KKeine Bearbeitungszusammenfassung
 
Zeile 1: Zeile 1:
'''Hinweis:''' Alle Pfade beziehen sich auf <code>/home/hendrik/Programme/llama.cpp/</code> als Installationsverzeichnis. Bitte entsprechend anpassen.
== Beschreibung ==
== Beschreibung ==


Zeile 6: Zeile 8:


== Download ==
== Download ==
'''llama.cpp:'''


<syntaxhighlight lang="bash" line="1">
<syntaxhighlight lang="bash" line="1">
git clone https://github.com/ggml-org/llama.cpp
git clone https://github.com/ggml-org/llama.cpp ~/Programme/llama.cpp
cd llama.cpp
cd ~/Programme/llama.cpp
</syntaxhighlight>
</syntaxhighlight>


Für ik_llama.cpp den entsprechenden Fork klonen.
'''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 ==
== Installation ==


=== Vulkan Build ===
=== Voraussetzungen ===
 
''Gilt für llama.cpp und ik_llama.cpp.''


<syntaxhighlight lang="bash" line="1">
<syntaxhighlight lang="bash" line="1">
sudo dnf install libcurl-devel -y
sudo dnf install libcurl-devel -y
</syntaxhighlight>
</syntaxhighlight>
{| class="wikitable"
|-
! 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.''


[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:
[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">
source /home/hendrik/Programme/Vulkan_SDK/1.4.335.0/setup-env.sh
source ~/Programme/Vulkan_SDK/1.4.335.0/setup-env.sh
cd /home/hendrik/Programme/llama.cpp/
cd ~/Programme/llama.cpp/
rm -R build-vulkan
rm -R build-vulkan
cmake -B build-vulkan -DGGML_VULKAN=1 -DGGML_RPC=ON        # llama.cpp
cmake -B build-vulkan -DGGML_VULKAN=1 -DGGML_RPC=ON        # llama.cpp
Zeile 37: Zeile 59:
=== ROCm Build (getestet mit ROCm 6.4.3 und 7.1.0) ===
=== ROCm Build (getestet mit ROCm 6.4.3 und 7.1.0) ===


{| class="wikitable"
==== ROCm Quick-Install ====
|-
! GPU !! Architektur !! Bemerkung
|-
| MI50 / MI60 || gfx906 || nur llama.cpp
|-
| RX 7900 XTX || gfx1100 ||
|-
| Strix Halo || gfx1151 || nur ik_llama.cpp
|}
 
==== 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.
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.
Zeile 67: Zeile 78:
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
</syntaxhighlight>
<syntaxhighlight lang="bash" line="1">
sudo dnf install rocwmma-devel -y
sudo dnf install rocwmma-devel -y
</syntaxhighlight>
</syntaxhighlight>
Zeile 76: Zeile 84:


<syntaxhighlight lang="bash" line="1">
<syntaxhighlight lang="bash" line="1">
cd /home/hendrik/Programme/llama.cpp/ && git pull && rm -R build-rocm-old && cp -R build-rocm build-rocm-old
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 -DCMAKE_BUILD_TYPE=Release
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
cmake --build build-rocm --config Release -- -j 16
</syntaxhighlight>
</syntaxhighlight>


Für mehrere GPU-Architekturen gleichzeitig:
'''Für MI50 (gfx906) — separater Build:'''


<syntaxhighlight lang="bash" line="1">
<syntaxhighlight lang="bash" line="1">
# Für MI50 (gfx906) und RX 7900 XTX (gfx1100)
cd ~/Programme/llama.cpp/ && 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=gfx906 -DCMAKE_BUILD_TYPE=Release
    cmake -S . -B build -DGGML_HIP=ON -DGGML_RPC=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>


Zeile 94: Zeile 100:


<syntaxhighlight lang="bash" line="1">
<syntaxhighlight lang="bash" line="1">
cd /home/hendrik/Programme/llama.cpp/ && rm -R build-rocm-old && cp -R build-rocm build-rocm-old
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
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
cmake --build build-rocm --config Release -- -j 16
</syntaxhighlight>
=== Build prüfen ===
<syntaxhighlight lang="bash" line="1">
./build/bin/llama-server --version
</syntaxhighlight>
</syntaxhighlight>


Zeile 118: Zeile 130:
[Service]
[Service]
Type=simple
Type=simple
User=username
User=hendrik
Group=username
Group=hendrik
WorkingDirectory=/home/username/Programme/llama.cpp/build/bin
WorkingDirectory=/home/hendrik/Programme/llama.cpp/build/bin


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


# Server mit optimalen Multi-GPU Einstellungen
# Server mit optimalen Multi-GPU Einstellungen
ExecStart=/home/username/Programme/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 206: Zeile 218:


<syntaxhighlight lang="bash" line="1">
<syntaxhighlight lang="bash" line="1">
cd /home/hendrik/Programme/llama.cpp/
cd ~/Programme/llama.cpp/
./build/bin/rpc-server --host 0.0.0.0
./build/bin/rpc-server --host 0.0.0.0
</syntaxhighlight>
</syntaxhighlight>
Zeile 218: Zeile 230:
<syntaxhighlight lang="bash" line="1">
<syntaxhighlight lang="bash" line="1">
./llama-server \
./llama-server \
   --model /home/hendrik/.lmstudio/models/unsloth/Step-3.7-Flash-GGUF/Step-3.7-Flash-UD-IQ4_XS-00001-of-00003.gguf \
   --model ~/.lmstudio/models/unsloth/Step-3.7-Flash-GGUF/Step-3.7-Flash-UD-IQ4_XS-00001-of-00003.gguf \
   --gpu-layers 99 \
   -ngl 99 \
   --rpc localhost:50052,192.168.1.19:50052
   --rpc localhost:50052,192.168.1.19:50052
</syntaxhighlight>
</syntaxhighlight>
Zeile 242: Zeile 254:
[Service]
[Service]
Type=simple
Type=simple
User=username
User=hendrik
Group=username
Group=hendrik
WorkingDirectory=/home/username/Programme/llama.cpp/build/bin
WorkingDirectory=/home/hendrik/Programme/llama.cpp/build/bin


Environment="HIP_VISIBLE_DEVICES=0"
Environment="HIP_VISIBLE_DEVICES=0"
Zeile 250: Zeile 262:
Environment="LD_LIBRARY_PATH=/opt/rocm/lib"
Environment="LD_LIBRARY_PATH=/opt/rocm/lib"


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


Restart=always
Restart=always
Zeile 272: Zeile 284:


<syntaxhighlight lang="bash" line="1">
<syntaxhighlight lang="bash" line="1">
cd ~/llama.cpp
cd ~/Programme/llama.cpp
git pull
git pull
cmake --build build --config Release -- -j $(nproc)
cmake --build build --config Release -- -j $(nproc)


# Service neu starten falls aktiv
# Services neu starten falls aktiv
sudo systemctl restart llama-server
sudo systemctl restart llama-server
sudo systemctl restart llama-rpc    # falls RPC-Service läuft
sudo systemctl restart llama-rpc    # falls RPC-Service läuft
Zeile 287: Zeile 299:
! Parameter !! Beschreibung
! Parameter !! Beschreibung
|-
|-
| <code>-ngl 99</code> || Alle Layer auf GPU auslagern
| <code>-ngl 99</code> || Alle Layer auf GPU auslagern (Langform: <code>--gpu-layers</code>)
|-
|-
| <code>-fa 1</code> || Flash Attention aktivieren
| <code>-fa 1</code> || Flash Attention aktivieren

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