Skip to content

fix: use parametrizations.weight_norm to silence deprecation warning - #3087

Open
li-lizhe wants to merge 1 commit into
speechbrain:developfrom
li-lizhe:fix/weight-norm-parametrizations
Open

li-lizhe wants to merge 1 commit into
speechbrain:developfrom
li-lizhe:fix/weight-norm-parametrizations

Conversation

@li-lizhe

Copy link
Copy Markdown

Fixes #3074

What & why

torch.nn.utils.weight_norm is deprecated in favor of
torch.nn.utils.parametrizations.weight_norm, which uses the modern
parametrization API. The old API emits a FutureWarning at import/use time
and is scheduled for removal.

SpeechBrain called the deprecated API directly in three source files:

  • speechbrain/nnet/CNN.py — Conv1d / Conv2d / ConvTranspose1d
  • speechbrain/lobes/models/HifiGAN.py — DiscriminatorS
  • speechbrain/lobes/models/beats.py — positional conv

speechbrain/lobes/models/discrete/dac.py already uses the new API via its
try/except import, so it needs no change.

Fix

Replace nn.utils.weight_norm(...) with
nn.utils.parametrizations.weight_norm(...) in the three files above. The new
API is documented as state_dict-compatible with the old one, so no checkpoint
migration is required. remove_weight_norm() calls are left untouched — in
current PyTorch it transparently handles parametrized modules.

Verification

  • No nn.utils.weight_norm( remains in speechbrain/ source (excl. recipes/tests).
  • The change is a pure 1:1 API swap on the same module, same signature
    (name/dim args in beats.py are preserved).
  • I could not run the full test suite locally (PyTorch unavailable in this
    environment), so behaviour was not exercised end-to-end here; CI is expected
    to validate forward/backward and checkpoint loading.

Note

This is a deprecation-warning fix rather than a crash — it does not alter
current runtime behaviour, but prevents breakage once the old API is removed.

torch.nn.utils.weight_norm is deprecated in favor of torch.nn.utils.parametrizations.weight_norm, which uses the modern parametrization API. The new API is state_dict-compatible with the old one. Update the three source files that call it directly (CNN.py, HifiGAN.py, beats.py).
@li-lizhe

Copy link
Copy Markdown
Author

Gentle ping on this one — it's been quiet for 11 days since the last activity, so I wanted to check whether there's anything else you'd like me to adjust or add before this can move forward. Happy to make changes if so. Thanks!

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.

FutureWarning: torch.nn.utils.weight_norm is deprecated in favor of torch.nn.utils.parametrizations.weight_norm.

1 participant