Fix GPU OOM: share one Whisper model across calls (was leaking per call)

Calls were dropping right after answer with "CUDA failed with error out of
memory". Cause: each call constructed a new HintedWhisperSTTService -> new
ctranslate2 WhisperModel on the GPU, and that VRAM was never released when the
call ended. Over ~13 calls the python process grew to 9.7GB; with the pinned LLM
(6GB) the 16GB GPU filled (14 MiB free) and Whisper load failed on every call.

Fix: cache one WhisperModel per (model,device,compute) in _WHISPER_MODEL_CACHE
and reuse it across all calls; bake the fixed hotwords into the shared model's
transcribe() once (drops the racy per-call monkey-patch). VRAM now constant
(~6GB LLM + ~1.5GB Whisper). Verified: two instances share one model object;
GPU back to 6.0/16GB used after restart. Documented the VRAM budget.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
tocmo0nlord
2026-06-27 22:07:59 +00:00
parent ab15023651
commit a521dc168e
2 changed files with 39 additions and 19 deletions

View File

@@ -396,6 +396,16 @@ a ~3s load. Fix: `server.py` has a `lifespan` handler that warms + pins the mode
later turns are 8B generation variance. Switching Whisper size would NOT help — it's not the
bottleneck (STT model `medium` is for accuracy, not latency).
### VRAM budget — shared Whisper model (fixes OOM)
GPU is 16GB. Budget: pinned LLM ~6GB (num_ctx 8192) + **one shared** Whisper `medium` ~1.5GB +
overhead ≈ 8GB, leaving headroom. Critical: Whisper is loaded **once per process and reused
across calls** (`_WHISPER_MODEL_CACHE` in `bot.py`). Loading a new `WhisperModel` per call leaks
VRAM — ctranslate2 doesn't release it when the call ends, so models accumulated and the GPU OOM'd
after ~68 calls (`CUDA failed with error out of memory`, every call dropping right after answer).
Symptom to watch: `nvidia-smi` shows the python process growing call-over-call. Don't reintroduce
per-call model loads.
### Why Q4_K_M not Q8_0
Q8_0 consumed ~8.5GB VRAM for weights alone. Under telephony load this caused