From fdad2a46fa86df1b534c5bb5acc1045564af8c9f Mon Sep 17 00:00:00 2001 From: victorcavero14 Date: Wed, 23 Sep 2026 00:55:08 +0200 Subject: [PATCH] perf(asr): Parakeet peak VRAM 6.1 -> 4.6 GB with the same transcripts Benchmarked in the prod container on 10 real user videos (40 min of audio, EN/ES/PT/FR-AR, 4,850 words) before changing anything: config peak VRAM ASR time words != prod ts drift prod (batch 8) 6.1 GB 32 s - - batch 4 + lean arena 4.6 GB 38 s 1 (*) 0.1 ms batch 2 + lean arena 4.1 GB 40 s dropped a sentence int8 3.9 GB 350 s 11.7 % 168 ms (*) outside the mixed-language clip, which goes to whisper in prod anyway. Ship batch 4 with the arena growing only by what is requested and no max cuDNN workspace (those two alone change nothing in the output). Co-Authored-By: Claude Opus 5.5 --- CLAUDE.md | 7 +++++++ tests/test_transcribe_backends.py | 13 +++++++++++++ transcribe_backends.py | 31 ++++++++++++++++++++++++++----- 3 files changed, 46 insertions(+), 5 deletions(-) diff --git a/CLAUDE.md b/CLAUDE.md index 05bf78a..57053d1 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -488,6 +488,13 @@ per hour at peak with `MAX_CONCURRENT_JOBS=8`): (`main.transcribe_video` → `release_models()`). Before, a job kept Parakeet's onnxruntime CUDA arena (~4-6 GB) for its whole render; TransNetV2 also `empty_cache()`s after each pass. +- **Parakeet runs lean** (`transcribe_backends.parakeet_providers`, + `PARAKEET_VAD_BATCH`=4): 4 VAD segments per encoder batch instead of 8, CUDA + arena `kSameAsRequested`, no max cuDNN workspace. Peak per transcription + 6.1 → 4.6 GB with the same words (benchmark 22-sep-2026: 10 real videos, + 4,850 words, 1 word changed outside a clip that goes to whisper anyway). + Batch 2 dropped a sentence and int8 was 11x slower with 11.7% of words + different: both rejected. - **Host-wide transcription slots** (`transcribe_backends.host_asr_slot`, `ASR_HOST_SLOTS`, default 2): flock files `output/.asr-gpu-N.lock`, shared by every job process and by both containers of a deploy. diff --git a/tests/test_transcribe_backends.py b/tests/test_transcribe_backends.py index 7ae25b5..48ad1ee 100644 --- a/tests/test_transcribe_backends.py +++ b/tests/test_transcribe_backends.py @@ -333,3 +333,16 @@ class TestHostAsrSlot: import transcribe_backends as tb with tb.host_asr_slot(slots=0, lock_dir=str(tmp_path)) as s: assert s._fh is None + + +class TestParakeetMemorySettings: + def test_vad_batch_default_is_the_benchmarked_one(self): + import transcribe_backends as tb + assert tb.PARAKEET_VAD_BATCH == 4 + + def test_cuda_provider_is_lean_with_cpu_fallback(self): + import transcribe_backends as tb + (name, opts), cpu = tb.parakeet_providers() + assert name == "CUDAExecutionProvider" and cpu == "CPUExecutionProvider" + assert opts["arena_extend_strategy"] == "kSameAsRequested" + assert opts["cudnn_conv_use_max_workspace"] == "0" diff --git a/transcribe_backends.py b/transcribe_backends.py index ce3dec3..7e21785 100644 --- a/transcribe_backends.py +++ b/transcribe_backends.py @@ -256,17 +256,38 @@ _parakeet_model = None _parakeet_lock = threading.Lock() +# How many VAD segments (up to 20 s each) the encoder takes per batch. The +# library default is 8; 4 cuts the peak VRAM of a transcription from ~6.1 to +# ~4.6 GB for the same words. Benchmarked in prod on 22-sep-2026 over 10 real +# user videos (40 min of audio, EN/ES/PT/FR-AR, 4,850 words): batch 4 changed +# 1 word outside the mixed-language clip (which goes to whisper in prod anyway), +# 0.1 ms mean timestamp drift, +3 s per 20-min video. Batch 2 saved another +# 0.5 GB but dropped a whole sentence; int8 was 11x slower on this GPU with +# 11.7% of words different. Don't go below 4 without re-running that check. +PARAKEET_VAD_BATCH = int(os.environ.get("PARAKEET_VAD_BATCH", "4")) + + +def parakeet_providers(): + """onnxruntime providers for Parakeet. The arena grows only by what is + asked and cuDNN gets no oversized workspace: same numerics (identical + transcripts in the benchmark), less memory held.""" + cuda_opts = { + "arena_extend_strategy": "kSameAsRequested", + "cudnn_conv_use_max_workspace": "0", + "cudnn_conv_algo_search": "HEURISTIC", + } + return [("CUDAExecutionProvider", cuda_opts), "CPUExecutionProvider"] + + def _get_parakeet_model(): global _parakeet_model with _parakeet_lock: if _parakeet_model is None: import onnx_asr - model = onnx_asr.load_model( - PARAKEET_MODEL_ID, - providers=["CUDAExecutionProvider", "CPUExecutionProvider"], - ) + model = onnx_asr.load_model(PARAKEET_MODEL_ID, providers=parakeet_providers()) vad = onnx_asr.load_vad("silero") - _parakeet_model = model.with_vad(vad).with_timestamps() + _parakeet_model = model.with_vad( + vad, batch_size=PARAKEET_VAD_BATCH).with_timestamps() return _parakeet_model