Migrate inverse short-time Fourier transform from torchaudio#34827
Migrate inverse short-time Fourier transform from torchaudio#34827mthrok wants to merge 2 commits intopytorch:masterfrom
Conversation
💊 CircleCI build failures summary and remediationsAs of commit 45a146f (more details on the Dr. CI page): ✅ None of the build failures appear to be your fault 💚
🚧 1 upstream failure:These were probably caused by upstream breakages:
This comment was automatically generated by Dr. CI (expand for details).Follow this link to opt-out of these comments for your Pull Requests.Please report bugs/suggestions on the GitHub issue tracker. This comment has been revised 95 times. |
facebook-github-bot
left a comment
There was a problem hiding this comment.
@vincentqb has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
50d40af to
e9d8538
Compare
facebook-github-bot
left a comment
There was a problem hiding this comment.
@vincentqb has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
0d4e25d to
678b2f7
Compare
|
I am confused about jit-ability of import torch
import torchaudio.functional
# Toggle this to change the behavior.
istft = torch.istft
# istft = torchaudio.functional.istft
stft_kwargs = {
'n_fft': 15,
'hop_length': 3,
'win_length': 11,
'window': torch.hamming_window(11),
'center': True,
'pad_mode': 'constant',
'normalized': True,
'onesided': False,
}
istft_kwargs = stft_kwargs.copy()
istft_kwargs['length'] = None
input = torch.stft(torch.randn(3, 15), **stft_kwargs)
def nested_istft(
stft_matrix, n_fft, hop_length, win_length, window, center, pad_mode, normalized, onesided, length):
# type: (Tensor, int, Optional[int], Optional[int], Optional[Tensor], bool, str, bool, bool, Optional[int]) -> Tensor
return istft(stft_matrix, n_fft, hop_length, win_length, window, center, pad_mode, normalized, onesided, length)
def test_func(istft_func):
jit_istft = torch.jit.script(istft_func)
py_result = istft_func(input, **istft_kwargs)
jit_result = jit_istft(input, **istft_kwargs)
assert torch.allclose(py_result, jit_result, atol=1e-6)
print('checking bare istft')
test_func(istft)
print('checking nested istft')
test_func(nested_istft)
print('ok')When but when |
|
@mthrok could you follow the example in #33737 ? Since the inputs all have one single type it shouldn't be very hard to make this torchscriptable. Just add basically we generally resolve |
|
Thanks @eellison for the suggestion. The trick did solve the issue above. I applied that to PR, but now some tests are failing due to something related to ATen, which were not happening earlier. |
2aae9df to
1ba32bb
Compare
Summary: Ported `torchaudio`'s implementation (test, and documentation as well) to ATen. Note - Batch packing/unpacking is performed in Python. ATen implementation expects 4D input tensor. - The way `hop_length` is initialized in the same way as `stft` implementation. [The Torchaudio's version tried to mimic the same behavior but slightly different](https://github.com/pytorch/audio/blob/7da61a4beeec7b7ff9ff5f1532b2adf99220a9b1/torchaudio/functional.py#L152-L157). Closes pytorch#34827 Relates pytorch#3775 Pull Request resolved: pytorch#35569 Differential Revision: D21178090 Pulled By: mthrok fbshipit-source-id: 2701a8b241a36a6fb1b740c2fb2b07cb938185d4
As suggested in #3775, this PR migrates Python code to perform ISTFT from torchaudio to PyTorch.
zerosandones)