Skip to content

Fix max_initial_timestamp_index never being applied in WhisperTimeStampLogitsProcessor - #1823

Open
l3xxxy wants to merge 1 commit into
huggingface:mainfrom
l3xxxy:fix/whisper-max-initial-timestamp
Open

l3xxxy wants to merge 1 commit into
huggingface:mainfrom
l3xxxy:fix/whisper-max-initial-timestamp

Conversation

@l3xxxy

@l3xxxy l3xxxy commented Oct 27, 2026

Copy link
Copy Markdown

WhisperTimeStampLogitsProcessor._call returned early (continue) at begin_index, which made the subsequent "apply the max_initial_timestamp option" block unreachable since it is guarded by the same condition. As a result max_initial_timestamp_index (set to 50, i.e. 1.0s, in the generation config of the official Whisper exports) was never enforced and the first timestamp token could be sampled anywhere in the 30s window. The reference implementation in transformers applies the restriction inside the first-step branch, right after masking text tokens.

This PR:

  • moves the first-step text-token masking into the same branch as the max_initial_timestamp check, mirroring transformers' WhisperTimeStampLogitsProcessor.__call__;
  • changes the WhisperGenerationConfig.max_initial_timestamp_index default from 1 to null (no restriction), matching getattr(generate_config, "max_initial_timestamp_index", None) in transformers. The previous default of 1 looks like a leftover of openai-whisper's max_initial_timestamp = 1.0 seconds and would have clamped models without the key to 0.02s once the block became reachable; the processor now checks != null so a missing key cannot produce subarray(NaN).

Tests: added unit tests in tests/utils/logits_process.test.js that construct the processor directly with a small synthetic vocabulary and verify (1) timestamps beyond timestamp_begin + max_initial_timestamp_index are masked at the first step, (2) nothing is masked when the index is unset, (3) the restriction is not applied on later steps. The first test fails on main. pnpm format:check and pnpm typegen pass.

Note: expected outputs of existing timestamp tests that rely on hub models (e.g. the return_timestamps: true case for Xenova/tiny-random-WhisperForConditionalGeneration, whose config sets max_initial_timestamp_index: 50 yet the current expectation has a first timestamp of 28.96s) may need to be regenerated, since they were recorded with the restriction unintentionally disabled. Happy to update them if you confirm the expected values.

…tampLogitsProcessor

The early `continue` at `begin_index` made the `max_initial_timestamp`
block unreachable, so the first timestamp was never restricted. Mirror the
reference implementation by nesting the check inside the first-step branch,
and align the `WhisperGenerationConfig` default with transformers (unset
means no restriction) instead of the previous `1` (= 0.02s).
@laoyyu

laoyyu commented Nov 7, 2026

Copy link
Copy Markdown

FYI, #1875 fixes the same unreachable first-step branch, and independently reached the same conclusion about the default (1 -> null), so the queue now has two near-identical diffs. I have noted on #1875 that I will withdraw it if this one lands first — no action needed from you.

One detail that may be worth folding in here: the guard has to be != null rather than !== null. When the key is absent the value is undefined, so timestamp_begin + undefined is NaN and subarray(last_allowed + 1) becomes subarray(NaN) -> subarray(0), which masks every logit in the row (text tokens included) and makes the row softmax return NaN. Your != null check is already correct; I am only flagging it because !== null reads as the natural port of getattr(..., None) and silently is not.

@nico-martin nico-martin self-assigned this Nov 11, 2026

@nico-martin nico-martin left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @l3xxxy, thanks for the fix!

Could you also cover an omitted limit and index zero, and check the existing Whisper expectations? We should coordinate the overlapping change with #1742.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants