Repository navigation
Fix InputNormalization padding masks for nondefault length dimensions - #3109
Open
mottopanikeiku wants to merge 1 commit into
Open
mottopanikeiku wants to merge 1 commit into
mottopanikeiku wants to merge 1 commit into
Conversation
I found that InputNormalization always built its padding mask along dimension 1, even when length_dim selected another time axis. I use the configured dimension for the mask and document the channel-first case. I added regression tests for sentence, batch and global normalization with the time axis in dimensions 2 and 3. Assisted-by: Claude Assisted-by: GPT-6 Astra Signed-off-by: mottopanikeiku <176798723+mottopanikeiku@users.noreply.github.com>
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.
What does this PR do?
InputNormalizationuseslength_dimto compute statistics but always builds its padding mask along dimension 1. For channel-first features,length_dim=2therefore gives wrong sentence-normalized values and raisesAssertionErrorwith batch/global normalization.This reproducer compares the same padded features in time-first and channel-first layouts:
Observed on CPU with torch/torchaudio 2.11.0:
matches_time_first=False; short first feature[-0.4170288145542145, -0.20851440727710724]matches_time_first=True;[-1.0, 1.0]AssertionErrormatches_time_first=TrueAssertionErrormatches_time_first=TrueI pass
self.length_dimto the existing mask helper and clarify the argument's docstring. The regression test moves the time axis to dimensions 2 and 3 for all three normalization modes, with and without padding-output normalization. All 12 cases fail before the fix and pass after it.This affects callers using the documented nondefault time axis, such as a channel-first spectrogram pipeline. I did not find a bundled recipe using a nondefault
length_dim. The default layout is unchanged. No new dependencies or breaking API changes.Checks run:
pytest tests/unittests/test_input_norm.py tests/unittests/test_features.py tests/unittests/test_length_mask.py --doctest-modules speechbrain/processing/features.py -q: 564 passed, 1 GPU-only test skipped.pre-commit run -a: all hooks passed.Before submitting
PR review
Reviewer checklist
I used AI assistance (Claude and GPT-6 Astra) to find, fix and test this bug.