Uninstall: offer to delete downloaded models, with a command that works
The old hint pointed at `hf`, which lived in the venv uninstall had just deleted. Uninstall now lists llm-host's catalog models in the cache with their sizes and asks (default no); --models deletes without asking. It runs `uv tool run --from huggingface_hub hf cache rm`, which also frees blobs in the shared hub/blobs directory, and prints that exact command when models are kept. Models outside the catalog are never touched. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QaE1hpvyZTJixEbUUMj9Ca
This commit is contained in:
parent
458b0cfc32
commit
22e3019725
2 changed files with 41 additions and 3 deletions
|
|
@ -52,7 +52,7 @@ PYTHONPATH=. python3 -P -m llmhost plan --simulate apple:64 # a 64 GB Mac
|
|||
| `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]` | remove services and backends (downloaded models are kept) |
|
||||
| `llmhost uninstall [--purge] [--models]` | remove services and backends; asks before deleting downloaded models (`--models` deletes without asking) |
|
||||
|
||||
The dashboard (`http://<host>.local:8080`) 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.
|
||||
|
|
|
|||
|
|
@ -399,7 +399,24 @@ def cmd_update(a):
|
|||
os.execv(args[0], args)
|
||||
|
||||
|
||||
def cached_catalog_models():
|
||||
"""(repo, GiB) for every catalog build present in the HF cache. Only llm-host's own
|
||||
models are considered; anything else in the cache is never touched."""
|
||||
repos = {v["repo"] for m in paths.load_catalog()["models"] for v in m["variants"].values()}
|
||||
return sorted((r, hfcache.disk_gib(r)) for r in repos if hfcache.repo_dir(r).exists())
|
||||
|
||||
|
||||
def hf_cache_rm_cmd(repos):
|
||||
# hf lives in the backend venv, which uninstall deletes; uv (installed by install.sh) stays.
|
||||
# `uv tool run` rather than uvx: some uv installs don't ship the uvx shim.
|
||||
uv = shutil.which("uv") or str(paths.BIN_DIR / "uv")
|
||||
return [uv, "tool", "run", "--from", "huggingface_hub", "hf", "cache", "rm",
|
||||
"--cache-dir", str(paths.hf_hub_dir()), *[f"model/{r}" for r in repos]]
|
||||
|
||||
|
||||
def cmd_uninstall(a):
|
||||
# Read the catalog now: --purge deletes it along with the rest of llm-host.
|
||||
cached = cached_catalog_models()
|
||||
for name in service.NAMES:
|
||||
service.uninstall(name)
|
||||
for d in ("venv-vllm", "venv-mlx", "cuda", "nvcc-test"):
|
||||
|
|
@ -410,7 +427,27 @@ def cmd_uninstall(a):
|
|||
shutil.rmtree(paths.DATA, ignore_errors=True)
|
||||
paths.SHIM.unlink(missing_ok=True)
|
||||
say("Removed config, API key and llm-host itself.")
|
||||
say(f"Downloaded models were kept in {paths.hf_hub_dir()} (delete with `hf cache rm`).")
|
||||
if not cached:
|
||||
return
|
||||
total = sum(g for _, g in cached)
|
||||
delete = a.models
|
||||
if not delete and sys.stdin.isatty():
|
||||
say(f"\nDownloaded models ({total:.1f} GiB):")
|
||||
for repo, gib in cached:
|
||||
say(f" {repo} {gib:.1f} GiB")
|
||||
delete = input("Delete them too? [y/N] ").strip().lower() in ("y", "yes")
|
||||
cmd = hf_cache_rm_cmd([r for r, _ in cached])
|
||||
if delete:
|
||||
# hf cache rm also frees blobs kept in the shared hub/blobs directory.
|
||||
try:
|
||||
ok = subprocess.run(cmd + ["--yes"]).returncode == 0
|
||||
except OSError:
|
||||
ok = False
|
||||
say(f"Deleted {len(cached)} model(s), {total:.1f} GiB." if ok else
|
||||
"Deleting models failed. Remove them with:\n " + " ".join(cmd).replace(str(paths.HOME), "~"))
|
||||
else:
|
||||
say(f"\nKept {len(cached)} downloaded model(s) ({total:.1f} GiB). To delete them later:\n "
|
||||
+ " ".join(cmd).replace(str(paths.HOME), "~"))
|
||||
|
||||
|
||||
def cmd_run_model(a):
|
||||
|
|
@ -486,8 +523,9 @@ def main(argv=None):
|
|||
s = sub.add_parser("update", help="pull the latest llm-host and re-plan")
|
||||
s.add_argument("--backend", action="store_true", help="also reinstall/upgrade the backend")
|
||||
s.set_defaults(fn=cmd_update)
|
||||
s = sub.add_parser("uninstall", help="remove services and backends (keeps downloaded models)")
|
||||
s = sub.add_parser("uninstall", help="remove services and backends (asks before deleting models)")
|
||||
s.add_argument("--purge", action="store_true", help="also remove config, API key and llm-host itself")
|
||||
s.add_argument("--models", action="store_true", help="also delete downloaded models without asking")
|
||||
s.set_defaults(fn=cmd_uninstall)
|
||||
sub.add_parser("run-model").set_defaults(fn=cmd_run_model)
|
||||
sub.add_parser("run-web").set_defaults(fn=cmd_run_web)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue