Closed Greenscreen23 closed 8 months ago
I was also told to ping @mthrok see here
I'm happy about any feedback / critique :)
Hi
The expected usage is to move the whole transform to the target device. Is there any reason you cannot do that?
This works.
device = torch.device('cuda')
mfcc = MFCC()
mfcc.to(device)
data = torch.rand([400, 400]).to(device)
print(mfcc(data))
Tested on Colab
Oops. I thought I tried that. You are completely right, thank you :)
🚀 The feature
The MFCC class should have a parameter for specifying a device for internally used tensors, so one can calculate a MFCC of a tensor that is not on the cpu.
Motivation, pitch
Trying to calculate a MFCC of a tensor that is not on the cpu fails because internally used tensors are on the cpu and operations (for example matrix multiplication) fail when tensors are on different devices. An example is:
To be able to compute the MFCC of a tensor that is on a gpu, one has to add these two lines after the creation of the mfcc object, which is not good, as one has to access torchaudio internals.
It would be great if this was possible without accessing the internals. I’d be happy to open a PR to fix this:
The way I would solve this issue in my PR would be to create a parameter
device
for theMFCC
class, a parametermel_scale_kwargs
for theMelSpectrogram
class and a parameterdevice
for theMelScale
class. Passing a device argument would transfer thedct_mat
to that device, and pass this device to the spectrogram window function (melkwargs
>wkwargs
>device
) and the mel scale (melkwargs
>mel_scale_kwargs
>device
), which transfer their respective tensors to the device.Alternatives
One could create a
to(device)
function for the different classes mentioned, which takes care of transferring all internal tensors to that device. This would allow moving the tensors multiple times, but would require a lot more code.Additional context
No response