Raise in vad on non-finite input instead of reporting silence (closes #4216) - #4217
Raise in vad on non-finite input instead of reporting silence (closes #4216)#4217Kayvan-Zahiri wants to merge 1 commit into
Conversation
The trigger measure is a running mean, so one NaN or infinity poisons it permanently and every later comparison against trigger_level is false. Nothing ever triggers, the whole waveform is treated as silence, and an empty Tensor is returned with no warning. The failure is position dependent, which makes it easy to miss: a non-finite sample in the leading region that vad scans discards everything, while one inside the speech leaves the trimming intact and returns a waveform that still contains the non-finite sample. Check the input up front and raise, as this file already does for out of range arguments elsewhere. Closes pytorch#4216
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/audio/4217
Note: Links to docs will display an error until the docs builds have been completed. This comment was automatically generated by Dr. CI and updates every 15 minutes. |
|
Hi @Kayvan-Zahiri! Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks! |
|
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks! |
Closes #4216.
The bug
vadbuilds a running trigger measure:One non-finite sample makes
measnon-finite, and the recurrence then keepsmean_meas[i]non-finite for the rest of the waveform. Every later comparisonagainst
trigger_levelis false, so nothing triggers and the whole input isreported as silence. The caller gets an empty Tensor, with no warning and no
exception.
It is position dependent, which is what makes it easy to miss:
The third row is not a working case. That output still contains the NaN, so
vadhands back a waveform that is just as broken, only without the obvioussymptom.
The fix
Check the input once at the top of
functional.vadand raise. This file alreadyraises
ValueErrorfor out-of-range arguments in several places, so the shape isconsistent with the surrounding code.
Behaviour change
Input containing NaN or infinity now raises
ValueErrorwhere it previouslyreturned a Tensor. That includes the "NaN inside speech" case above, which used to
return trimmed audio. Given that output still carried the non-finite sample, an
error seems better than a result the caller is likely to trust.
Clean input is unaffected.
Verification
NaN and infinity now raise instead of returning an empty Tensor.
torch.isfiniteis safe for every dtypevadaccepts, including integertensors, where it is true everywhere.
Vadis covered bytorchscript_consistency_impl.py, so Ichecked the guard compiles under
torch.jit.scriptand raises correctly whenscripted.
bool()on the 0-dim result is required for that.vad, so nothing already in thesuite changes meaning.
transforms_cpu_test.py -k vad: 24 passed. The 6 new cases (3 values x 2dtypes) fail with
AssertionError: ValueError not raisedwithout the guard.I could not build torchaudio from source on this machine, so the behavioural runs
above were done by applying the same guard to an installed 2.11.0 and restoring it
afterwards. CI is authoritative over my numbers.
Note
@adityaanikam confirmed the root cause on the issue and stood aside for me to open
this, which I appreciated.
I also saw the notice that this repository is no longer actively monitored, so no
expectation of a quick review. The fix is small and self-contained if it is ever
useful.