Skip to content

fix: clamp shift perturbation for short audio instead of silently skipping#15561

Merged
pzelasko merged 3 commits into
NVIDIA-NeMo:mainfrom
stanley1208:fix/shift-perturbation-clamp-short-audio
Apr 23, 2026
Merged

fix: clamp shift perturbation for short audio instead of silently skipping#15561
pzelasko merged 3 commits into
NVIDIA-NeMo:mainfrom
stanley1208:fix/shift-perturbation-clamp-short-audio

Conversation

@stanley1208
Copy link
Copy Markdown
Contributor

What does this PR do?

Fix a bug in ShiftPerturbation.perturb() where audio augmentation was silently skipped when the randomly sampled shift exceeded the audio duration. This caused short audio clips to receive no shift augmentation at all, with no warning to the user.

Before: If abs(shift_ms) / 1000 > data.duration, the method returned immediately — a silent no-op. Users with short utterances or large max_shift_ms had their augmentation silently disabled.

After: The shift is clamped to the audio duration so some shift is always applied. This resolves the TODO at line 442: "do something smarter than just ignore this condition".

Collection: ASR

Changelog

  • Fix ShiftPerturbation.perturb() to clamp shift amount instead of silently skipping augmentation for short audio
  • Remove resolved TODO comment
  • Add 7 unit tests for ShiftPerturbation covering normal operation, short audio clamping, length preservation, and zero-shift edge case

Usage

from nemo.collections.asr.parts.preprocessing.perturb import ShiftPerturbation

# Previously: short audio (5ms) with max_shift=20ms would silently skip augmentation
# Now: shift is clamped to audio duration and applied
perturb = ShiftPerturbation(min_shift_ms=10.0, max_shift_ms=20.0)
perturb.perturb(short_audio_segment)  # now always applies shift

…pping

Signed-off-by: stanley1208 <stanley.mei08@gmail.com>
Made-with: Cursor
@github-actions github-actions Bot added the ASR label Mar 29, 2026
@stanley1208
Copy link
Copy Markdown
Contributor Author

@nithinraok @pzelasko Ready for review — fixes a real bug where ShiftPerturbation silently skipped augmentation for short audio clips. Resolves the TODO at perturb.py line 442. Includes 7 unit tests. Thanks!

pzelasko
pzelasko previously approved these changes Mar 30, 2026
Copy link
Copy Markdown
Collaborator

@pzelasko pzelasko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Looks good to me.

@chtruong814 chtruong814 added the needs-follow-up Issue needs follow-up label Mar 31, 2026
@stanley1208
Copy link
Copy Markdown
Contributor Author

@pzelasko @nithinraok Friendly ping , this was approved but hasn't been merged yet. Is there anything else needed? Happy to address any feedback. Thanks!

@pzelasko pzelasko enabled auto-merge (squash) April 7, 2026 14:54
@pzelasko pzelasko added Run CICD and removed Run CICD labels Apr 7, 2026
@pzelasko
Copy link
Copy Markdown
Collaborator

pzelasko commented Apr 7, 2026

Can you fix the linters? Otherwise the CI with tests won't trigger

@chtruong814 chtruong814 added waiting-for-customer waiting-on-customer Waiting on the original author to respond needs-follow-up Issue needs follow-up and removed waiting-for-customer needs-follow-up Issue needs follow-up waiting-on-customer Waiting on the original author to respond labels Apr 14, 2026
@svcnvidia-nemo-ci svcnvidia-nemo-ci added waiting-on-maintainers Waiting on maintainers to respond and removed needs-follow-up Issue needs follow-up labels Apr 21, 2026
Signed-off-by: Jason <jasoli@nvidia.com>
@copy-pr-bot
Copy link
Copy Markdown

copy-pr-bot Bot commented Apr 22, 2026

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@svcnvidia-nemo-ci svcnvidia-nemo-ci added waiting-on-customer Waiting on the original author to respond and removed waiting-on-maintainers Waiting on maintainers to respond labels Apr 22, 2026
@pzelasko pzelasko merged commit 154e993 into NVIDIA-NeMo:main Apr 23, 2026
235 of 241 checks passed
@svcnvidia-nemo-ci svcnvidia-nemo-ci removed the waiting-on-customer Waiting on the original author to respond label Apr 24, 2026
@blisc
Copy link
Copy Markdown
Collaborator

blisc commented Apr 24, 2026

Thanks for the contribution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants