Funk-lab/ansible/roles/llama_server/tasks/main.yml
ALI YESILKAYA 577d61ebaa
feat: anti-502 LLM — heartbeat (litellm) + watchdog auto-réparation (llama_server) (#23)
* feat(litellm): heartbeat anti-502 + request_timeout 20s

Cause racine du 502 « 1ʳᵉ demande après une pause » : la connexion keep-alive
LiteLLM↔llama-server devient inactive → llama-server la ferme → LiteLLM garde le
socket mort → la requête suivante part dans le vide → timeout → 502.

- llm-heartbeat : service systemd qui appelle hermes-default toutes les 15s
  (max_tokens:1, /no_think → ~10ms GPU) → la connexion n'est jamais inactive,
  jamais périmée. Logge les échecs → sert aussi de sonde (vraie génération).
- request_timeout 60→20s : un socket périmé échoue vite, dans la fenêtre où
  num_retries:2 peut rejouer sur une connexion neuve (sinon le client abandonnait
  avant le retry → 502 sec).
- Doc : admin/incidents-llm-gpu.md (fix racine) + README rôle.

⚠️ heartbeat appelle hermes-default en continu → si bascule sur Claude (facturé),
mettre llm_heartbeat_enabled: false. request_timeout global → remonter si Claude.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

* feat(llama_server): watchdog auto-réparation du wedge ROCm

Service systemd local sur gpu-01 qui sonde une vraie génération sur :1234
(pas juste /health, qui ment quand le slot d'inférence est figé). Sur N
échecs consécutifs → systemctl restart llama-server en local (root, sans
SSH/sudo distant). Gère le 503 "Loading model" post-restart sans le compter
comme échec.

Complète le llm-heartbeat (rôle litellm) : le heartbeat empêche la péremption
par inactivité de la connexion ; le watchdog répare le figeage du serveur lui-même.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-19 20:52:29 +02:00

153 lines
4 KiB
YAML

---
- name: Install build dependencies
ansible.builtin.dnf:
name:
- cmake
- gcc-c++
- git
- patchelf
- hipblas-devel
- rocblas-devel
- hip-devel
- hipcc
state: present
- name: Clone llama.cpp
ansible.builtin.git:
repo: https://github.com/ggerganov/llama.cpp
dest: /opt/llama.cpp
depth: 1
version: "{{ llama_server_commit | default('HEAD') }}"
register: llama_clone
- name: Check if llama-server binary exists
ansible.builtin.stat:
path: /opt/llama.cpp/build/bin/llama-server
register: llama_server_binary_stat
- name: Configure cmake build (ROCm HIP)
ansible.builtin.command:
cmd: >
cmake -B build
-DGGML_HIP=ON
-DAMDGPU_TARGETS={{ llama_amdgpu_targets }}
-DCMAKE_BUILD_TYPE=Release
-DROCM_PATH={{ rocm_path }}
-DCMAKE_PREFIX_PATH={{ rocm_path }}
-DCMAKE_HIP_COMPILER={{ rocm_path }}/llvm/bin/clang++
chdir: /opt/llama.cpp
environment:
PATH: "{{ rocm_path }}/bin:{{ ansible_env.PATH }}"
when: llama_clone is changed or not llama_server_binary_stat.stat.exists
- name: Build llama-server
ansible.builtin.command:
cmd: cmake --build build --target llama-server -j{{ ansible_processor_nproc }}
chdir: /opt/llama.cpp
environment:
PATH: "{{ rocm_path }}/bin:{{ ansible_env.PATH }}"
when: llama_clone is changed or not llama_server_binary_stat.stat.exists
- name: Deploy systemd service
ansible.builtin.template:
src: llama-server.service.j2
dest: /etc/systemd/system/llama-server.service
mode: '0644'
notify:
- Reload systemd
- Restart llama-server
- name: Enable llama-server service
ansible.builtin.systemd:
name: llama-server
enabled: true
daemon_reload: true
state: started
- name: Open port in firewall
ansible.posix.firewalld:
port: "{{ llama_server_port }}/tcp"
permanent: true
state: enabled
immediate: true
- name: Disable lm-studio service (replaced by llama-server)
ansible.builtin.systemd:
name: lm-studio
enabled: false
state: stopped
ignore_errors: true
# --- Instance dédiée embeddings (nomic-embed-text) — optionnelle ---------------
- name: Ensure embedding model directory exists
ansible.builtin.file:
path: "{{ llama_embed_model_path | dirname }}"
state: directory
mode: '0755'
when: llama_embed_enabled and llama_embed_model_path | length > 0
- name: Download embedding model (GGUF) if absent
ansible.builtin.get_url:
url: "{{ llama_embed_model_url }}"
dest: "{{ llama_embed_model_path }}"
mode: '0644'
timeout: 120
when:
- llama_embed_enabled
- llama_embed_model_url | length > 0
- llama_embed_model_path | length > 0
- name: Deploy embedding llama-server service
ansible.builtin.template:
src: llama-embed.service.j2
dest: /etc/systemd/system/llama-embed.service
mode: '0644'
notify:
- Reload systemd
- Restart llama-embed
when: llama_embed_enabled
- name: Enable embedding llama-server service
ansible.builtin.systemd:
name: llama-embed
enabled: true
daemon_reload: true
state: started
when: llama_embed_enabled
- name: Open embedding port in firewall
ansible.posix.firewalld:
port: "{{ llama_embed_port }}/tcp"
permanent: true
state: enabled
immediate: true
when: llama_embed_enabled
# --- Watchdog auto-réparation (wedge ROCm) — optionnel ------------------------
- name: Deploy llama-watchdog script
ansible.builtin.template:
src: llama-watchdog.sh.j2
dest: /usr/local/bin/llama-watchdog
mode: '0755'
notify: Restart llama-watchdog
when: llama_watchdog_enabled
- name: Deploy llama-watchdog service
ansible.builtin.template:
src: llama-watchdog.service.j2
dest: /etc/systemd/system/llama-watchdog.service
mode: '0644'
notify:
- Reload systemd
- Restart llama-watchdog
when: llama_watchdog_enabled
- name: Enable llama-watchdog service
ansible.builtin.systemd:
name: llama-watchdog
enabled: true
daemon_reload: true
state: started
when: llama_watchdog_enabled