Measuring Real 8 GB VRAM Co-Residency Instead of Guessing#
Running a full conversational voice pipeline (faster-whisper -> Ollama -> Kokoro/Piper + Silero VAD) concurrently on a single 8 GB RTX 3070 looks straightforward on paper until real hardware measurements expose where the memory and milliseconds go.
In Phase 1 of SpeakOn, we built clean Python Protocol interfaces behind app/stt/, app/llm/, app/tts/, and app/vad/, cached open-source weights locally, and built an automated NVML + end-to-end latency benchmark (scripts/bench_turn.py) that forced several concrete architectural improvements.
Architecture: Pluggable Protocols, Shared GPU Weights, and CPU Offload#
Every AI stage sits behind a strict interface in app/*/base.py, paired with deterministic in-memory fakes in tests/fakes.py so GitHub Actions executes unit and contract tests without a GPU:
- STT (
app/stt/faster_whisper.py): Decodes arbitrary browser/mobile audio (WAV,WebM,Opus,M4A) to 16 kHz mono float32 in memory via PyAV (av)—removing any externalffmpegbinary dependency—and runsfaster-whisper-small(int8_float16) with word-level timestamps and confidence probabilities. - LLM (
app/llm/): Talks to hostollama serveviahttpx.AsyncClient(trust_env=False)with JSON-schema enforcement (TutorReply), delimiter-isolated user utterances (<user_utterance>), one automated JSON-repair pass, and deterministicpypinyintone-mark validation on every Mandarin turn. - Multilingual TTS Router (
app/tts/): Shares a singleKokoro-82MKModelinstance across six languageKPipelineinstances (en,es,zh,fr,it,pt) to avoid duplicating ~0.3 GB of weights per language, chunks CJK (。!?) and Latin punctuation without splitting short exclamations, caches synthesized WAV files atomically on disk by SHA-256, and falls back to CPU Piper (deprimary and zero-VRAM fallback). - Streaming VAD (
app/vad/silero.py): RunsSilero VAD(VADIterator,16 kHz,600 mssilence threshold) single-threaded on CPU (0additional GPU VRAM).
What the RTX 3070 Benchmark Actually Measured#
Initial benchmarks uncovered three empirical realities on an active Linux workstation (~0.86–1.21 GB desktop VRAM baseline and OLLAMA_MODELS stored on a SATA HDD):
- Cold HDD Loading vs. Steady-State Turns: Loading multi-gigabyte GGUF blobs from an HDD took ~50–90 seconds on the first turn (tripping a 45 s timeout), whereas
keep_alive=30mkept warm turns fast. RaisingSPEAKON_LLM_TIMEOUT_SECto120.0prevents cold-start timeouts. qwen3.5-fast:9bvs.llama3.1:latestCo-Residency: Co-resident alongsidefaster-whisper-smallandKokoro,qwen3.5-fast:9b(6.2 GB) spilled35%of its layers to CPU RAM, pushing total turn latency to6.68 s(7.27 GBtotal VRAM). By contrast,llama3.1:latest(4.9 GB,num_ctx=4096,num_predict=180) stayed88%on GPU and delivered1,212.7 mstotal uncached turn latency (stt: 142.3 ms,llm: 988.1 ms,tts: 82.3 ms) at5.882 GBSpeakOn VRAM delta (7.088 GBpeak). SpeakOn defaults real-time voice turns tollama3.1:latestwhile exposingqwen3.5:9bandqwen3.5-fast:9bfor Mandarin & deep Studio coaching.- MIT Piper
2023.11.14-2Phoneme Guardrail: To keep the Apache-2.0 repository free of GPL-3.0piper-tts >= 1.3, we pinned the archived MIT standalonepiperbinary (2023.11.14-2, SHA-256 verified) and discovered it aborts (Phonemes must be one codepoint) on newer diphthong ONNX configs (['aɪ', 'aʊ', ...]). Selecting single-codepoint MIT voices fromrhasspy/piper-voicesenabled reliable CPU synthesis across all seven languages.
Security & Reliability Hardening#
- Prompt-Injection Delimiters & Schema Repair: Untrusted learner transcripts are sanitized and wrapped inside
<user_utterance>delimiters, validated againstTutorReplyJSON Schema, and protected by 5-failure / 30 s circuit breakers (app/core/resilience.py), per-stage timeouts (30 sSTT,120 sLLM,20 sTTS), andtenacityretries. - Zero-Leak CUDA & Model Hygiene:
app/core/cuda.pyresolvesnvidia.cublas/nvidia.cudnnwheel shared libraries dynamically viaLD_LIBRARY_PATHandRTLD_GLOBAL, keeping model weights in git-ignoredSPEAKON_HF_HOMEand audio caches under git-ignoreddata/. - Verification:
18/18CPU unit tests (ruff,mypy --strict, OpenAPI drift check) and9/9GPU regression & 7-language synthetic-TTS round-trip STT tests (en,es,zh,pt,de,it,fr, plusSilero VAD) passed on the RTX 3070.
