Skip to content

stft does not consistently check window device #30865

@seungwonpark

Description

@seungwonpark

🐛 Bug

Consider a situation when applying torch.stft to audio x, which is in CUDA memory. We also have a given tensor window, which is not in CUDA memory yet.
When n_fft is equal to win_length, it causes RuntimeError: expected device cuda:0 but got device cpu.

To Reproduce

See my Google Colab notebook:
https://colab.research.google.com/drive/15ZOc5SnFwXsb3-vgIbzdd2roeY6kOV2H

import torch
import librosa

print(torch.__version__) # 1.3.1
print(librosa.__version__) # 0.6.3

x, sr = librosa.load(librosa.util.example_audio_file(), offset=15.0, duration=5.0)
print(x.shape) # (110250,)
x = torch.from_numpy(x).cuda()
window = torch.hann_window(window_length=400)

torch.stft(x, n_fft=512, hop_length=160, win_length=400, window=window).shape # torch.Size([257, 690, 2])

torch.stft(x, n_fft=400, hop_length=160, win_length=400, window=window).shape # RuntimeError: expected device cuda:0 but got device cpu

Expected behavior

No error is expected here.

cc @mruberry @peterbell10

Metadata

Metadata

Assignees

Labels

module: error checkingBugs related to incorrect/lacking error checkingmodule: ffttriagedThis issue has been looked at a team member, and triaged and prioritized into an appropriate module

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions