Parakeet TDT: CUDA illegal memory access in the CUDA-graph greedy decoder after GPU memory is released between transcribe() calls
Describe the bug
With parakeet-tdt-0.6b-v2 and the CUDA-graph TDT greedy decoder (use_cuda_graph_decoder=True, the default), a second transcribe() call fails with CUDA error: an illegal memory access was encountered when GPU memory was allocated and then released back to the driver (torch.cuda.empty_cache()) between the two calls. In a diarize-then-transcribe pipeline the diarization model running on the same GPU between two recordings' transcribe() calls does this, so every run failed on the second recording. The audio does not matter: the same pieces transcribe fine in a fresh process, and random clips reproduce it.
Steps/Code to reproduce bug
Minimal, no diarization and no specific recording (clips are random 0.2 to 30 s slices of any 16 kHz speech audio; we used the AMI Mix-Headset recordings):
import math, random, numpy as np, soundfile as sf, torch
import nemo.collections.asr as nemo_asr
audio = sf.read("any_16k_speech.wav", dtype="float32")[0]
rng = random.Random(1234)
def clips(n):
out = []
for _ in range(n):
k = int(16000 * math.exp(rng.uniform(math.log(0.2), math.log(30.0))))
s = rng.randrange(0, len(audio) - k); out.append(np.ascontiguousarray(audio[s:s + k]))
return out
asr = nemo_asr.models.ASRModel.restore_from("parakeet-tdt-0.6b-v2.nemo", map_location="cuda").eval() # CUDA-graph decoder on (default)
with torch.inference_mode():
asr.transcribe(clips(1000), batch_size=8, verbose=False) # completes
blocks = [torch.randn(64 * 1024 * 1024, device="cuda") for _ in range(32)] # about 8 GB
torch.cuda.synchronize(); del blocks; torch.cuda.empty_cache()
with torch.inference_mode():
asr.transcribe(clips(1000), batch_size=8, verbose=False) # illegal memory accessWhat does and does not trigger it (one process each, batch 8, A100-SXM4-80GB):
Between the two transcribe() calls |
CUDA-graph decoder | Short clips padded to 0.5 s | Result |
|---|---|---|---|
| nothing (20 calls of 1,000 random clips, 20,000 clips) | on | no | completes |
allocate 8 GB, free, empty_cache() |
on | no | 2nd call: illegal memory access |
allocate 8 GB, free, no empty_cache() |
on | no | completes |
allocate 8 GB, free, empty_cache() |
off | no | completes |
allocate 8 GB, free, empty_cache() |
on | yes | 2nd call: illegal memory access |
| AMI meeting EN2002b's 886 diarized pieces alone, fresh process | on | no | completes |
| EN2002a's pieces, then EN2002b's, nothing between | on | no | completes |
| EN2002a's pieces, diarization model (Sortformer) run on the GPU, EN2002b's pieces | on | no | 2nd call: illegal memory access |
all 16 meetings, diarization run beforehand in a separate process (ASR process never calls empty_cache()) |
on | yes | completes |
The crash needs memory to be returned to the driver between calls: reuse inside the PyTorch caching allocator alone does not trigger it. This looks like the decoder's captured CUDA graphs keeping device addresses of buffers that are freed after the first call (inferred from the pattern above; not traced in the decoder code).
In a diarize-then-transcribe pipeline, the diarization step's own empty_cache() is what triggers it: at fc0cbdb, SortformerEncLabelModel._diarize_forward calls torch.cuda.empty_cache() after every forward pass (nemo/collections/asr/models/sortformer_diar_models.py:694), and DiarizeMixin.diarize_generator after every batch (nemo/collections/asr/parts/mixins/diarization.py:351). Where we first saw it: each AMI test meeting (16, sorted by name) is diarized, same-speaker segments less than 0.5 s apart are merged, turns are cut into pieces of at most 30 s, and each meeting's pieces go to transcribe(pieces, batch_size=8); meeting 1 (EN2002a, 1,252 pieces) completes and meeting 2 (EN2002b) fails.
Traceback (paths shortened; CUDA reports the error asynchronously, so the faulting kernel may be earlier than the last frame shown):
nemo/collections/asr/models/rnnt_models.py, line 323, in transcribe
nemo/collections/asr/parts/mixins/transcription.py, line 299, in transcribe
nemo/collections/asr/parts/mixins/transcription.py, line 399, in transcribe_generator
nemo/collections/asr/models/rnnt_models.py, line 962, in _transcribe_output_processing
nemo/collections/asr/parts/submodules/rnnt_decoding.py, line 752, in rnnt_decoder_predictions_tensor
nemo/collections/asr/parts/submodules/rnnt_greedy_decoding.py, line 202, in __call__
nemo/collections/asr/parts/submodules/rnnt_greedy_decoding.py, line 2929, in forward
nemo/collections/asr/parts/submodules/rnnt_greedy_decoding.py, line 2992, in _greedy_decode_blank_as_pad_loop_labels
nemo/collections/asr/parts/utils/rnnt_utils.py, line 316, in batched_hyps_to_hypotheses
torch.AcceleratorError: CUDA error: an illegal memory access was encounteredExpected behavior
The second transcribe() call completes like the first, whatever other GPU work (for example a diarization model in the same process) allocated and released memory in between.
Environment overview (please complete the following information)
- Environment location: Docker (a podman container) on a bare-metal host with NVIDIA A100-SXM4-80GB GPUs, one GPU per container.
- Method of NeMo install: pip from source, inside a CUDA 12.9 container that already had PyTorch 2.13.0:
pip install "nemo_toolkit[asr] @ git+https://github.com/NVIDIA-NeMo/Speech.git@fc0cbdb795236b88bf6a65ca11e8d763d7598cbe"(nemo.__version__3.1.0+fc0cbdb79). - If method of install is [Docker], provide
docker pull&docker runcommands used: the image is built locally (not pullable); run withpodman run -e NVIDIA_VISIBLE_DEVICES=<gpu> -e NVIDIA_DRIVER_CAPABILITIES=compute,utility --ipc=host --net=host -v <data>:/data:ro -v <models>:/models:ro --entrypoint python3 <image> <script>.
Environment details
- OS version: Ubuntu 22.04.5 LTS in the container (host Ubuntu 24.04.3 LTS, kernel 6.8.0-142-generic)
- PyTorch version: 2.13.0+cu129 (CUDA 12.9)
- Python version: 3.12.13
Additional context
- GPU model: NVIDIA A100-SXM4-80GB, driver 570.211.01.
- Model:
nvidia/parakeet-tdt-0.6b-v2(.nemofile), decoding config left at defaults (greedy_batch, CUDA-graph decoder on). - Workaround: turning the CUDA-graph decoder off alone avoids it (padding short pieces alone does not, see the table). With it off, all 16 meetings complete (9.06 audio hours, 13,211 pieces) with cpWER 20.5%. Running diarization in a separate process also avoids it and keeps the faster CUDA-graph decoder.
from omegaconf import open_dict
dcfg = asr.cfg.decoding
with open_dict(dcfg):
dcfg.greedy.use_cuda_graph_decoder = False
asr.change_decoding_strategy(dcfg)- Questions: is this known for the label-looping TDT decoder with CUDA graphs (graphs captured in one
transcribe()call replayed in the next after the buffers they reference were freed)? Should the decoder keep its graph buffers alive between calls, or re-capture when they change?
Source: NVIDIA-NeMo/Speech