Skip to content

Commit 7a8e9a0

Browse files
committed
Fix OOB decode crash when right_padding_size >> chunk_size in buffered RNNT pipeline
enc_lens_dec was left unclamped for a request's final chunk, letting it exceed the actual post-left-padding tensor size and feed an out-of-bounds time index into the TDT decoder (CUDA index-out-of-bounds assert). Signed-off-by: naymaraq <dkaramyan@nvidia.com>
1 parent 8270308 commit 7a8e9a0

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

nemo/collections/asr/inference/pipelines/buffered_rnnt_pipeline.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -706,15 +706,22 @@ def shared_transcribe_step_stateful(self, requests: list[Request], encs: Tensor,
706706
request_is_last = torch.tensor(
707707
[request.is_last for request in requests_to_process], dtype=torch.bool, device=self.device
708708
)
709-
enc_lens_dec = enc_lens - tokens_per_left_padding_tensor
709+
encs_to_process = encs[request_ids_to_process][:, :, self.tokens_per_left_padding :]
710+
# For the last chunk of a request, enc_lens_dec is left untrimmed (see below), so it can reflect
711+
# more valid encoder frames than the request's window actually has room for once left padding is
712+
# sliced off (e.g. when right_padding_size is much larger than chunk_size). Clamp it to the actual
713+
# post-left-padding tensor length so it never exceeds `encs_to_process`'s time dimension, which
714+
# would otherwise let an out-of-bounds time index reach the decoder for that request.
715+
max_post_left_padding_len = encs_to_process.shape[-1]
716+
enc_lens_dec = torch.clamp(enc_lens - tokens_per_left_padding_tensor, max=max_post_left_padding_len)
710717
enc_lens_dec_trimmed = torch.where(
711718
request_is_last,
712719
enc_lens_dec,
713720
torch.minimum(enc_lens_dec, tokens_per_frame_tensor.expand_as(enc_lens_dec)),
714721
)
715722
self.stateful_transcribe_step(
716723
requests_to_process,
717-
encs[request_ids_to_process][:, :, self.tokens_per_left_padding :],
724+
encs_to_process,
718725
enc_lens_dec_trimmed,
719726
enc_lens_dec,
720727
ready_state_ids,

0 commit comments

Comments
 (0)