Repository navigation
Description
Problem
The BatchEngine groups concurrent HTTP requests into a single model.transcribe() call with B>1 (up to max_batch_size=32). VRAM for attention scales linearly with batch size: VRAM = baseline + 136.6 * B * T_max^2 bytes, where T_max is the longest file in the batch.
This causes OOM on L4 (24GB) when multiple long files arrive within the 100ms flush window:
| Batch Size | File Duration | Peak VRAM | Status |
|---|---|---|---|
| B=1 | 5min | 6.7 GB | Safe |
| B=4 | 5min | 12.2 GB | Safe |
| B=8 | 5min | 19.5 GB | Tight |
| B=12 | 5min | 26.8 GB | OOM |
| B=32 | 30s | 8.3 GB | Safe |
| B=32 | 2min | 14.2 GB | Safe |
In production (issue #5), this causes ~10 OOM events/hour with MAX_BATCH_SIZE=32.
Root cause
BatchEngine._flush_batch()groups up tomax_batch_sizefiles regardless of their duration- The auto-attention switch in
gpu_worker.py:718only checksmax(file_duration)against threshold — does NOT account for cumulative batch VRAM - No VRAM budget estimation exists in the batching path
Testing gap from PR #8
PR #8 benchmarked only with full + torch.compile and uniform audio durations. Never tested:
- VRAM with compile OFF at various batch sizes
- Mixed-duration batches (e.g., 4x 30s + 2x 5min in one batch)
- Batch-aware OOM boundary
Proposed Fix
1. Dynamic batch size cap based on max file duration
In BatchEngine._flush_batch(), read audio duration from WAV headers and cap batch size:
def max_safe_batch(max_dur_sec, vram_budget_mb=17000):
T = max_dur_sec / 0.08
per_file_mb = 136.6 * T * T / (1024 * 1024)
if per_file_mb <= 0:
return 32
return max(1, min(32, int(vram_budget_mb / per_file_mb)))2. Pre-flight duration check in BatchEngine
Read audio duration when request enters the queue. Use duration metadata for batch formation.
3. VRAM profiling in benchmark suite
Add to benchmark.py: VRAM measurement at each concurrency level, batch size x duration matrix, compile-on vs compile-off comparison.
Affected Files
examples/asr/serving/batch_engine.py— batch formation with VRAM budgetexamples/asr/serving/gpu_worker.py— expose VRAM estimation helperexamples/asr/serving/benchmark.py— add VRAM profilingexamples/asr/serving/server.py— pass duration metadata to BatchEngine
Related
- Issue Add duration-aware batch scheduling to prevent OOM on long audio #3 (duration-aware batch scheduling — broader scope)
- Issue Parakeet server: NeMo warnings flood logs on every transcribe() call + CUDA OOM under load #5 (prod OOM — this is the root cause)
- Issue CUDA stream capture error after OOM recovery with torch.compile + CUDA graphs #6 (unrecoverable GPU state after OOM — prevented by this fix)
Empirical Data
Scaling factor measured on L4 with nvidia-smi during inference (torch.compile OFF, full attention):
- 30s (T=375): +106 MB per file
- 5min (T=3750): +1,826 MB per file
- 8min (T=6000): +4,720 MB per file
- Formula: delta_MB = 136.6 * T-squared / (1024*1024), baseline ~4,862 MB
Activity