Refactor LLM runtime handling and enhance CLI documentation

- Updated `resolve_llm_runtime` to prioritize live configuration over legacy notes, ensuring accurate runtime resolution.
- Enhanced `tunnel_forwards` to prefer current configuration for LLM runtime, improving tunnel setup logic.
- Improved idle-killer logic to handle stale markers and provide clearer warnings in the status output.
- Updated CLI documentation in `cli.md` to reflect changes in command behavior and runtime handling.
- Enhanced tests to validate new runtime resolution logic and ensure proper handling of configuration states.
This commit is contained in:
Leonid Pershin
2026-08-21 05:40:22 +03:00
parent 82e36129cd
commit dc1fde9e3e
17 changed files with 464 additions and 152 deletions
+46 -1
View File
@@ -260,13 +260,29 @@ def provision_llm(cfg: Config, host: str, log: Log) -> None:
from gpu_rent.state import load_state, save_state
runtime = normalize_runtime(cfg.llm_runtime)
def _stop_units(*names: str) -> None:
for name in names:
run_ssh(
cfg,
host,
f"sudo -n systemctl stop {name} 2>/dev/null; "
f"sudo -n systemctl disable {name} 2>/dev/null || true",
check=False,
)
# Always drop the other runtime so VRAM is not held by a leftover unit.
if runtime == "none":
log("LLM: none — останавливаю gpu-rent-ollama / gpu-rent-llamacpp если были")
_stop_units("gpu-rent-ollama", "gpu-rent-llamacpp")
st = load_state()
st.notes = dict(st.notes or {})
st.notes["llm_runtime"] = "none"
st.notes.pop("llm_error", None)
save_state(st)
return
if runtime == "ollama":
_stop_units("gpu-rent-llamacpp")
log("LLM: ставим/запускаем Ollama")
run_script_sudo(
cfg,
@@ -278,6 +294,9 @@ def provision_llm(cfg: Config, host: str, log: Log) -> None:
log=log,
)
entries = parse_ollama_models(cfg.ollama_models_manifest)
defaults = [e.name for e in entries if e.default]
if defaults:
log(f"Ollama preferred: {defaults[0]}")
names = [e.name for e in entries]
if not names:
log("ollama-models.yaml пуст — pull skip")
@@ -293,6 +312,7 @@ def provision_llm(cfg: Config, host: str, log: Log) -> None:
log=log,
)
elif runtime == "llamacpp":
_stop_units("gpu-rent-ollama")
log("LLM: ставим/запускаем llama.cpp server")
run_script_sudo(
cfg,
@@ -306,6 +326,7 @@ def provision_llm(cfg: Config, host: str, log: Log) -> None:
st = load_state()
st.notes = dict(st.notes or {})
st.notes["llm_runtime"] = runtime
st.notes.pop("llm_error", None)
save_state(st)
@@ -337,15 +358,39 @@ def provision_vm(
if cfg.pull_output:
pull_tree(cfg, host, f"{DATA}/Output", cfg.local_output_dir, log)
ensure_swarmui_running(cfg, host, log, restart=restart)
from gpu_rent.state import load_state, save_state
try:
provision_llm(cfg, host, log)
except Exception as exc:
log(f"LLM runtime: {exc}")
st = load_state()
st.notes = dict(st.notes or {})
st.notes["llm_error"] = str(exc)[:500]
# Do not claim success — leave previous notes.llm_runtime or clear to none.
st.notes["llm_runtime"] = "none"
save_state(st)
raise CloudError(f"LLM runtime: {exc}") from exc
if conn is not None and server_id:
try:
arm_idle_killer(cfg, host, conn, server_id, log)
st = load_state()
st.notes = dict(st.notes or {})
st.notes["idle_killer"] = "armed"
st.notes.pop("idle_killer_error", None)
save_state(st)
except GpuRentError as exc:
log(f"idle-killer: {exc}")
st = load_state()
st.notes = dict(st.notes or {})
st.notes["idle_killer"] = "failed"
st.notes["idle_killer_error"] = str(exc)[:500]
save_state(st)
log(
"⚠ idle-killer НЕ вооружён — GPU может тарифицироваться без авто-stop. "
"См. status / docs/setup.md"
)
log("SwarmUI слушает 127.0.0.1:7801 — gpu-rent tunnel")
from gpu_rent.llm_runtime import normalize_runtime