Repository navigation
VRAM-aware dynamic batch sizing for parakeet - #8535
Conversation
There was a problem hiding this comment.
4 issues found across 5 files
Confidence score: 2/5
backend/tests/unit/test_vram_batch.pyadds 20 important validation scenarios, but they are not wired intotest.sh, so CI will not run them and regressions can slip through unnoticed. Add this test file totest.shbefore merging so the new coverage is actually enforced.- In
backend/parakeet/batch_engine.py(submit()via_get_audio_duration), synchronous_wave.open/_sf.infocalls run on the event loop and can stall concurrent requests under load. Move duration reads torun_in_executor(per AGENTS.md) before merging to avoid request latency and throughput regressions. backend/charts/parakeet/prod_omi_parakeet_values.yamlsetsPARAKEET_VRAM_BYTES_PER_T2to 136.6 whilePARAKEET_TORCH_COMPILEis"true", which mismatches the validated 45.5 coefficient and can overestimate VRAM ~3x. Align the coefficient with torch.compile settings before merging to prevent unnecessary batch throttling/capacity loss.backend/parakeet/batch_engine.pyappears to overcountvram_limited_batchesby treating any undersized batch as VRAM-limited, including normal low-queue conditions. Tighten the increment condition to only true VRAM-constrained paths before merging so operational metrics remain trustworthy.
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="backend/tests/unit/test_vram_batch.py">
<violation number="1" location="backend/tests/unit/test_vram_batch.py:1">
P1: New test file is not registered in test.sh. Per AGENTS.md: "New test files must be added to test.sh or they won't run." The CI test harness won't execute these tests, so all 20 validation scenarios are dead in CI.</violation>
</file>
<file name="backend/charts/parakeet/prod_omi_parakeet_values.yaml">
<violation number="1" location="backend/charts/parakeet/prod_omi_parakeet_values.yaml:117">
P2: PARAKEET_VRAM_BYTES_PER_T2 is set to 136.6 (the non-torch.compile coefficient) but PARAKEET_TORCH_COMPILE is "true". The PR-validated torch.compile coefficient is 45.5. Using 136.6 overestimates per-file VRAM by 3x, capping batches far below safe capacity and unnecessarily reducing throughput.</violation>
</file>
<file name="backend/parakeet/batch_engine.py">
<violation number="1" location="backend/parakeet/batch_engine.py:142">
P1: Blocking I/O in async submit(): _get_audio_duration performs synchronous file reads via _wave.open/_sf.info, freezing the event loop for every request. Must use run_in_executor per AGENTS.md rules.</violation>
<violation number="2" location="backend/parakeet/batch_engine.py:226">
P2: vram_limited_batches metric is inflated: it counts any batch smaller than max_batch_size as VRAM-limited, even when the queue simply has fewer pending requests. Should only increment when _form_vram_safe_batch actually reduced the batch due to VRAM constraints.</violation>
</file>
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
| @@ -0,0 +1,251 @@ | |||
| """Tests for VRAM-aware batch sizing in batch_engine.py.""" | |||
There was a problem hiding this comment.
P1: New test file is not registered in test.sh. Per AGENTS.md: "New test files must be added to test.sh or they won't run." The CI test harness won't execute these tests, so all 20 validation scenarios are dead in CI.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At backend/tests/unit/test_vram_batch.py:
<comment>New test file is not registered in test.sh. Per AGENTS.md: "New test files must be added to test.sh or they won't run." The CI test harness won't execute these tests, so all 20 validation scenarios are dead in CI.</comment>
<file context>
@@ -0,0 +1,251 @@
+"""Tests for VRAM-aware batch sizing in batch_engine.py."""
+
+import asyncio
+import os
+import struct
+import tempfile
+import time
+import unittest
+from unittest.mock import MagicMock, patch
</file context>
|
|
||
| async def submit(self, audio_path: str, timestamps: bool = True, owns_file: bool = False) -> dict: | ||
| enqueued = False | ||
| duration = self._get_audio_duration(audio_path) |
There was a problem hiding this comment.
P1: Blocking I/O in async submit(): _get_audio_duration performs synchronous file reads via _wave.open/_sf.info, freezing the event loop for every request. Must use run_in_executor per AGENTS.md rules.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At backend/parakeet/batch_engine.py, line 142:
<comment>Blocking I/O in async submit(): _get_audio_duration performs synchronous file reads via _wave.open/_sf.info, freezing the event loop for every request. Must use run_in_executor per AGENTS.md rules.</comment>
<file context>
@@ -71,8 +106,40 @@ async def stop(self) -> None:
+
async def submit(self, audio_path: str, timestamps: bool = True, owns_file: bool = False) -> dict:
enqueued = False
+ duration = self._get_audio_duration(audio_path)
try:
async with self._lock:
</file context>
| duration = self._get_audio_duration(audio_path) | |
| duration = await asyncio.get_running_loop().run_in_executor(None, self._get_audio_duration, audio_path) |
| value: "3600" | ||
| - name: PARAKEET_VRAM_SAFETY_FACTOR | ||
| value: "0.8" | ||
| - name: PARAKEET_VRAM_BYTES_PER_T2 |
There was a problem hiding this comment.
P2: PARAKEET_VRAM_BYTES_PER_T2 is set to 136.6 (the non-torch.compile coefficient) but PARAKEET_TORCH_COMPILE is "true". The PR-validated torch.compile coefficient is 45.5. Using 136.6 overestimates per-file VRAM by 3x, capping batches far below safe capacity and unnecessarily reducing throughput.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At backend/charts/parakeet/prod_omi_parakeet_values.yaml, line 117:
<comment>PARAKEET_VRAM_BYTES_PER_T2 is set to 136.6 (the non-torch.compile coefficient) but PARAKEET_TORCH_COMPILE is "true". The PR-validated torch.compile coefficient is 45.5. Using 136.6 overestimates per-file VRAM by 3x, capping batches far below safe capacity and unnecessarily reducing throughput.</comment>
<file context>
@@ -112,6 +112,12 @@ env:
value: "3600"
+ - name: PARAKEET_VRAM_SAFETY_FACTOR
+ value: "0.8"
+ - name: PARAKEET_VRAM_BYTES_PER_T2
+ value: "136.6"
+ - name: PARAKEET_STARVATION_TIMEOUT
</file context>
| batch = self._form_vram_safe_batch(self._pending) | ||
| batch_set = set(id(r) for r in batch) | ||
| self._pending = [r for r in self._pending if id(r) not in batch_set] | ||
| if len(batch) < self._max_batch_size and self._vram_enabled: |
There was a problem hiding this comment.
P2: vram_limited_batches metric is inflated: it counts any batch smaller than max_batch_size as VRAM-limited, even when the queue simply has fewer pending requests. Should only increment when _form_vram_safe_batch actually reduced the batch due to VRAM constraints.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At backend/parakeet/batch_engine.py, line 226:
<comment>vram_limited_batches metric is inflated: it counts any batch smaller than max_batch_size as VRAM-limited, even when the queue simply has fewer pending requests. Should only increment when _form_vram_safe_batch actually reduced the batch due to VRAM constraints.</comment>
<file context>
@@ -108,12 +176,55 @@ async def _flush_loop(self) -> None:
+ batch = self._form_vram_safe_batch(self._pending)
+ batch_set = set(id(r) for r in batch)
+ self._pending = [r for r in self._pending if id(r) not in batch_set]
+ if len(batch) < self._max_batch_size and self._vram_enabled:
+ self._metrics["vram_limited_batches"] += 1
</file context>
Git-on-my-level
left a comment
There was a problem hiding this comment.
Solid work on the VRAM formula and batch formation algorithm — the prod OOM scenario (12x250s) is correctly capped to 9, and the starvation guard is well-designed. I verified all 22 tests pass and ran 10K random fuzz trials with zero budget violations.
A few things to address before merge:
1. Startup timing race (blocking): batch_engine.start() reads gpu_worker.vram_info immediately after gpu_worker.start(), but the model loads asynchronously in a background thread (~30-60s). At that point _vram_total_mb=0.0, so _vram_enabled is set to False and never re-checked — VRAM-aware batching will be permanently disabled in fresh container starts. Consider reading VRAM info lazily in _estimate_max_batch() / _form_vram_safe_batch(), or after wait_ready().
2. Sync I/O in async path: _get_audio_duration() does synchronous _wave.open / _sf.info calls inside the async submit() method, which blocks the event loop. Per AGENTS.md async rules, this should use run_in_executor.
3. Tests not in CI: test_vram_batch.py is not listed in test.sh — AGENTS.md requires new test files to be added there or they will not run in CI.
4. Metric accuracy: vram_limited_batches increments on any batch smaller than max_batch_size when VRAM is enabled, including normal low-queue conditions. Consider only counting when the batch was actually reduced by VRAM constraints.
Minor: the duration_known parameter in _estimate_max_batch() is accepted but never used in the computation.
Note: cubic flagged the VRAM coefficient (136.6 vs 45.5 for torch.compile) — but that is correct here since prod uses PARAKEET_ATTENTION_MODE=auto, which skips torch.compile.
Tagging @beastoin for the changes above.
E2E OOM Reproduction Test AddedCommit RED without fix (
|
| Test | What it proves |
|---|---|
test_without_fix_all_oom |
Uncapped batch of 12 → OOM (the bug) |
test_with_fix_all_succeed |
VRAM cap splits into safe batches → all pass (the fix) |
test_batch_size_matches_formula |
Formula caps 290s to B<12 on L4 |
test_uncapped_exceeds_l4_vram |
12×1711 MiB exceeds L4 capacity (proves fix is needed) |
test_oom_error_signature_matches_prod |
Error string matches prod format |
All 25 tests pass (20 existing + 5 new).
There was a problem hiding this comment.
1 issue found across 1 file (changes from recent commits).
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="backend/tests/unit/test_oom_reproduction.py">
<violation number="1" location="backend/tests/unit/test_oom_reproduction.py:17">
P1: New test file `test_oom_reproduction.py` is not registered in `backend/test.sh`. CI runs from test.sh so this test will never execute in automated pipelines.</violation>
</file>
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
| import unittest | ||
| from unittest.mock import MagicMock, patch | ||
|
|
||
| from batch_engine import BatchEngine |
There was a problem hiding this comment.
P1: New test file test_oom_reproduction.py is not registered in backend/test.sh. CI runs from test.sh so this test will never execute in automated pipelines.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At backend/tests/unit/test_oom_reproduction.py, line 17:
<comment>New test file `test_oom_reproduction.py` is not registered in `backend/test.sh`. CI runs from test.sh so this test will never execute in automated pipelines.</comment>
<file context>
@@ -0,0 +1,228 @@
+import unittest
+from unittest.mock import MagicMock, patch
+
+from batch_engine import BatchEngine
+
+L4_TOTAL_MB = 22563
</file context>
Git-on-my-level
left a comment
There was a problem hiding this comment.
Thanks for chasing the Parakeet OOM issue — the VRAM-budgeted batching approach and the reproduction tests are pointed in the right direction.
I think this still needs changes before merge because the new limiter appears to be disabled in the real server lifecycle:
main.pystartsgpu_worker.start()and immediately callsawait batch_engine.start().BatchEngine.start()snapshotsself._gpu_worker.vram_infoonce.GPUWorker.vram_infostays attotal_mb=0/baseline_mb=0until_load_model()completes inside the background GPU worker thread.- That means production startup will log
VRAM-aware batching disabled (safety_factor=0 or no VRAM info)and_estimate_max_batch(290s)falls back to the static max batch size (32) even after the model later becomes ready.
I locally reproduced the lifecycle shape with a delayed vram_info: after BatchEngine.start() the limiter remained enabled=False, and after simulating the model becoming ready the estimate for 290s files was still 32, not the intended ~7. The current unit tests miss this because their mock GPU worker exposes populated VRAM info before engine.start().
Suggested fix: initialize/recompute the VRAM budget after the GPU worker is ready/model-loaded, or have BatchEngine lazily refresh from gpu_worker.vram_info before forming batches when the initial snapshot had no VRAM data. Please add a regression test that starts the engine with zero VRAM info, updates the GPU worker to realistic L4 values later, and verifies long-file batches become capped.
I did not formally approve because the PR already carries needs-maintainer-review and needs-tests, and this startup-order issue looks blocking for the production fix.
|
@beastoin The VRAM cap is initialized too early: Please defer the batch-engine VRAM initialization until the worker is ready, refresh the VRAM budget lazily once by AI for @beastoin |
|
Fixed the startup-order race in c500b7f: extracted Added regression test by AI for @beastoin |
|
@beastoin by AI for @beastoin |
|
Fixed in 03389de: guarded Also added All parakeet tests pass individually (59 gpu_worker + 48 batch_engine + 25 vram_batch + 5 oom_reproduction + 89 endpoints). by AI for @beastoin |
|
@beastoin The VRAM cap is still per-batch while prod now sets Please either make VRAM-aware mode serialize GPU batches, divide/reserve the VRAM budget across inflight work, or add active VRAM accounting before launching another flush; add a regression test where the first capped batch is still running when the second flush starts. by AI for @beastoin |
|
Fixed in 1d338c1: VRAM budget is now divided by With
Added by AI for @beastoin |
|
@beastoin The current head still needs one test fix: by AI for @beastoin |
|
@beastoin No issues found in the current head. I rechecked the prior startup-order, CPU/mock by AI for @beastoin |
There was a problem hiding this comment.
2 issues found across 10 files (changes from recent commits).
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="backend/tests/unit/test_vram_batch.py">
<violation number="1" location="backend/tests/unit/test_vram_batch.py:1">
P1: New test file is not registered in test.sh. Per AGENTS.md: "New test files must be added to test.sh or they won't run." The CI test harness won't execute these tests, so all 20 validation scenarios are dead in CI.</violation>
</file>
<file name="backend/charts/parakeet/prod_omi_parakeet_values.yaml">
<violation number="1" location="backend/charts/parakeet/prod_omi_parakeet_values.yaml:117">
P2: PARAKEET_VRAM_BYTES_PER_T2 is set to 136.6 (the non-torch.compile coefficient) but PARAKEET_TORCH_COMPILE is "true". The PR-validated torch.compile coefficient is 45.5. Using 136.6 overestimates per-file VRAM by 3x, capping batches far below safe capacity and unnecessarily reducing throughput.</violation>
</file>
<file name="backend/parakeet/batch_engine.py">
<violation number="1" location="backend/parakeet/batch_engine.py:142">
P1: Blocking I/O in async submit(): _get_audio_duration performs synchronous file reads via _wave.open/_sf.info, freezing the event loop for every request. Must use run_in_executor per AGENTS.md rules.</violation>
<violation number="2" location="backend/parakeet/batch_engine.py:226">
P2: vram_limited_batches metric is inflated: it counts any batch smaller than max_batch_size as VRAM-limited, even when the queue simply has fewer pending requests. Should only increment when _form_vram_safe_batch actually reduced the batch due to VRAM constraints.</violation>
</file>
<file name="backend/tests/unit/test_oom_reproduction.py">
<violation number="1" location="backend/tests/unit/test_oom_reproduction.py:17">
P1: New test file `test_oom_reproduction.py` is not registered in `backend/test.sh`. CI runs from test.sh so this test will never execute in automated pipelines.</violation>
</file>
<file name="backend/parakeet/main.py">
<violation number="1" location="backend/parakeet/main.py:144">
P1: `PARAKEET_MAX_INFLIGHT` is parsed without any lower-bound validation before being passed to `BatchEngine`, where it is used directly as the initial value for `asyncio.Semaphore`. A negative value causes a `ValueError` at startup, and a value of 0 permanently blocks all flush tasks because the semaphore has no permits.</violation>
</file>
Tip: Review your code locally with the cubic CLI to iterate faster.
Re-trigger cubic
| vram_safety_factor=float(os.getenv("PARAKEET_VRAM_SAFETY_FACTOR", "0.8")), | ||
| vram_bytes_per_t2=float(os.getenv("PARAKEET_VRAM_BYTES_PER_T2", "136.6")), | ||
| starvation_timeout_sec=float(os.getenv("PARAKEET_STARVATION_TIMEOUT", "5.0")), | ||
| max_inflight=int(os.getenv("PARAKEET_MAX_INFLIGHT", "2")), |
There was a problem hiding this comment.
P1: PARAKEET_MAX_INFLIGHT is parsed without any lower-bound validation before being passed to BatchEngine, where it is used directly as the initial value for asyncio.Semaphore. A negative value causes a ValueError at startup, and a value of 0 permanently blocks all flush tasks because the semaphore has no permits.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At backend/parakeet/main.py, line 144:
<comment>`PARAKEET_MAX_INFLIGHT` is parsed without any lower-bound validation before being passed to `BatchEngine`, where it is used directly as the initial value for `asyncio.Semaphore`. A negative value causes a `ValueError` at startup, and a value of 0 permanently blocks all flush tasks because the semaphore has no permits.</comment>
<file context>
@@ -141,6 +141,7 @@ async def lifespan(app: FastAPI):
vram_safety_factor=float(os.getenv("PARAKEET_VRAM_SAFETY_FACTOR", "0.8")),
vram_bytes_per_t2=float(os.getenv("PARAKEET_VRAM_BYTES_PER_T2", "136.6")),
starvation_timeout_sec=float(os.getenv("PARAKEET_STARVATION_TIMEOUT", "5.0")),
+ max_inflight=int(os.getenv("PARAKEET_MAX_INFLIGHT", "2")),
)
await batch_engine.start()
</file context>
| max_inflight=int(os.getenv("PARAKEET_MAX_INFLIGHT", "2")), | |
| max_inflight=max(1, int(os.getenv("PARAKEET_MAX_INFLIGHT", "2"))), |
|
Thanks @beastoin — solid work here. I did a full static + test review in a worktree; here is what I verified. What this does well
Test coverage
Notes for a human maintainer
No security/data-handling/auth surfaces touched; no new dependencies, network, or secret handling. No agent-instruction/behavior docs affected. |
|
lgtm |
Replace static max_batch_size slice with VRAM-budget-based batch formation. Probes audio duration at submit time and uses the formula max_safe_B = available_vram / (coeff × T²) to cap batch size per the longest file's attention matrix cost. Includes starvation guard for requests queued >5s. Short files (30s) still batch at 32; long files (250s) cap to 9, preventing the exact OOM observed in prod (12 files at ~250s exhausted 93% VRAM). Co-Authored-By: zen <[email protected]> Co-Authored-By: Claude Opus 4.6 <[email protected]>
Store VRAM baseline and total as instance fields (previously local vars in _load_model) and add a vram_info property returning total_mb, baseline_mb, attention_mode, and auto_threshold_sec. Used by BatchEngine to compute VRAM-aware batch size limits. Co-Authored-By: zen <[email protected]> Co-Authored-By: Claude Opus 4.6 <[email protected]>
Add PARAKEET_VRAM_SAFETY_FACTOR (0.8), PARAKEET_VRAM_BYTES_PER_T2 (136.6 for uncompiled attention), and PARAKEET_STARVATION_TIMEOUT (5.0s) to BatchEngine constructor. Set safety_factor=0 to disable and fall back to static PARAKEET_MAX_BATCH_SIZE. Co-Authored-By: zen <[email protected]> Co-Authored-By: Claude Opus 4.6 <[email protected]>
PARAKEET_VRAM_SAFETY_FACTOR=0.8, PARAKEET_VRAM_BYTES_PER_T2=136.6, PARAKEET_STARVATION_TIMEOUT=5.0. These enable the dynamic batch sizing that adapts to file duration instead of a static cap. Co-Authored-By: Claude Opus 4.6 <[email protected]>
Tests cover: VRAM formula estimation, batch formation with mixed durations, starvation guard priority, unknown duration handling, WAV duration probing, disabled mode fallback, and prod OOM scenario validation (confirms B=12 at 250s would be prevented). Co-Authored-By: zen <[email protected]> Co-Authored-By: Claude Opus 4.6 <[email protected]>
Reproduces exact prod OOM: 12 x 290s files on L4 in auto mode. Mock GPU worker OOMs when batch VRAM exceeds physical capacity. - test_without_fix_all_oom: safety_factor=0, single batch of 12 -> CUDA OOM - test_with_fix_all_succeed: safety_factor=0.8, split into safe batches -> all pass - test_batch_size_matches_formula: verifies 290s cap < 12 on L4 - test_uncapped_exceeds_l4_vram: proves 12 x 1711 MB > available 16854 MB - test_oom_error_signature_matches_prod: validates error string format Co-Authored-By: Claude Opus 4.6 <[email protected]>
Switch from memory_allocated() (PyTorch-managed only) to mem_get_info() (captures all GPU allocations including CUDA context, cuDNN workspace, etc.) for more accurate VRAM budget. Accept durations list from batch engine payload to skip redundant file I/O for duration probing in auto attention mode. Co-Authored-By: Claude Opus 4.6 <[email protected]>
Concurrent flushing: inflight semaphore (max_inflight=2) allows batch N+1 to form while GPU processes batch N. _guarded_flush() with _flush_pending flag prevents duplicate flush task accumulation. stop() cancels and awaits inflight tasks before draining semaphore. Attention-mode-aware estimation: local mode skips quadratic VRAM cap (linear scaling). Auto mode with known long duration >= threshold also skips cap (will switch to local attention). Unknown durations conservatively apply the cap. Duration passthrough: sends durations list in GPU worker payload. Adopted from beastoin/NeMo PR #11 (zen). Co-Authored-By: Claude Opus 4.6 <[email protected]>
Default: 2 concurrent inflight batches on GPU. Co-Authored-By: Claude Opus 4.6 <[email protected]>
Tests for NeMo PR #11 adoption: - TestConcurrentFlush: inflight semaphore bounds, stop drains, flush loop fires without blocking - TestFlushGuard: no duplicate flush tasks - TestDurationPassthrough: payload includes durations - Attention mode tests: local skips limit, auto long file skips, auto short applies, unknown duration conservatively capped - Fix vram_info in existing test mocks for new start() flow Co-Authored-By: Claude Opus 4.6 <[email protected]>
BatchEngine.start() is called immediately after gpu_worker.start(), but the GPU model loads in a background thread — vram_info has total_mb=0 at that point. Extract _try_init_vram() and call it lazily from _flush_batch() so VRAM budget is picked up once the worker finishes loading. Addresses reviewer feedback from CODEx review on PR #8535. Co-Authored-By: Claude Opus 4.6 <[email protected]>
Guard torch.cuda.mem_get_info() behind is_available() check so GPU worker tests pass in CPU/mock mode. Add mem_get_info mock return value to gpu_worker and endpoint test fixtures. Register test_vram_batch.py and test_oom_reproduction.py in test.sh so they run in CI. Co-Authored-By: Claude Opus 4.6 <[email protected]>
With max_inflight=2, two batches each sized for the full VRAM budget can run concurrently and exceed available memory. Divide the budget by max_inflight so each concurrent batch only uses its share. Example (L4 22GB, baseline 5709 MiB, safety 0.8): - Total budget: 12718 MB - Per-batch with inflight=2: 6359 MB - 250s files: max 5 per batch (safe for 2 concurrent) Addresses CODEx reviewer feedback on PR #8535 round 2. Co-Authored-By: Claude Opus 4.6 <[email protected]>
Add sys.path setup and torch/nemo mocks to test_oom_reproduction.py (same pattern as other parakeet test files). Update budget assertion to use engine._vram_available_mb (per-batch) instead of total budget. Co-Authored-By: Claude Opus 4.6 <[email protected]>
…ght=2 Tests addressing tester feedback: - TestMemGetInfoGuard: assert mem_get_info NOT called when CUDA unavailable, IS called when available - TestDurationPassthroughInGPUWorker: verify batcher durations skip file probe, fallback probes files when no durations - TestMaxInflight2: prove two batches run concurrently with max_inflight=2 using async gate pattern Co-Authored-By: Claude Opus 4.6 <[email protected]>
9647a57 to
f32fa3a
Compare
The early `self._flush_pending = False` inside `_flush_batch()` (added in PR #8535) allowed the 2ms flush timer to fire between individual request arrivals, producing batch=1 flushes instead of accumulating requests during GPU processing. Production data showed 72.8% batch=1 (avg 1.6 files/batch) causing LB 504 timeouts. Fix: remove the early reset so `_flush_pending` only resets in `_guarded_flush()`'s `finally` block, keeping the gate held during the entire GPU inference cycle. Requests accumulate while GPU is busy. Adds regression test simulating staggered arrivals with GPU latency. Updates TestMaxInflight2 to verify accumulation behavior. Closes #8664 Co-Authored-By: Claude Opus 4.6 <[email protected]>
Summary
max_batch_sizeslice with VRAM-budget-based dynamic batch formationmax_safe_B = available_vram / (coeff × T²)to cap batch size based on longest file's attention matrix costvram_infoproperty to GPUWorker exposing VRAM baseline/total for budget calculationPARAKEET_VRAM_SAFETY_FACTOR,PARAKEET_VRAM_BYTES_PER_T2,PARAKEET_STARVATION_TIMEOUT,PARAKEET_MAX_INFLIGHTNeMo PR #11 adoption
Adopts beastoin/NeMo#11 (by zen) into omi parakeet server:
_inflight_sem = asyncio.Semaphore(max_inflight)allows batch N+1 to form while GPU processes batch N._guarded_flush()with_flush_pendingflag prevents duplicate flush task accumulation.torch.cuda.mem_get_info()captures ALL GPU allocations (CUDA context, cuDNN workspace) vsmemory_allocated()which only tracks PyTorch-managed tensors. Guarded for CPU/mock environments.durationslist in GPU worker payload to avoid redundant file I/O for duration probing._try_init_vram()defers VRAM budget setup until GPU worker finishes model loading (fixes startup-order race where BatchEngine.start() runs before model load completes).max_inflightso concurrent batches each use only their share, preventing combined OOM.Review cycle fixes
mem_get_infofor CPU/mock environments (reviewer round 2)max_inflightto prevent concurrent OOM (reviewer round 3)test.shfor CI coverageContext
Follow-up to PR #8486 post-deploy OOM. A burst of 12 files at ~250s each (120-300s danger zone — long enough for massive O(T²) softmax but just under the 300s auto-attention threshold) exhausted 93% VRAM on the L4. Static cap (#8533) doesn't solve the fundamental issue: B=8 with 280s files still hits ~18 GiB.
VRAM formula (validated empirically by zen on L4):
Dynamic behavior (L4 22GB, 5709 MiB baseline, per-batch with inflight=2):
Set
PARAKEET_VRAM_SAFETY_FACTOR=0to disable and fall back to staticPARAKEET_MAX_BATCH_SIZE.Supersedes #8533 (static cap=8 hotfix).
Test plan
Risks / edge cases
max_inflight=2allows GPU overlap — each batch gets half the VRAM budget.mem_get_info()may include fragmented free memory as available — safety factor (0.8) provides margin.by AI for @beastoin