()
| 35 | return False |
| 36 | |
| 37 | def _start_server(): |
| 38 | global _server_proc |
| 39 | if _server_proc and _server_proc.poll() is None: |
| 40 | # Check if thermal manager has requested a server restart (thread reduction) |
| 41 | try: |
| 42 | from core.thermal import get_thermal_manager |
| 43 | tm = get_thermal_manager() |
| 44 | if tm.restart_recommended: |
| 45 | info(f"Thermal: restarting server with {tm.current_threads} threads...") |
| 46 | _server_proc.terminate() |
| 47 | _server_proc.wait(timeout=10) |
| 48 | _server_proc = None |
| 49 | tm.restart_recommended = False |
| 50 | except Exception: |
| 51 | pass |
| 52 | if _server_proc and _server_proc.poll() is None: |
| 53 | return |
| 54 | |
| 55 | cfg = MODEL_CONFIG |
| 56 | cmd = [ |
| 57 | LLAMA_SERVER_BIN, |
| 58 | "--model", str(MODEL_PATH), |
| 59 | "--ctx-size", str(cfg["n_ctx"]), |
| 60 | "--threads", str(cfg["n_threads"]), |
| 61 | "--batch-size", str(cfg["batch_size"]), |
| 62 | "--cache-type-k", cfg["kv_type"], |
| 63 | "--cache-type-v", cfg["kv_type"], |
| 64 | "--flash-attn", "on", # fused attention kernel, 10-20% faster prefill |
| 65 | "--port", "8080", # was 8081 — collided with plannd/summarizer |
| 66 | "--log-disable", |
| 67 | ] |
| 68 | |
| 69 | info(f"Starting llama-server (ctx={cfg['n_ctx']}, threads={cfg['n_threads']}, batch={cfg['batch_size']}, kv={cfg['kv_type']}, fa=on)...") |
| 70 | _server_proc = subprocess.Popen( |
| 71 | cmd, |
| 72 | stdout=subprocess.DEVNULL, |
| 73 | stderr=subprocess.DEVNULL, |
| 74 | env=_get_env(), |
| 75 | ) |
| 76 | |
| 77 | if not _server_ready(): |
| 78 | error("llama-server failed to start.") |
| 79 | _server_proc.kill() |
| 80 | raise RuntimeError("llama-server did not become ready.") |
| 81 | info("Server ready.") |
| 82 | |
| 83 | # Start dedicated embed server (nomic on port 8082) alongside generation server |
| 84 | try: |
| 85 | from core.embed_server import start_embed_server |
| 86 | start_embed_server() |
| 87 | except Exception: |
| 88 | pass # embed server is optional — BM25 fallback remains active |
| 89 | |
| 90 | def stop_server(): |
| 91 | global _server_proc |
no test coverage detected