No description
Find a file
neil 8611d92cf4 MLX: cap KV caches and recover from crashes; add llmhost watch
- mlx_lm.server kept up to 10 conversations' KV caches with no byte
  limit and prefilled 8 prompts at once, which ran a 16 GB Mac out of
  GPU memory. The plan now gives the live request half the free memory
  (at least 32k tokens), caps --prompt-cache-bytes to the rest, and on
  small machines prefills one prompt at a time.
- When its generation thread dies, mlx_lm.server keeps running but fails
  every request. The proxy now restarts it.
- llmhost watch: one live line with download progress (bytes, speed,
  time left), then loading, until the model answers. Setup and switch
  point at it instead of llmhost logs -f.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QaE1hpvyZTJixEbUUMj9Ca
2026-11-02 07:45:12 -08:00
llmhost MLX: cap KV caches and recover from crashes; add llmhost watch 2026-11-02 07:45:12 -08:00
tools Initial llm-host: hardware-aware local LLM server with dashboard 2026-11-02 03:51:06 -08:00
.gitignore Initial llm-host: hardware-aware local LLM server with dashboard 2026-11-02 03:51:06 -08:00
install.sh Installer: add ~/.local/bin to PATH instead of only warning 2026-11-02 05:44:35 -08:00
README.md MLX: cap KV caches and recover from crashes; add llmhost watch 2026-11-02 07:45:12 -08:00

llm-host

Turn a machine with a decent GPU into a local LLM server for coding agents like opencode. llm-host detects the hardware, picks the models (and the right build of each) that fit, installs the inference backend, and runs it as a background service with a web dashboard.

  • Linux + NVIDIA → vLLM
  • macOS on Apple Silicon → MLX, behind a small proxy that adds API keys

Either way you get the same OpenAI-compatible API (with an API key) on port 1134 and a dashboard on port 11340. Everything installs into your home directory; no sudo, Docker or system CUDA toolkit needed.

Install

On the machine that will run the models:

/bin/bash -c "$(curl -fsSL https://git.neilbantoc.dev/pub/llm-host/raw/branch/main/install.sh)"

It shows the plan (which models fit, which build, how much context) and asks before installing. Pass setup options after --:

/bin/bash -c "$(curl -fsSL https://git.neilbantoc.dev/pub/llm-host/raw/branch/main/install.sh)" -- --yes --default ornith-1.5-35b

Ports: the API defaults to 1134 and the dashboard to 11340. On a first install a busy default moves to the next free port; after that the ports are saved and never move on their own (clients are configured with them). Change them with llmhost setup --api-port <port> --web-port <port>. On a Mac, MLX also uses the API port + 1.

Preview what a machine would get without installing anything (needs only Python 3.11+):

git clone https://git.neilbantoc.dev/pub/llm-host.git && cd llm-host
PYTHONPATH=. python3 -P -m llmhost plan                       # this machine
PYTHONPATH=. python3 -P -m llmhost plan --simulate nvidia:24:8.9   # an RTX 4090
PYTHONPATH=. python3 -P -m llmhost plan --simulate apple:64        # a 64 GB Mac

Use

Command
llmhost status service state and URLs
llmhost models models that fit this machine (* = active)
llmhost switch <model> serve a different model (downloads it first if needed)
llmhost download <model> download ahead of time
llmhost watch download and loading progress, until the model is ready
llmhost logs -f follow the model server log
llmhost start / stop / restart control the model server (stop frees the GPU)
llmhost key print the API key
llmhost opencode-setup install opencode here if needed and connect it to this server
llmhost opencode-config print what to add to opencode on another machine
llmhost update pull the latest llm-host and re-plan (--backend also upgrades vLLM/MLX)
llmhost uninstall [--purge] [--models] remove services and backends; asks before deleting downloaded models (--models deletes without asking)

The dashboard (http://<host>.local:11340) shows the active model, throughput, KV cache, GPU utilization, temperature and power with 10-minute charts, the server log, and buttons to switch models or stop the server.

Connecting opencode

On the server itself, setup handles it: if opencode isn't installed it offers to install it (official installer, into ~/.opencode/bin), then adds an llmhost provider to ~/.config/opencode/opencode.json pointing at http://localhost:<api port>/v1 and reading the key straight from llm-host's key file. Other providers and your default model are left alone; the first change backs the file up as opencode.json.before-llmhost. llmhost update keeps the provider's port and model list in sync. Run it on demand with llmhost opencode-setup (--yes to install without asking); skip it during setup with --no-opencode, or install without asking with --opencode. A config with comments (.jsonc) is never rewritten, since that would drop them; setup prints the block to paste instead.

On another machine, run llmhost opencode-config on the server. It prints a provider block and a one-liner that copies the API key over. Only one model is loaded at a time; pick the one the server is currently running.

How models are chosen

llmhost/catalog.json lists each model with every build of it (FP8, BF16, NVFP4, AWQ, MLX 8/6/4-bit), its size, and its KV-cache cost per token (measured on real hardware). For each model, llm-host tries builds in preference order and keeps the first that fits:

weights + ~3 GiB overhead + KV cache for 32k tokens  ≤  usable GPU memory
  • NVIDIA: usable = VRAM × 0.90 (0.95 if needed), summed over GPUs with tensor parallelism. Builds are filtered by compute capability (NVFP4 needs Blackwell; FP8 and BF16 need Ampere or newer). vLLM then sizes the context window to the memory that's actually left (--max-model-len -1).
  • Apple Silicon: usable = the GPU's share of unified memory (macOS allows ~67–75% by default, or iogpu.wired_limit_mb if you've raised it). MLX keeps an fp16 KV cache, so it's counted double.

--prefer changes the order: balanced (default: FP8 on NVIDIA, 6-bit on Mac), quality (BF16 / 8-bit), or speed (NVFP4 / 4-bit).

To add a model: add an entry to catalog.json (copy an existing one; vLLM flags such as the tool-call and reasoning parsers come from the model card or the vLLM recipes), then run python3 tools/refresh_catalog.py --write to fill in sizes, and llmhost update on each server.

What setup does on Linux + NVIDIA

These avoid problems that come up on a fresh desktop install without sudo:

  • vLLM goes in its own venv built on uv's Python (distro Pythons often lack the headers Triton needs).
  • vLLM compiles some GPU kernels at startup and needs nvcc. Setup installs the CUDA compiler from pip, pinned to the CUDA version torch was built for, and assembles a CUDA toolkit directory from the pip wheels.
  • Kernel builds are limited to one compile job per ~12 GB of RAM (unlimited builds can exhaust memory).
  • loginctl enable-linger keeps the services running when you're logged out (and starts them at boot).

Files

Path
~/.local/bin/llmhost launcher
~/.local/share/llm-host/ this repo (src/), backend venvs, the assembled CUDA toolkit
~/.config/llm-host/config.json the plan: backend, fitting models, active model, ports
~/.config/llm-host/api_key API key (mode 600)
~/.cache/huggingface/hub/ downloaded models
Linux: ~/.config/systemd/user/llm-host-{model,web}.service services (journalctl --user -u llm-host-model)
macOS: ~/Library/LaunchAgents/dev.llm-host.{model,web}.plist services; logs in ~/Library/Logs/llm-host/

On macOS the services are launchd agents, so they run while you're logged in.

Limitations

  • One model loaded at a time.
  • AMD (ROCm), Intel and CPU-only machines aren't supported yet.
  • The API and dashboard use plain HTTP and are meant for a trusted LAN. Don't expose them to the internet.