Bug: UnboundLocalError for timestamps in _retrieve_segment masks the intended ValueError
Repo/code: generation.py, method _retrieve_segment (as shipped in the remote code of BUT-FIT/DiCoW_v3_3; same code path in TS-ASR-Whisper).
Summary
In _retrieve_segment, the local timestamps is only assigned inside the else: branch of the
if len(timestamp_segment_indices) > 0: split, but the diagnostic at the end of the method
references timestamps unconditionally. When the if-branch is taken and segment_offset <= 0,
line ~524 raises
UnboundLocalError: local variable 'timestamps' referenced before assignment
instead of the intended, informative ValueError("Segment offset: ... <= 0. This should not happen! ...").
This masks the real condition and makes the failure very hard to diagnose. It is reachable e.g. on
prompt_ids-conditioned / certain long-form decoding paths.
Location (line numbers from the BUT-FIT/DiCoW_v3_3 checkpoint)
def _retrieve_segment(self, ...):
...
if len(timestamp_segment_indices) > 0:
... # segment_offset computed at ~L475 / ~L481
# <-- `timestamps` is NEVER assigned in this branch
else:
timestamps = seek_sequence[timestamp_tokens.nonzero().flatten()] # ~L485 (only binding)
...
if segment_offset <= 0:
msg = f"Timestamps: {timestamps}, Segments: {segments}" # ~L524 <-- UnboundLocalError
raise ValueError(f"Segment offset: {segment_offset} <= 0. This should not happen!\n{msg}")
return segments, segment_offset
Fix (minimal)
Initialise timestamps at method entry so the diagnostic always has a value:
def _retrieve_segment(self, ...):
+ timestamps = None
...
if len(timestamp_segment_indices) > 0:
...
(Alternatively, guard the message construction, but a top-of-function init is simplest and keeps the
intended ValueError diagnostic intact.)
Environment
BUT-FIT/DiCoW_v3_3 remote code, transformers==4.55.0, torch 2.5.1 (MPS), Python 3.11.
Bug:
UnboundLocalErrorfortimestampsin_retrieve_segmentmasks the intendedValueErrorRepo/code:
generation.py, method_retrieve_segment(as shipped in the remote code ofBUT-FIT/DiCoW_v3_3; same code path in TS-ASR-Whisper).Summary
In
_retrieve_segment, the localtimestampsis only assigned inside theelse:branch of theif len(timestamp_segment_indices) > 0:split, but the diagnostic at the end of the methodreferences
timestampsunconditionally. When theif-branch is taken andsegment_offset <= 0,line ~524 raises
instead of the intended, informative
ValueError("Segment offset: ... <= 0. This should not happen! ...").This masks the real condition and makes the failure very hard to diagnose. It is reachable e.g. on
prompt_ids-conditioned / certain long-form decoding paths.Location (line numbers from the
BUT-FIT/DiCoW_v3_3checkpoint)Fix (minimal)
Initialise
timestampsat method entry so the diagnostic always has a value:def _retrieve_segment(self, ...): + timestamps = None ... if len(timestamp_segment_indices) > 0: ...(Alternatively, guard the message construction, but a top-of-function init is simplest and keeps the
intended
ValueErrordiagnostic intact.)Environment
BUT-FIT/DiCoW_v3_3remote code,transformers==4.55.0, torch 2.5.1 (MPS), Python 3.11.