Llama.cpp: Unterschied zwischen den Versionen

Aus XccesS Wiki
Zur Navigation springen Zur Suche springen
KKeine Bearbeitungszusammenfassung
 
(17 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">
cmake -B build-vulkan -DGGML_VULKAN=1
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)
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 (ROCm) ====
<syntaxhighlight lang="bash" line="1">
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
</syntaxhighlight>
'''Für MI50 (gfx906) — separater Build:'''
<syntaxhighlight lang="bash" line="1">
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>
==== ik_llama.cpp kompilieren (ROCm) ====


# llama.cpp kompilieren
<syntaxhighlight lang="bash" line="1">
HIPCXX="$(hipconfig -l)/clang" HIP_PATH="$(hipconfig -R)" \
cd ~/Programme/llama.cpp/ && rm -R build-rocm-old && cp -R build-rocm build-rocm-old
    cmake -B build-rocm -DGGML_HIP=ON -DAMDGPU_TARGETS=gfx906 -DGGML_HIP_ROCWMMA_FATTN=ON \
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
    -DCMAKE_BUILD_TYPE=Release
cmake --build build-rocm --config Release -- -j 16
cmake --build build-rocm --config Release -- -j 8
</syntaxhighlight>
</syntaxhighlight>


Für mehrere GPU-Architekturen gleichzeitig:
=== Build prüfen ===
 
<syntaxhighlight lang="bash" line="1">
<syntaxhighlight lang="bash" line="1">
# Für MI50 (gfx906) und RX 7900 XTX (gfx1100)
./build/bin/llama-server --version
HIPCXX="$(hipconfig -l)/clang" HIP_PATH="$(hipconfig -R)" \
    cmake -S . -B build -DGGML_HIP=ON -DAMDGPU_TARGETS="gfx906;gfx1100" \
    -DCMAKE_BUILD_TYPE=Release && \
    cmake --build build --config Release -- -j 8
</syntaxhighlight>
</syntaxhighlight>


=== Konfiguration ===
== Konfiguration ==


==== llama-server als systemd Service einrichten ====
=== llama-server als systemd Service einrichten ===


'''Service-Datei erstellen:'''
'''Service-Datei erstellen:'''
<syntaxhighlight lang="bash" line="1">
<syntaxhighlight lang="bash" line="1">
sudo nano /etc/systemd/system/llama-server.service
sudo nano /etc/systemd/system/llama-server.service
Zeile 54: Zeile 122:


'''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 61: 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 72: 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 100: 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
sudo journalctl -u llama-server -f    # Logs verfolgen
</syntaxhighlight>


# Status prüfen
'''Service verwalten:'''
sudo systemctl status llama-server


# Logs anzeigen
<syntaxhighlight lang="bash" line="1">
sudo journalctl -u llama-server -f
sudo systemctl stop llama-server      # Stoppen
sudo systemctl restart llama-server    # Neustarten
sudo systemctl disable llama-server   # Autostart deaktivieren
</syntaxhighlight>
</syntaxhighlight>


'''Service Management:'''
=== Manuelle Server-Starts ===
<syntaxhighlight lang="bash" line="1">
# Service stoppen
sudo systemctl stop llama-server
 
# Service neustarten
sudo systemctl restart llama-server


# Service deaktivieren
'''Multi-GPU (ROCm) — optimal:'''
sudo systemctl disable llama-server


==== Manuelle Server-Starts ====
'''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 147: Zeile 207:
</syntaxhighlight>
</syntaxhighlight>


=== Update ===
=== RPC — Verteiltes Inference über mehrere Hosts ===
 
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>.
 
'''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.
 
==== 1. RPC-Server auf allen Remote-Hosts starten ====
 
Auf jedem Host, der seine GPU zur Verfügung stellen soll:
 
<syntaxhighlight lang="bash" line="1">
cd ~/Programme/llama.cpp/
./build/bin/rpc-server --host 0.0.0.0
</syntaxhighlight>
 
Standardmäßig lauscht der rpc-server auf Port '''50052'''. Mit <code>--port</code> kann ein anderer Port gewählt werden.
 
==== 2. llama-server auf dem Main-Host starten ====
 
Auf dem Host, der die Inferenz koordiniert:
 
<syntaxhighlight lang="bash" line="1">
./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
</syntaxhighlight>
 
Dabei ist <code>localhost:50052</code> die lokale GPU und <code>192.168.1.19:50052</code> die Remote-GPU.
 
==== rpc-server als systemd Service (Remote-Host) ====
 
'''Service-Datei erstellen:'''
 
<syntaxhighlight lang="bash" line="1">
<syntaxhighlight lang="bash" line="1">
cd ~/llama.cpp
sudo nano /etc/systemd/system/llama-rpc.service
git pull
</syntaxhighlight>
cmake --build build --config Release -- -j $(nproc)
 
'''Service-Datei Inhalt:'''
 
<syntaxhighlight lang="ini" line="1">
[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


# Service neu starten falls aktiv
[Install]
sudo systemctl restart llama-server
WantedBy=multi-user.target
</syntaxhighlight>
</syntaxhighlight>


=== Test ===
'''Aktivieren:'''
=== Bekannte Probleme ===
 
<syntaxhighlight lang="bash" line="1">
<syntaxhighlight lang="bash" line="1">
Error 1 [ 34%] Linking HIP shared library ../../../bin/libggml-hip.so [ 34%] Built target ggml-hip gmake[1]: *** [CMakeFiles/Makefile2:1775: ggml/src/CMakeFiles/ggml-cpu.dir/all] Error 2 gmake: *** [Makefile:146: all] Error 2
sudo systemctl daemon-reload
sudo systemctl enable --now llama-rpc
</syntaxhighlight>
</syntaxhighlight>
Lösung:
 
== Update ==
 
<syntaxhighlight lang="bash" line="1">
<syntaxhighlight lang="bash" line="1">
GCC 13.3.0 konnte damit nicht umgehen, aber GCC 14.2.0 hat bessere C++-Standard-Compliance und kann diesen Header-Konflikt korrekt auflösen – deshalb funktioniert die Kompilierung jetzt mit der neueren Compiler-Version.
cd ~/Programme/llama.cpp
sudo update-alternatives --remove gcc /usr/bin/gcc-13
git pull
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-14 100
cmake --build build --config Release -- -j $(nproc)
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-13 50
sudo update-alternatives --config gcc
# Wähle gcc-14


sudo update-alternatives --remove g++ /usr/bin/g++-13
# Services neu starten falls aktiv
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-14 100
sudo systemctl restart llama-server
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-13 50
sudo systemctl restart llama-rpc    # falls RPC-Service läuft
sudo update-alternatives --config g++
# Wähle g++-14
</syntaxhighlight>
</syntaxhighlight>
=== Nützliche Links ===
 
* [https://github.com/ggml-org/llama.cpp Offizielles llama.cpp Repository]
== Parameter-Referenz ==
* [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]
{| class="wikitable"
* [https://huggingface.co/models?library=gguf GGUF Modelle auf Hugging Face]
|-
* [https://docs.rocm.com/ ROCm Dokumentation]
! Parameter !! Beschreibung
* [https://vulkan.lunarg.com/doc/sdk Vulkan SDK Dokumentation]
|-
| <code>-ngl 99</code> || Alle Layer auf GPU auslagern (Langform: <code>--gpu-layers</code>)
|-
| <code>-fa 1</code> || Flash Attention aktivieren
|-
| <code>-c 32768</code> || Kontextfenster-Größe
|-
| <code>-b 2048</code> || Batch-Size
|-
| <code>-ub 2048</code> || Physical USB batch size
|-
| <code>--split-mode row</code> || Tensor-Split-Modus (Multi-GPU)
|-
| <code>--tensor-split 0.5,0.5</code> || Gleichmäßige Aufteilung auf 2 GPUs
|-
| <code>--parallel 1</code> || Anzahl paralleler Sequenzen
|-
| <code>--jinja</code> || Jinja-Template-Support für Chat
|-
| <code>--rpc host:port,…</code> || RPC-Backends für verteiltes Inference
|-
| <code>-DGGML_RPC=ON</code> || CMake-Flag: RPC-Support einkompilieren
|}

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