Repository navigation
Description
Current State
model.transcribe() is not thread-safe. Concurrent calls from a multi-threaded serving framework (e.g. FastAPI + uvicorn) cause race conditions that result in:
ValueError: Cannot unfreeze partially without first freezing the module- CUDA stream capture errors
- Corrupted
_frozen_grad_mapstate - Intermittent incorrect transcription results
Production impact: 33 concurrent requests → 2,103 HTTP 500 errors in our Parakeet TDT service.
Current workaround: threading.Semaphore(1) serializing all inference — kills throughput.
Root Cause
ASRTranscriptionMixin._transcribe_on_begin() calls encoder.freeze(), decoder.freeze(), joint.freeze() which mutate shared _frozen_grad_map dicts on each module. _transcribe_on_end() calls .unfreeze(partial=True) which reads and deletes those dicts. Under concurrent access, thread A's unfreeze races with thread B's freeze.
The freeze/unfreeze is redundant:
transcribe()is already decorated with@torch.inference_mode()— disables autograd, makingrequires_grad=Falseunnecessary_transcribe_on_begin()already callsself.eval()— handles BatchNorm/Dropout correctly- RNNT's
transcribe()adds@torch.no_grad()on top of that
The freeze/unfreeze predates the @inference_mode() decorator and was never updated.
Additional issue: transcribe_generator() is NOT decorated with @inference_mode(), unlike transcribe().
Affected Code (4 locations)
| File | What's frozen |
|---|---|
nemo/collections/asr/parts/mixins/transcription.py (ASRTranscriptionMixin) |
encoder, decoder, joint |
nemo/collections/asr/models/hybrid_rnnt_ctc_models.py |
ctc_decoder |
nemo/collections/asr/models/aed_multitask_models.py |
transf_decoder |
nemo/collections/asr/models/transformer_bpe_models.py |
transf_decoder |
Requirements
- Remove all freeze/unfreeze calls from the transcription path
- Add
@torch.inference_mode()totranscribe_generator() - Keep
self.eval()/self.train(mode=original)(these are needed for BatchNorm/Dropout) - Add concurrent transcription regression tests
- Existing tests must pass with no regressions
Remaining Lower-Priority Issues (not in scope)
These shared mutations still exist but don't crash — they cause minor non-determinism:
preprocessor.featurizer.dither— mutated to 0.0 then restoredpreprocessor.featurizer.pad_to— mutated to 0 then restoredlogging.set_verbosity()— global state change
References
- Upstream NeMo issue: model.transcribe() is not thread-safe: encoder.freeze()/unfreeze() race causes ValueError under concurrent inference NVIDIA-NeMo/Speech#15771
- NeMo issue parakeet-tdt-0.6b-v2 Multi-threaded transcription crashes NVIDIA-NeMo/Speech#13988 (confirms transcribe not thread-safe)
Activity
fix(serving): address CODEx review — semaphore-before-dequeue, timest…