Fix IndexError in alignment.py when token id == vocab size (clamp upper bound)#1215
Open
uduntuntu wants to merge 3 commits intom-bain:mainfrom
Open
Fix IndexError in alignment.py when token id == vocab size (clamp upper bound)#1215uduntuntu wants to merge 3 commits intom-bain:mainfrom
uduntuntu wants to merge 3 commits intom-bain:mainfrom
Conversation
…below.
# Run: python test_alignment_out_of_bounds.py
import torch
from whisperx import alignment as A
def run_case(V, tokens, blank_id=0, label=""):
fe = torch.randn(V, dtype=torch.float32)
t = torch.tensor(tokens, dtype=torch.long)
try:
out = A.get_wildcard_emission(fe, t, blank_id)
ok = bool(torch.isfinite(out).all())
print(f"[OK ] {label:36s} -> out.shape={tuple(out.shape)} finite={ok}")
except Exception as e:
print(f"[ERR] {label:36s} -> {type(e).__name__}: {e}")
print("Testing whisperx.alignment.get_wildcard_emission")
print("Function:", A.get_wildcard_emission.__code__.co_filename)
# OFF-BY-ONE repro: token equals vocab size (used to crash)
run_case(34, [34], 0, "off-by-one (V=34, token=V)")
# Mixed case: wildcard + valid + token==V
run_case(34, [-1, 0, 5, 34], 0, "wildcard + in-range + token=V")
# Edge case: empty emissions -> assert (not IndexError)
run_case(0, [0], 0, "empty emissions (V=0)")
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Reproduction on Finnish with alignment showed IndexError: index X is out of bounds for dimension 0 with size V.
Cause: only lower bound was clamped (min=0), so token==V indexed out of range.
Fix: clamp tokens to [0, V-1] and assert valid blank_id/non-empty emissions.
Included minimal repro script and observed OK results after patch.