Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -706,15 +706,22 @@ def shared_transcribe_step_stateful(self, requests: list[Request], encs: Tensor,
request_is_last = torch.tensor(
[request.is_last for request in requests_to_process], dtype=torch.bool, device=self.device
)
enc_lens_dec = enc_lens - tokens_per_left_padding_tensor
encs_to_process = encs[request_ids_to_process][:, :, self.tokens_per_left_padding :]
# For the last chunk of a request, enc_lens_dec is left untrimmed (see below), so it can reflect
# more valid encoder frames than the request's window actually has room for once left padding is
# sliced off (e.g. when right_padding_size is much larger than chunk_size). Clamp it to the actual
# post-left-padding tensor length so it never exceeds `encs_to_process`'s time dimension, which
# would otherwise let an out-of-bounds time index reach the decoder for that request.
max_post_left_padding_len = encs_to_process.shape[-1]
enc_lens_dec = torch.clamp(enc_lens - tokens_per_left_padding_tensor, max=max_post_left_padding_len)
enc_lens_dec_trimmed = torch.where(
request_is_last,
enc_lens_dec,
torch.minimum(enc_lens_dec, tokens_per_frame_tensor.expand_as(enc_lens_dec)),
)
self.stateful_transcribe_step(
requests_to_process,
encs[request_ids_to_process][:, :, self.tokens_per_left_padding :],
encs_to_process,
enc_lens_dec_trimmed,
enc_lens_dec,
ready_state_ids,
Expand Down
Loading