Fix PESQ aborting a whole batch on one unscorable sample - #3455
Open
Kayvan-Zahiri wants to merge 1 commit into
Open
Fix PESQ aborting a whole batch on one unscorable sample#3455Kayvan-Zahiri wants to merge 1 commit into
Kayvan-Zahiri wants to merge 1 commit into
Conversation
Kayvan-Zahiri
requested review from
SkafteNicki and
justusschock
as code owners
August 13, 2026 22:29
The pesq backend defaults to on_error=PesqError.RAISE_EXCEPTION, so a single degenerate sample (e.g. a silent reference, or a prediction whose amplitude dwarfs the reference after the backend's shared normalisation) raised NoUtterancesError out of the whole update. Pass on_error=PesqError.RETURN_VALUES at every call site and map the returned error codes, as well as the exception objects pesq_batch collects from its workers, onto nan. The result now keeps one entry per input sample, so the documented shape contract holds again for inputs with more than one batch dimension. The class metric leaves nan samples out of its average instead of propagating them. Fixes Lightning-AI#3304
Kayvan-Zahiri
force-pushed
the
fix/pesq-degenerate-sample-3304
branch
from
August 24, 2026 18:35
e87534b to
8426d03
Compare
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.
Fixes #3304.
One unscorable sample takes down the whole batch.
pesqandpesq_batchbothdefault to
on_error=PesqError.RAISE_EXCEPTIONand torchmetrics never passeson_error, so what happens depends onn_processes:n_processes=1(the default):pesq()raisesNoUtterancesErrorand itpropagates out of
update(). The_filter_error_msgguard added in Ignore theNoUtterancesErrorwhen calculating pesq for a batch #2753 isunreachable on this path.
n_processes != 1:pesq_batch()catches worker exceptions and returns themin the result list, so the guard is reached, but it drops the failed
entry. A 3-sample batch silently returns 2 values.
Measured on a 3-sample batch with
target[1]silent:After:
Change
Pass
on_error=PesqError.RETURN_VALUESat all three call sites and map everyfailure report onto
nan, keeping one entry per input sample. Failures arrivetwo ways and both are handled: negative error codes (
-1..-7, which cannotcollide with a real score since valid PESQ is
>= -0.5) and the exceptionobjects
pesq_batchcollects from its workers.The class metric excludes
nansamples from both the running sum andtotal,so a degenerate sample does not poison an epoch's average. That matches what the
multiprocessing path already did by dropping them, so it is not a new policy.
Scores for scorable samples are unchanged:
RETURN_VALUESandRAISE_EXCEPTIONreturn the same value on success (verified,2.158228635787964 both ways).
Also in this PR
#2753 replaced
pesq_val.reshape(preds.shape[:-1])withreshape(len(pesq_val)), so a(2, 3, 2100)input returned(6,)instead of(2, 3), contradicting the documented(...,)shape. Restored, which is safenow that no entries are dropped. This is a behaviour change for
ndim > 2inputs relative to 1.4.x-1.9.0. Happy to split it into its own PR if you would
rather keep this one minimal.
Tests
Four cases in
tests/unittests/audio/test_pesq.py, all failing on main:The two different failure modes for
[1]and[2]are the two paths above.tests/unittests/audio/test_pesq.py: 20 -> 24 passed, same 6 skipped and 3xfailed. Doctests pass. Wider audio dir: 88 passed. ruff, format and mypy clean.