mstar.model.whisper.components.timestamps#

Whisper timestamp decoding rules as a per-request state that travels with the token.

When a request asks for timestamps (no <|notimestamps|> in its prompt), Whisper’s decoding is constrained the way openai-whisper / HF’s WhisperTimeStampLogitsProcessor constrain it:

  • the first generated token is a timestamp no later than max_initial_timestamp_index;

  • timestamps come in pairs — after <|t|> that closed a segment only a timestamp (>= the same value) or end-of-text may follow, and after the pair only text may follow;

  • timestamps never decrease;

  • when the total probability of all timestamp tokens beats the best text token, a timestamp is sampled.

Which rule applies depends on the tokens generated so far. The worker launches the next decode step before it has read the previous step’s token on the host, so that history cannot live in Python: the four integers that summarize it ([active, phase, last_ts, ceil]) are a tensor row that is routed along with the sampled token, updated by TimestampRules.advance() inside the (captured) forward, and turned into masks on the (bs, vocab) logits by TimestampRules.apply() with no data-dependent control flow. rule_state() builds the same row from a token history on the host — the prefill’s first row, and the tests’ oracle for advance.

Functions

inactive_state()

rule_state(generated, config)

The rule for the next token, from what the request generated since its prompt.

Classes

TimestampRules(config)

Vectorized rule application and state transition.

class mstar.model.whisper.components.timestamps.TimestampRules(config)[source]#

Bases: object

Vectorized rule application and state transition.

Parameters:

config (WhisperModelConfig)

advance(state, tokens)[source]#

The state after sampling tokens: (bs,); inactive rows are returned unchanged. Pure tensor ops, so it runs inside the graph.

Parameters:
Return type:

Tensor

apply(logits, state)[source]#

logits: (bs, vocab), state: (bs, 4) int64 -> masked logits.

Rows with active == 0 pass through untouched.

Parameters:
Return type:

Tensor

mstar.model.whisper.components.timestamps.inactive_state()[source]#
Return type:

list[int]

mstar.model.whisper.components.timestamps.rule_state(generated, config)[source]#

The rule for the next token, from what the request generated since its prompt. last_ts is the last timestamp token (timestamp_begin - 1 when none yet); ceil the exclusive timestamp bound.

Parameters:
Return type:

list[int]