[Whisper] Fix decoder position IDs for left-padded batches in longform generation (#48028)
* [Whisper] Fix decoder_position_ids for left-padded batches in longform generation PR #44130 refactored prepare_inputs_for_generation to stop using cache_position for input slicing, but inadvertently removed the cumsum-based decoder_position_ids computation from decoder_attention_mask. Without it, WhisperDecoder falls back to past_kv.get_seq_length() for all batch items — a single value that ignores per-item padding — giving wrong position embeddings for left-padded sequences. With condition_on_prev_tokens=True and heterogeneous batch sizes, shorter sequences get left-padded, so each item has a different real token length. The restored cumsum correctly computes per-item positions from the decoder_attention_mask regardless of padding. Fixes test_whisper_longform_multi_batch_hard_prev_cond and test_whisper_longform_no_speech_detection (both failing since Feb 2026). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * [Whisper] Re-enable test_longform_generate_multi_batch_cond_prev This test was skipped in #44130 with "to be checked asap". It now passes with the decoder_position_ids fix in the previous commit. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * [Whisper] Move position_ids fix to Whisper-specific prepare_inputs_for_generation Instead of patching the generic prepare_inputs_for_generation in generation/utils.py, override it in WhisperForConditionalGeneration to compute decoder_position_ids from decoder_attention_mask for left-padded batches in longform generation. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * format --------- Co-authored-by: ydshieh <ydshieh@users.noreply.github.com>
Y
Yih-Dar committed
e12c79c582bc742029e5f12b538ec71391ace8b3
Parent: f9b76f2
Committed by GitHub <noreply@github.com>
on 8/19/2026, 7:10:07 AM