我如何 emulate/run PyTorch 模型在基于 arm 的 cpu 上使用 ATen STFT 实现?

How can I emulate/run PyTorch model that uses ATen STFT implementation on arm based cpu?

我正在尝试 运行 我的 ASR PyTorch 模型在没有 GPU 的基于手臂的设备上。据我所知,arm不支持​​ATen使用的MKL。自然地,当我尝试进行推理时出现以下错误:

RuntimeError: fft: ATen not compiled with MKL support

我该如何解决这个问题?有没有我可以使用的替代品?

如果您的目标设备是移动设备,首先尝试使用 Pytorch Mobile 将其转换为 TorchScript 是合理的。 TorchScript 是 PyTorch 模型的中间表示,然后可以 运行 在移动环境中。 https://pytorch.org/mobile/home/

我通过绕过 PyTorch 的 stft 实现解决了这个问题。这可能对每个人都不可行,但就我而言,它允许我使用我的模型进行预测,而在 arm 设备上没有任何问题。

问题源于 _VF.stft 调用 packages/torch/functional.py.

我改线了

return _VF.stft(input, n_fft, hop_length, win_length, window, normalized, onesided, return_complex) 

与:

librosa_stft = librosa.stft(input.cpu().detach().numpy().reshape(-1), n_fft, hop_length, win_length, window="hann", center=True, pad_mode=pad_mode)
librosa_stft = np.array([[a.real, a.imag] for a in librosa_stft])
librosa_stft = np.transpose(librosa_stft, axes=[0, 2, 1])
librosa_stft = np.expand_dims(librosa_stft, 0)
librosa_stft = torch.from_numpy(librosa_stft)
return librosa_stft

此代码可能会进一步优化。我只是试图通过使用 Librosa 来复制 PyTorch 所做的事情。就我而言,两个版本的结果输出相同。但是你应该检查你的输出以确定你是否决定使用这个方法。