Skip to content

Copy the VAD context instead of writing through a view - #1725

Open
Arjun-Sivasankar wants to merge 1 commit into
SYSTRAN:masterfrom
Arjun-Sivasankar:fix-vad-context-view
Open

Arjun-Sivasankar wants to merge 1 commit into
SYSTRAN:masterfrom
Arjun-Sivasankar:fix-vad-context-view

Conversation

@Arjun-Sivasankar

@Arjun-Sivasankar Arjun-Sivasankar commented Nov 25, 2026 •

Copy link
Copy Markdown

Fixes #1688

Problem

SileroVADModel.__call__ builds the per-window context with a basic slice of the reshaped audio:

batched_audio = audio.reshape(-1, num_samples)
context = batched_audio[..., -context_size_samples:]  # view
context[-1] = 0                                       # also zeroes batched_audio[-1, -64:]

The slice is a view, so zeroing its last row also zeroes the last 64 samples of the audio. The final window is then scored on modified samples, and when reshape returns a view the caller's array is changed in place.

Change

  • Take a copy of the slice (.copy()), one line in faster_whisper/vad.py.
  • Add tests/test_vad.py with two regression tests:
    • calling the model leaves the input unchanged and gives the same result on a second call;
    • the output matches a reference computed from a copy of the audio (this catches the changed last-window probability).

Testing

  • Both new tests fail on current master and pass with the fix.
  • pytest tests/: 20 passed, 1 failed. The failure is test_cliptimestamps_segments (expected " And so my fellow Americans ... your country." and got lower-case text without the final period). It fails in the same way on unmodified master in my environment (Windows, Python 3.13, CPU) and does not use the VAD, so it is unrelated to this change.
  • black, isort and flake8 pass on the changed files.

SileroVADModel.__call__ took the per-window context as a basic slice of
the reshaped audio, which is a view. Zeroing its last row (the silent
context for window 0 after the roll) therefore also zeroed the last 64
samples of the audio: the final window was scored on modified samples,
and a caller's buffer was changed in place whenever reshape returned a
view.

Take a copy of the slice and add regression tests that check the input
is left unchanged and the last window matches a reference computed from
a copy.

Fixes SYSTRAN#1688
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.

SileroVADModel.__call__ zeroes the last 64 audio samples before scoring them (numpy view mutation)

1 participant