Repository navigation
fix(serving): batch=1 throughput collapse + 8 gpu_worker lifecycle bugs - #13
Merged
Merged
Conversation
…ghput collapse The early reset of _flush_pending inside _flush_batch() after dequeue allowed the flush loop to immediately re-trigger while the GPU was still processing, causing every new request to be flushed as batch=1 instead of accumulating into efficient batches. Fix: keep only the reset in _guarded_flush() finally block. Also fix test_semaphore_before_dequeue batch_wait from 999s to 0.05s, and add regression test verifying no batch=1 payloads during GPU processing. Co-Authored-By: Claude Opus 4.6 <[email protected]>
… guard CODEx R1 correctly identified that simply removing the early _flush_pending reset serializes GPU batches (max_inflight=2 becomes effectively unused). Fix: add _batches_inflight counter. The flush loop only fires partial batches when GPU is idle (batches_inflight==0), preventing batch=1 collapse. Submit's full-batch trigger still works during GPU processing, preserving the second inflight slot for full batches. - Restore early _flush_pending reset after dequeue (enables full-batch dispatch while GPU busy) - Add _batches_inflight counter (increment after sem acquire, decrement in finally) - Guard flush loop: only fire when batches_inflight==0 - Add test_full_batch_uses_second_inflight_slot regression test Co-Authored-By: Claude Opus 4.6 <[email protected]>
Owner
Author
CODEx Review — R2 APPROVEDR1 finding (resolved): Removing early R2 fix: Added Verified locally:
by CODEx for @beastoin |
- _drain_queues: use _safe_set_exception (prevents InvalidStateError on cancelled futures during shutdown) - submit: reject work after stop() (prevents futures hanging on dead queues) - Pool readiness: create pool queues/threads before _ready.set() (prevents IndexError on fast first request) - Pool shutdown: drain pool queues after worker threads join - Prefetch shutdown: drain _prefetch_queue and join thread; use timeout on put() to prevent hang during shutdown - Pool gc_counter: per-thread local counter (eliminates shared mutable state across pool threads) Co-Authored-By: Claude Opus 4.6 <[email protected]>
- submit/stop: guard both with _submit_lock so enqueue cannot race behind shutdown drain (CODEx R1 finding) - prefetch loop: track owned_item in finally block so items being prefetched during shutdown get their futures failed instead of hanging forever (CODEx R1 finding) Co-Authored-By: Claude Opus 4.6 <[email protected]>
…rror Make gpu_worker.start() accept optional batch_cfg/stream_cfg args so pod's main.py can call start() with no args during migration. Add AudioDurationExceededError class that pod's main.py imports. Co-Authored-By: Claude Opus 4.6 <[email protected]>
…ization Add bench_batch.py and bench_stream.py that automate the full benchmark suite: LibriSpeech download, warmup, WER evaluation (via wer_utils.py Whisper normalization), concurrency sweep, sustained load, and markdown report output. Replaces ad-hoc /tmp scripts that repeatedly computed WER without text normalization. Co-Authored-By: Claude Opus 4.6 <[email protected]>
…h.py Add audio duration tracking per file, compute RTFx (total_audio/wall_time), RTF (wall_time/total_audio), sess/min, and max concurrency with zero failures to both the JSON report and markdown output. Co-Authored-By: Claude Opus 4.6 <[email protected]>
…h.py Manual WAV header parsing returned incorrect durations for LibriSpeech files, making RTFx show 0.0x. Switch to wave.open() for reliable frame count / sample rate computation. Co-Authored-By: Claude Opus 4.6 <[email protected]>
Owner
Author
Batch Benchmark ResultsWER: 1.84% (200 samples, whisper_english normalization) Concurrency Sweep
Peak: 15.31 RPS / 139.19x RTFx at c=32 | Max concurrency (0 failures): c=64 Sustained Load
|
Owner
Author
All Checkpoints Passed — Ready for Merge
Key numbers: WER 1.84% · Peak 15.3 RPS / 139x RTFx at c=32 · Sustained 19.1 RPS / 174x RTFx · 0 failures across 1,600 files |
Owner
Author
|
lgtm |
This was referenced Jun 30, 2026
Closed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fix a throughput collapse bug where every request was processed as batch_size=1 under concurrent load, plus 8 gpu_worker lifecycle bugs (races, leaks, crashes) found via CODEx audit. Also adds deterministic benchmark scripts with industry-standard WER evaluation.
What was wrong
Under concurrent load,
_flush_pendingwas reset immediately after dequeue — before the GPU finished processing the current batch. This allowed the flush loop to fire during GPU work, flushing every waiting request as a single-item batch. The result: batch_size=1 regardless of load, destroying throughput.A CODEx audit of
gpu_worker.pythen uncovered 8 additional lifecycle bugs — race conditions betweenstop()/submit(), futures silently hanging on shutdown, pool threads sharing mutable state, and more. All are concurrency bugs that surface under production load patterns (high request rate, graceful shutdown, pool mode).Fixes
_flush_pendingreset before GPU completes_batches_inflightcounter — partial flushes only when GPU idle_drain_queuescrashes on cancelled futures_safe_set_exceptionstop()/submit()race — futures enqueued to dead queues_submit_lock_ready.set()_prefetch_queueowned_itemtracking withfinally_gc_countershared across pool threadsstart()requires args — breaks pod migrationBenchmark
Generated by
examples/asr/serving/bench_batch.py— deterministic benchmark with Whisper English text normalization viawer_utils.py.Model:
nvidia/parakeet-tdt-0.6b-v3· GPU: NVIDIA L4 (24GB) · Container:nvcr.io/nvidia/nemo:26.02Config: auto attention, VRAM-aware batching,
cuda_graphs=falseDataset: LibriSpeech test-clean, 200 samples
Concurrency scaling
Files changed
examples/asr/serving/batch_engine.py—_batches_inflightcounter for flush loop guardexamples/asr/serving/gpu_worker.py— 8 lifecycle/concurrency fixes + backward-compat interfaceexamples/asr/serving/test_batch_engine.py— 35 tests including batch=1 regression testsexamples/asr/serving/bench_batch.py— Deterministic batch benchmark with WER (new)examples/asr/serving/bench_stream.py— Deterministic streaming benchmark with WER (new)Test plan