elixir-nx / nx_signal Goto Github PK
View Code? Open in Web Editor NEWDSP with Elixir Nx
License: Other
DSP with Elixir Nx
License: Other
I've noticed the speed of NxSignal.stft
is much slower than in PyTorch (on the order of ~500x). Is this expected? I'm using Exla.Backend
, but I feel like I'm missing something. In my tests I see a STFT of zeros with length 480000 taking ~3ms in PyTorch and ~1.5 seconds (after the initial jit compilation) in NxSignal
:
import time
import torch
class STFT(torch.nn.Module):
def __init__(self):
super().__init__()
self.fft_length = 400
self.hop_length = 160
self.window = torch.nn.Parameter(
torch.hann_window(self.fft_length, periodic=True), requires_grad=False
)
def forward(self, sample):
stft = torch.stft(
sample,
self.fft_length,
self.hop_length,
window=self.window,
return_complex=True,
)
return stft
if __name__ == "__main__":
s = STFT().eval()
i = torch.zeros([480000])
start = time.time()
result = s(i)
print(f"took {(time.time() - start)*1000000}us")
This returns ~ 3000us
And (what I think is) the corresponding Elixir
defmodule StftTest do
import Nx.Defn
defn test(sample) do
fft_length = 400
sample_rate = 16000
hop_length = 160
window = NxSignal.Windows.hann(n: fft_length, is_periodic: true)
{stft, _, _} =
NxSignal.stft(sample, window,
sampling_rate: sample_rate,
fft_length: fft_length,
overlap_length: fft_length - hop_length,
window_padding: :reflect
)
stft
end
def test_jit() do
sample = Nx.broadcast(0.0, {480_000})
{time, _} = :timer.tc(fn -> Nx.Defn.jit(&test/1, compiler: EXLA).(sample) end)
IO.puts("STFT took #{time}us")
end
end
This returns 1596447us after the initial run.
The main goal of this library is to mirror the functionality provided by scipy.signal. However, some of those overlap with Scholar.
With that in mind, we still have the following sections to implement:
The previous version would just perform ifft for each frame. We actually want to apply the inversion with overlap_and_add.
20ee79b has the previous code still.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.