Skip to content

stft: remove non-center overload and python functional wrapper#73434

Closed
peterbell10 wants to merge 26 commits intogh/peterbell10/281/basefrom
gh/peterbell10/281/head
Closed

stft: remove non-center overload and python functional wrapper#73434
peterbell10 wants to merge 26 commits intogh/peterbell10/281/basefrom
gh/peterbell10/281/head

Conversation

@peterbell10
Copy link
Collaborator

@peterbell10 peterbell10 commented Feb 25, 2022

@pytorch-bot
Copy link

pytorch-bot bot commented Feb 25, 2022

CI Flow Status

⚛️ CI Flow

Ruleset - Version: v1
Ruleset - File: https://github.com/pytorch/pytorch/blob/992b3e5a2af5dfdb08baed867ce08543f39e7904/.github/generated-ciflow-ruleset.json
PR ciflow labels: ciflow/default
Add ciflow labels to this PR to trigger more builds:

Workflows Labels (bold enabled) Status
Triggered Workflows
linux-binary-conda ciflow/binaries, ciflow/binaries_conda, ciflow/default ✅ triggered
linux-binary-libtorch-cxx11-abi ciflow/binaries, ciflow/binaries_libtorch, ciflow/default ✅ triggered
linux-binary-libtorch-pre-cxx11 ciflow/binaries, ciflow/binaries_libtorch, ciflow/default ✅ triggered
linux-binary-manywheel ciflow/binaries, ciflow/binaries_wheel, ciflow/default ✅ triggered
linux-bionic-py3.7-clang9 ciflow/all, ciflow/cpu, ciflow/default, ciflow/linux, ciflow/noarch, ciflow/trunk ✅ triggered
linux-bionic-rocm4.5-py3.7 ciflow/all, ciflow/default, ciflow/linux, ciflow/rocm, ciflow/trunk ✅ triggered
linux-docs ciflow/all, ciflow/cpu, ciflow/default, ciflow/docs, ciflow/linux, ciflow/trunk ✅ triggered
linux-vulkan-bionic-py3.7-clang9 ciflow/all, ciflow/cpu, ciflow/default, ciflow/linux, ciflow/trunk, ciflow/vulkan ✅ triggered
linux-xenial-cuda11.3-py3.7-gcc7 ciflow/all, ciflow/cuda, ciflow/default, ciflow/linux, ciflow/trunk ✅ triggered
linux-xenial-cuda11.3-py3.7-gcc7-bazel-test ciflow/all, ciflow/bazel, ciflow/cpu, ciflow/default, ciflow/linux, ciflow/trunk ✅ triggered
linux-xenial-py3-clang5-mobile-build ciflow/all, ciflow/default, ciflow/linux, ciflow/mobile, ciflow/trunk ✅ triggered
linux-xenial-py3-clang5-mobile-custom-build-static ciflow/all, ciflow/default, ciflow/linux, ciflow/mobile, ciflow/trunk ✅ triggered
linux-xenial-py3.7-clang7-asan ciflow/all, ciflow/cpu, ciflow/default, ciflow/linux, ciflow/sanitizers, ciflow/trunk ✅ triggered
linux-xenial-py3.7-clang7-onnx ciflow/all, ciflow/cpu, ciflow/default, ciflow/linux, ciflow/onnx, ciflow/trunk ✅ triggered
linux-xenial-py3.7-gcc5.4 ciflow/all, ciflow/cpu, ciflow/default, ciflow/linux, ciflow/trunk ✅ triggered
linux-xenial-py3.7-gcc7 ciflow/all, ciflow/cpu, ciflow/default, ciflow/linux, ciflow/trunk ✅ triggered
linux-xenial-py3.7-gcc7-no-ops ciflow/all, ciflow/cpu, ciflow/default, ciflow/linux, ciflow/trunk ✅ triggered
macos-arm64-binary-conda ciflow/binaries, ciflow/binaries_conda, ciflow/default ✅ triggered
macos-arm64-binary-wheel ciflow/binaries, ciflow/binaries_wheel, ciflow/default ✅ triggered
macos-binary-conda ciflow/binaries, ciflow/binaries_conda, ciflow/default ✅ triggered
macos-binary-libtorch-cxx11-abi ciflow/binaries, ciflow/binaries_libtorch, ciflow/default ✅ triggered
macos-binary-libtorch-pre-cxx11 ciflow/binaries, ciflow/binaries_libtorch, ciflow/default ✅ triggered
macos-binary-wheel ciflow/binaries, ciflow/binaries_wheel, ciflow/default ✅ triggered
pytorch-linux-xenial-py3-clang5-android-ndk-r19c-gradle-custom-build-single ciflow/all, ciflow/android, ciflow/cpu, ciflow/default, ciflow/linux, ciflow/trunk ✅ triggered
pytorch-linux-xenial-py3-clang5-android-ndk-r19c-gradle-custom-build-single-full-jit ciflow/all, ciflow/android, ciflow/cpu, ciflow/default, ciflow/linux, ciflow/trunk ✅ triggered
win-vs2019-cpu-py3 ciflow/all, ciflow/cpu, ciflow/default, ciflow/trunk, ciflow/win ✅ triggered
win-vs2019-cuda11.3-py3 ciflow/all, ciflow/cuda, ciflow/default, ciflow/trunk, ciflow/win ✅ triggered
windows-binary-libtorch-cxx11-abi ciflow/binaries, ciflow/binaries_libtorch, ciflow/default ✅ triggered
windows-binary-libtorch-pre-cxx11 ciflow/binaries, ciflow/binaries_libtorch, ciflow/default ✅ triggered
windows-binary-wheel ciflow/binaries, ciflow/binaries_wheel, ciflow/default ✅ triggered
Skipped Workflows
caffe2-linux-xenial-py3.7-gcc5.4 ciflow/all, ciflow/cpu, ciflow/linux, ciflow/trunk 🚫 skipped
docker-builds ciflow/all, ciflow/trunk 🚫 skipped
ios-12-5-1-arm64 ciflow/all, ciflow/ios, ciflow/macos, ciflow/scheduled 🚫 skipped
ios-12-5-1-arm64-coreml ciflow/all, ciflow/ios, ciflow/macos, ciflow/scheduled 🚫 skipped
ios-12-5-1-arm64-custom-ops ciflow/all, ciflow/ios, ciflow/macos, ciflow/scheduled 🚫 skipped
ios-12-5-1-arm64-metal ciflow/all, ciflow/ios, ciflow/macos, ciflow/scheduled 🚫 skipped
ios-12-5-1-x86-64 ciflow/all, ciflow/ios, ciflow/macos, ciflow/trunk 🚫 skipped
ios-12-5-1-x86-64-coreml ciflow/all, ciflow/ios, ciflow/macos, ciflow/trunk 🚫 skipped
libtorch-linux-xenial-cuda10.2-py3.7-gcc7 ciflow/all, ciflow/cuda, ciflow/libtorch, ciflow/linux, ciflow/trunk 🚫 skipped
libtorch-linux-xenial-cuda11.3-py3.7-gcc7 ciflow/all, ciflow/cuda, ciflow/libtorch, ciflow/linux, ciflow/trunk 🚫 skipped
linux-bionic-cuda10.2-py3.9-gcc7 ciflow/all, ciflow/cuda, ciflow/linux, ciflow/slow, ciflow/trunk 🚫 skipped
linux-docs-push ciflow/all, ciflow/cpu, ciflow/linux, ciflow/scheduled 🚫 skipped
linux-xenial-cuda11.3-py3.7-gcc7-no-ops ciflow/all, ciflow/cuda, ciflow/linux, ciflow/trunk 🚫 skipped
macos-10-15-py3-arm64 ciflow/all, ciflow/macos, ciflow/trunk 🚫 skipped
macos-10-15-py3-lite-interpreter-x86-64 ciflow/all, ciflow/macos, ciflow/trunk 🚫 skipped
macos-11-py3-x86-64 ciflow/all, ciflow/macos, ciflow/trunk 🚫 skipped
parallelnative-linux-xenial-py3.7-gcc5.4 ciflow/all, ciflow/cpu, ciflow/linux, ciflow/trunk 🚫 skipped
periodic-libtorch-linux-bionic-cuda11.5-py3.7-gcc7 ciflow/all, ciflow/cuda, ciflow/libtorch, ciflow/linux, ciflow/scheduled 🚫 skipped
periodic-libtorch-linux-xenial-cuda11.1-py3.7-gcc7 ciflow/all, ciflow/cuda, ciflow/libtorch, ciflow/linux, ciflow/scheduled 🚫 skipped
periodic-linux-bionic-cuda11.5-py3.7-gcc7 ciflow/all, ciflow/cuda, ciflow/linux, ciflow/scheduled 🚫 skipped
periodic-linux-xenial-cuda10.2-py3-gcc7-slow-gradcheck ciflow/all, ciflow/cuda, ciflow/linux, ciflow/scheduled, ciflow/slow, ciflow/slow-gradcheck 🚫 skipped
periodic-linux-xenial-cuda11.1-py3.7-gcc7-debug ciflow/all, ciflow/cuda, ciflow/linux, ciflow/scheduled 🚫 skipped
periodic-win-vs2019-cuda11.1-py3 ciflow/all, ciflow/cuda, ciflow/scheduled, ciflow/win 🚫 skipped
periodic-win-vs2019-cuda11.5-py3 ciflow/all, ciflow/cuda, ciflow/scheduled, ciflow/win 🚫 skipped
pytorch-linux-xenial-py3-clang5-android-ndk-r19c-build ciflow/all, ciflow/android, ciflow/cpu, ciflow/linux, ciflow/trunk 🚫 skipped
pytorch-xla-linux-bionic-py3.7-clang8 ciflow/all, ciflow/cpu, ciflow/linux, ciflow/trunk, ciflow/xla 🚫 skipped

@facebook-github-bot
Copy link
Contributor

facebook-github-bot commented Feb 25, 2022

🔗 Helpful links

💊 CI failures summary and remediations

As of commit f2f924a (more details on the Dr. CI page):

Expand to see more

💚 💚 Looks good so far! There are no failures yet. 💚 💚


This comment was automatically generated by Dr. CI (expand for details).

Please report bugs/suggestions to the (internal) Dr. CI Users group.

Click here to manually regenerate this comment.

@facebook-github-bot facebook-github-bot added the oncall: jit Add this issue/PR to JIT oncall triage queue label Feb 25, 2022
peterbell10 added a commit that referenced this pull request Feb 25, 2022
peterbell10 added a commit that referenced this pull request Feb 26, 2022
peterbell10 added a commit that referenced this pull request Feb 28, 2022
peterbell10 added a commit that referenced this pull request Feb 28, 2022
@peterbell10 peterbell10 requested a review from mruberry March 1, 2022 12:51
…nter overload and python functional wrapper"

[ghstack-poisoned]
peterbell10 added a commit that referenced this pull request Mar 2, 2022
peterbell10 added a commit that referenced this pull request Mar 3, 2022
@zou3519
Copy link
Contributor

zou3519 commented May 3, 2022

@pytorchbot merge this please

@pytorchmergebot
Copy link
Collaborator

Merge failed due to Refusing to merge as mandatory check Lint failed for rule superuser
Raised by https://github.com/pytorch/pytorch/actions/runs/2261168663

peterbell10 added a commit that referenced this pull request May 3, 2022
@peterbell10
Copy link
Collaborator Author

@pytorchbot merge this

facebook-github-bot pushed a commit that referenced this pull request May 4, 2022
Summary:
Pull Request resolved: #73434

Approved by: https://github.com/anjali411

Test Plan: contbuild & OSS CI, see https://hud.pytorch.org/commit/pytorch/pytorch/d23ecbfc9ac157560611b242f015743f189dbf48

Reviewed By: malfet

Differential Revision: D36101857

Pulled By: malfet

fbshipit-source-id: 63ae429254479e0c60cf81388ee2302cb5ab72d7
@facebook-github-bot facebook-github-bot deleted the gh/peterbell10/281/head branch May 7, 2022 14:17
@malfet
Copy link
Contributor

malfet commented May 9, 2022

This PR seems to be causing slight forward-backward compatibility problems (by removing torch.functional.F symbol), that few other projects (Opacus for example) relied on, and also seem to have an incomplete model upgrader logic. But at the same time PR description as super succinct.

@peterbell10 can you please provide a more detailed description to your PRs especially if they introduce something that looks like backward incompatible changes.

@anjali411 please do not accept the PRs with one-line description that introduce non-trivial changes especially if they had to re-landed as introducing some regressions in other ecosystem projects. And if some backward incompatible changes are introduced, make sure that upgrade codepaths are thoroughly tested.

@peterbell10
Copy link
Collaborator Author

peterbell10 commented May 9, 2022

This PR seems to be causing slight forward-backward compatibility problems (by removing torch.functional.F symbol)

You mean someone is explicitly importing torch.functional.F instead of torch.nn.functional? Does that mean every import removal is considered a BC-break?

can you please provide a more detailed description to your PRs especially if they introduce something that looks like backward incompatible changes.

I thought the whole point of the JIT upgraders is that this isn't considered a BC break any more? Or do you mean the import?

@anjali411
Copy link
Contributor

Hey @malfet F should have never been exposed in torch.functional so this is also goes back to a bigger discussion of our public API policies. Internal failures were fixed by Natalia (see https://fb.workplace.com/groups/1405155842844877/posts/5840766845950399/?comment_id=5841992042494546&reply_comment_id=5842183229142094)

cc. @ngimel @albanD

@anjali411
Copy link
Contributor

You mean someone is explicitly importing torch.functional.F instead of torch.nn.functional? Does that mean every import removal is considered a BC-break?

Yeah. F was being exposed in torch.functional since we don't have an __all__ for torch.functional. So, yeah the import removals would be considered bc breaking if we remove something that we were (intentionally or unintentionally) exposing before.

@malfet
Copy link
Contributor

malfet commented May 9, 2022

Hi @anjali411 , there were few more internal projects that dependent on the change, so I have to push some updates as well.
But it looks like upgrader is not configured correctly, as running something as simple as:

$ python -c "import torch;import torchaudio; torch.jit.script(torchaudio.transforms.Spectrogram()).save('foo.pth')"

before the change and the loading the model after results in an error:

% python -c "import torch;print(torch.load('foo.pth'))"                                                            
/Users/nshulga/miniconda3/envs/py_39/lib/python3.9/site-packages/torch/serialization.py:707: UserWarning: 'torch.load' received a zip file that looks like a TorchScript archive dispatching to 'torch.jit.load' (call 'torch.jit.load' directly to silence this warning)
  warnings.warn("'torch.load' received a zip file that looks like a TorchScript archive"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/Users/nshulga/miniconda3/envs/py_39/lib/python3.9/site-packages/torch/serialization.py", line 711, in load
    return torch.jit.load(opened_file)
  File "/Users/nshulga/miniconda3/envs/py_39/lib/python3.9/site-packages/torch/jit/_serialization.py", line 164, in load
    cpp_module = torch._C.import_ir_module_from_buffer(
RuntimeError: 

aten::stft(Tensor self, int n_fft, int? hop_length=None, int? win_length=None, Tensor? window=None, bool center=True, str pad_mode="reflect", bool normalized=False, bool? onesided=None, bool? return_complex=None) -> (Tensor):
Expected a value of type 'str' for argument 'pad_mode' but instead found type 'Optional[bool]'.
:
  File "code/__torch__/torch/functional.py", line 21
  else:
    input0 = input
  _2 = torch.stft(input0, n_fft, hop_length, win_length, window, normalized, onesided, return_complex)
       ~~~~~~~~~~ <--- HERE
  return _2
'stft' is being compiled since it was called from 'spectrogram'
  File "/Users/nshulga/miniconda3/envs/py_3.7-torch-1.11/lib/python3.7/site-packages/torchaudio/functional/functional.py", line 102

    # default values are consistent with librosa.core.spectrum._spectrogram
    spec_f = torch.stft(
             ~~~~~~~~~~ <--- HERE
        input=waveform,
        n_fft=n_fft,
Serialized   File "code/__torch__/torchaudio/functional/functional.py", line 25
  shape = torch.size(waveform0)
  waveform2 = torch.reshape(waveform0, [-1, shape[-1]])
  spec_f = __torch__.torch.functional.stft(waveform2, n_fft, hop_length, win_length, window, center, pad_mode, False, onesided, True, )
  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ <--- HERE
  _1 = torch.add(torch.slice(shape, None, -1), torch.slice(torch.size(spec_f), -2))
  spec_f0 = torch.reshape(spec_f, _1)
'spectrogram' is being compiled since it was called from 'Spectrogram.forward'
Serialized   File "code/__torch__/torchaudio/transforms.py", line 18
  def forward(self: __torch__.torchaudio.transforms.Spectrogram,
    waveform: Tensor) -> Tensor:
    _0 = __torch__.torchaudio.functional.functional.spectrogram
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ <--- HERE
    window = self.window
    center = self.center

Which also affects internal pipeline, see https://fb.workplace.com/groups/4571909969591489/posts/5035659103216571/?comment_id=5036153876500427

@peterbell10
Copy link
Collaborator Author

Can someone revert?

@peterbell10
Copy link
Collaborator Author

@pytorchbot revert this please

@pytorch-bot
Copy link

pytorch-bot bot commented May 9, 2022

Revert unsuccessful: please retry the command explaining why the revert is necessary, e.g. @pytorchbot revert this as it breaks mac tests on trunk, see {url to logs}.

@peterbell10
Copy link
Collaborator Author

@pytorchbot revert this please as it breaks backward compatibility of torchaudio models

@pytorchmergebot
Copy link
Collaborator

Will not revert as @peterbell10 is not a MEMBER, but COLLABORATOR

@albanD
Copy link
Collaborator

albanD commented May 9, 2022

@pytorchbot revert this please as it breaks backward compatibility of torchaudio models

Doing this for Peter above who doesn't have the rights.

@vmoens
Copy link
Contributor

vmoens commented May 10, 2022

FYI This PR also seems to be BC breaking on some torch hub models

@peterbell10
Copy link
Collaborator Author

Can't reopen this PR, so have opened #77257. Will continue discussion there.

facebook-github-bot pushed a commit that referenced this pull request May 13, 2022
Summary:
This reverts commit d23ecbf.

Reverted #73434 on behalf of https://github.com/albanD

Test Plan: contbuild & OSS CI, see https://hud.pytorch.org/commit/pytorch/pytorch/2c5bf12584a8ec359cbce34fac73fb2bc3cd0af0

Reviewed By: malfet

Differential Revision: D36269304

fbshipit-source-id: f6382f5230890afd68eeb6623480d60cd4c24463
pytorchmergebot pushed a commit that referenced this pull request Feb 6, 2025
Skips advancing the fc window on #145437, since I just found that there were non-trivial efforts to do so a while ago that eventually was reverted: #73434

Works around the issue by keeping the stft sans center overload

Pull Request resolved: #146379
Approved by: https://github.com/justinchuby, https://github.com/iseeyuan
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla signed oncall: jit Add this issue/PR to JIT oncall triage queue open source Reverted topic: not user facing topic category

Projects

None yet

Development

Successfully merging this pull request may close these issues.