Repository navigation
feat(serving): VRAM-aware dynamic batching with auto attention switching - #11
Conversation
BatchEngine now reads audio duration at submit time and dynamically caps batch size based on available GPU VRAM, preventing OOM when long files arrive at high concurrency. Fixes #9. Key changes: - PendingRequest stores audio duration (wave/soundfile header read) - _form_vram_safe_batch() sorts by duration and caps using empirical VRAM formula: available_mb / (136.6 * T_max^2 / 1048576) - GPUWorker exposes vram_info (total/baseline measured after all models load via mem_get_info for accuracy) - Starvation guard ensures long-duration files aren't starved by steady short-file traffic (5s timeout, anchor-based batch formation) - Unknown duration treated conservatively (auto_threshold_sec → B=1) - Local attention and auto-mode long files skip quadratic limiter - Config: vram_safety_factor, vram_bytes_per_t2, starvation_timeout_sec - 17 unit tests covering estimation, batch formation, starvation, edge cases Co-Authored-By: Claude Opus 4.6 <[email protected]>
…unknown durations - Distinguish disabled-by-config (vram_enabled=False) from measured no-headroom (vram_available=0 but enabled → cap to B=1) - Unknown durations no longer bypass auto-mode quadratic limiter: _estimate_max_batch() takes duration_known flag, auto-mode skip requires known duration >= threshold - Divide VRAM budget by pool_size for multi-worker mode - Form one global VRAM-safe batch then partition by timestamps (prevents double-dequeue exceeding max_batch_size) - Added 3 new tests: negative budget, auto-mode unknown bypass, auto-mode unknown batch formation Co-Authored-By: Claude Opus 4.6 <[email protected]>
…ed-queue batching - Move vram_available <= 0 check before local/auto attention bypasses so negative budget caps to B=1 for all modes - Change batch shrink from jump (n = limit) to step-down (n -= 1) so mixed queues properly exclude long/unknown files while keeping short files in large batches (e.g., 20 short + 1 unknown → batch of 20) - Added 2 tests: mixed-queue throughput, negative budget across modes Co-Authored-By: Claude Opus 4.6 <[email protected]>
All checkpoints passed — ready for reviewWorkflow Summary
Key Results
|
…with it) 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 -> 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]>
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 |
12x1711 MiB exceeds L4 capacity (proves fix is needed) |
test_oom_error_signature_matches_prod |
Error string matches prod format |
All 27 tests pass (22 existing + 5 new).
…-user scale - Fire-and-forget flush loop: batch N+1 forms while N processes on GPU - Inflight semaphore (max_inflight=2) bounds concurrent GPU work - Tuned defaults: max_wait_seconds=0.002 (+111% RPS), max_queue_depth=4096 - Removed sub-batch timestamp splitting (single GPU call per batch) - Aligned server.py fallback defaults with batch_engine.py - Added 4 concurrent flush tests (semaphore, drain, fire-and-forget, queue full) Co-Authored-By: Claude Opus 4.6 <[email protected]>
…amp leak - Acquire inflight semaphore before dequeuing from _pending, preventing batch pile-up behind saturated GPU (CODEx finding #2) - Use per-request req.timestamps in _serialize_result instead of batch-level any_ts flag, preventing timestamp data leak to non- timestamp callers (CODEx finding #1) - Added test_mixed_timestamps_no_leak: verifies non-ts requests don't receive timestamp fields when batched with ts requests - Added test_semaphore_before_dequeue: verifies requests stay in _pending until a semaphore slot opens Co-Authored-By: Claude Opus 4.6 <[email protected]>
CODEx round 2 found that _serialize_result's dict path (production GPUWorker shape) bypassed the per-request timestamps flag via output.update(result). Added timestamp pop for non-ts callers and split test into object-path and dict-path variants. Co-Authored-By: Claude Opus 4.6 <[email protected]>
BatchEngine.__init__ now accepts **kwargs so callers passing extra options (e.g. on_batch_complete, on_gpu_oom) don't crash. Co-Authored-By: Claude Opus 4.6 <[email protected]>
Benchmark Results — Parakeet TDT 0.6B (VRAM-Aware Batch Sizing)GPU: NVIDIA L4 | VRAM: 23 GB (4.8 GB used post-benchmark) | Container: nvcr.io/nvidia/nemo:26.02 Quality Gate — PASS ✓LibriSpeech test-clean (20 samples): WER 2.0% (9/441 words) Concurrency Sweep — PASS ✓
Max tested: c=512, 0 failures, p99 < 3s OOM Prevention — PASS ✓
Post-benchmark VRAM7,384 total requests processed, 0 rejected, 0 pending. VRAM: 4,886 MiB used / 17,678 MiB free (no leak). |
All Checkpoints Passed — Ready for Review
Key Numbers
|
Full Benchmark Results — PR #11 (VRAM-aware Batch Sizing)GPU: L4 (24GB) | Container: nvcr.io/nvidia/nemo:26.02 | Dataset: 200 LibriSpeech test-clean samples (26.1 min audio) Batch ModeQuality
Concurrency Sweep
Peak: RTFx 106.4x | RPS 13.6 (baseline RPS 13.2) — NO REGRESSION Sustained Load (c=32, 3 reps)
Streaming ModeQuality
Concurrency (start-high step-down from c=64)
Confirmed max concurrency: c=32 | RTFx 10.8x (baseline RTFx 7.3x at c=64, PR #4) — IMPROVEMENT Sustained Load (c=32, 3 reps)
Verdict
WER baseline calibrated at 12.6% per commit 76d5e985 (L4, parakeet-tdt-0.6b-v3) |
Auto Attention Mode Benchmark — VRAM-aware Batching + Attention SwitchingGPU: L4 (24GB) | Container: nvcr.io/nvidia/nemo:26.02 | Dataset: 200 LibriSpeech test-clean (26.1 min) Test 1: Quality (c=1, auto mode)
Test 2: Mixed Concurrent (interleaved short+long, forces attention switching)
110 total attention switches confirmed in server logs — all handled cleanly Test 3: Long-only burst (all local attention)
Test 4: Short-only burst (all full attention + VRAM sizing)
Test 5: Sustained mixed load (2 min at c=16)
Verdict
|
- Prevent unbounded flush task accumulation behind saturated semaphore by tracking a single pending flush task (_flush_pending guard) - Fall back auto attention to full mode when model_pool_size > 1 to prevent shared mutable state race between pool workers - Pass durations through GPU payload so auto-switching works correctly even when prefetch replaces paths with audio tensors - Add 4 new tests covering flush guard, pool fallback, and duration passthrough (38 total, all pass) Co-Authored-By: Claude Opus 4.6 <[email protected]>
- GPU worker now also falls back auto→full when pool_size>1, preventing _switch_attention() from mutating shared _raw_batch_model/_attn_is_local - Submit's immediate flush path now uses _guarded_flush to prevent unbounded task accumulation under saturated semaphore - Release _flush_pending after dequeue (not after GPU completes) so new work can trigger another flush while previous batch processes Co-Authored-By: Claude Opus 4.6 <[email protected]>
Co-Authored-By: Claude Opus 4.6 <[email protected]>
All Checkpoints Complete — Ready for Review
Summary: 38 tests pass, 0 failures across 3,815+ requests (batch + streaming + auto), WER within tolerance, RTFx improved over baseline. CODEx approved after 4 review rounds. Awaiting merge approval. |
|
Merged by manager. PR #11 complete. 🎉 |
Summary
BatchEngine now dynamically caps batch size based on audio duration and available GPU VRAM, preventing OOM when long files arrive at high concurrency. Concurrent batch flushing allows batch N+1 to form while N processes on GPU, maximizing throughput for million-user scale. Fixes #9.
Model: nvidia/parakeet-tdt-0.6b-v3 (0.6B params)
Changes
VRAM-aware batch formation (
batch_engine.py)_estimate_max_batch()caps batch using empirical quadratic VRAM formulaConcurrent batch flushing (
batch_engine.py)max_inflight=2) bounds concurrent GPU workSafety guards (
batch_engine.py,gpu_worker.py)model_pool_size > 1(prevents shared state race)Tuned defaults (
batch_engine.py,server.py,serving-batch.yaml)max_wait_seconds: 0.1 -> 0.002 (reduces batch formation latency)max_queue_depth: 256 -> 4096 (prevents 503 cascade at high concurrency)VRAM Formula
Benchmark Results
GPU: NVIDIA L4 (24GB) | Container: nvcr.io/nvidia/nemo:26.02 | Dataset: 200 LibriSpeech test-clean (26.1 min audio)
Batch Mode (full attention, compiled)
Streaming Mode (480ms latency)
Auto Attention Mode (VRAM batching + attention switching)
Config:
attention_mode: auto, threshold 15s, torch.compile disabled110 attention switches confirmed -- 0 failures across 2,615 total requests
Files Changed
Serving
examples/asr/serving/batch_engine.py-- VRAM-aware batch sizing, concurrent flush, flush guard, pool fallbackexamples/asr/serving/server.py-- Aligned fallback defaults, added max_inflightexamples/asr/serving/gpu_worker.py-- Auto-pool fallback, duration passthrough for auto-switchingexamples/asr/serving/conf/serving-batch.yaml-- Added max_inflight configTests (38 total, all pass)
examples/asr/serving/test_batch_engine.py-- 33 unit tests (flush guard, pool fallback, duration passthrough)examples/asr/serving/test_oom_reproduction.py-- 5 E2E OOM reproduction testsTest Plan
CODEx Review Summary
4 rounds to approval: