Skip to content

fix: use persistent=False for recomputable buffers in transforms#4188

Open
prisha2410 wants to merge 1 commit intopytorch:mainfrom
prisha2410:fix/non-persistent-buffers
Open

fix: use persistent=False for recomputable buffers in transforms#4188
prisha2410 wants to merge 1 commit intopytorch:mainfrom
prisha2410:fix/non-persistent-buffers

Conversation

@prisha2410
Copy link
Copy Markdown

Summary

Updates all register_buffer() calls in torchaudio/transforms/_transforms.py
to use persistent=False for buffers that are recomputable from constructor
arguments.

Motivation

Fixes #3059

When loading a pre-existing checkpoint into a model containing torchaudio
transforms, a missing key error is raised because recomputable buffers
(e.g. window functions, mel filterbanks, kernels) are saved in the state dict
even though they can be reconstructed from the constructor parameters.

Changes

Added persistent=False to the following buffers across transforms:

  • window — in Spectrogram, InverseSpectrogram, GriffinLim, ISTFT, PitchShift (5 locations)
  • fb — in MelScale, InverseMelScale (2 locations)
  • dct_mat — in MFCC, LFCC (2 locations)
  • filter_mat — in LFCC (1 location)
  • kernel — in Resample (1 location)
  • phase_advance — in TimeStretch (1 location)

Verification

Before fix:

T.Resample(16000, 8000).state_dict().keys()  # ['kernel']
T.Spectrogram().state_dict().keys()           # ['window']
T.MelSpectrogram().state_dict().keys()        # ['spectrogram.window', 'mel_scale.fb']

After fix:

T.Resample(16000, 8000).state_dict().keys()  # []
T.Spectrogram().state_dict().keys()           # []
T.MelSpectrogram().state_dict().keys()        # []

cc @mthrok @nateanl

@prisha2410 prisha2410 requested a review from a team as a code owner April 21, 2026 12:16
@pytorch-bot
Copy link
Copy Markdown

pytorch-bot Bot commented Apr 21, 2026

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/audio/4188

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.

@meta-cla
Copy link
Copy Markdown

meta-cla Bot commented Apr 21, 2026

Hi @prisha2410!

Thank you for your pull request and welcome to our community.

Action Required

In 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.

Process

In 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 CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at [email protected]. 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.

Use non-persistent buffers

1 participant