feat(model-manager): "Free GPU memory" button to unload ComfyUI models
ComfyUI caches the last model when RAM is plentiful (unified memory), so memory doesn't drop after switching models even though models are being swapped, not accumulated. Add a sidebar "Free GPU memory" button that proxies ComfyUI's POST /free (unload_models + free_memory) via a new /api/comfyui/free endpoint (COMFYUI_URL env). Verified it releases ~7GB. README documents this plus the --disable-smart-memory auto-unload option. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -15,6 +15,7 @@ from pydantic import BaseModel
|
||||
from . import db, downloader, registries
|
||||
from .config import (
|
||||
COMFYUI_PORT,
|
||||
COMFYUI_URL,
|
||||
COMFYUIMINI_PORT,
|
||||
IMAGE_EXTS,
|
||||
KEY_BY_FOLDER,
|
||||
@@ -314,6 +315,20 @@ def ui_config() -> dict:
|
||||
return {"comfyui_port": COMFYUI_PORT, "comfyuimini_port": COMFYUIMINI_PORT}
|
||||
|
||||
|
||||
@app.post("/api/comfyui/free")
|
||||
async def comfyui_free() -> dict:
|
||||
"""Ask ComfyUI to unload all models and free GPU/RAM (proxies POST /free)."""
|
||||
try:
|
||||
async with httpx.AsyncClient(timeout=30) as client:
|
||||
resp = await client.post(
|
||||
f"{COMFYUI_URL}/free",
|
||||
json={"unload_models": True, "free_memory": True})
|
||||
resp.raise_for_status()
|
||||
except Exception as exc: # noqa: BLE001 - report to UI
|
||||
raise HTTPException(502, f"Could not reach ComfyUI: {exc}")
|
||||
return {"ok": True}
|
||||
|
||||
|
||||
@app.get("/start")
|
||||
def start() -> FileResponse:
|
||||
return FileResponse(STATIC_DIR / "start.html")
|
||||
|
||||
Reference in New Issue
Block a user