-
Notifications
You must be signed in to change notification settings - Fork 145
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added parallel STFT implementation #113
Added parallel STFT implementation #113
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot for this work. This is a pretty strong PR and all the logics seem making sense to me.
I left some comments but all are easy fixes.
Agreed that using cpu_count() is better than defaulting to 10. What I meant was to let user control the number of process optionally.
… On Nov 26, 2020, at 23:56, J. Pery ***@***.***> wrote:
@JPery commented on this pull request.
In kapre/backend.py:
> @@ -248,3 +252,35 @@ def mu_law_decoding(signal_mu, quantization_channels):
tf.math.sign(signal) * (tf.math.exp(tf.math.abs(signal) * tf.math.log1p(mu)) - 1.0) / mu
)
return signal
+
+
+def parallel_stft(signals, frame_length, frame_step, fft_length=None, window_fn=window_ops.hann_window,
How about adding n_cpu=None in the function signature and it defaults to be multiprocessing.cpu_count()?
The tf.map_fn docs say that the default value is 10. I think it's a better approach to use the available cpu number instead.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub, or unsubscribe.
|
@JPery Thanks a lot again! I'm merging it to a temporary branch and will ultimately merge it to the next release. |
Hi, I have been testing Kapre's STFT layer against the spectrogram computation methods we have implemented in Ketos which are based on numpy's rfft and tile functions. On CPU, I observe the same behaviour as noted previously by @JPery : Kapre is significantly slower than the numpy-based implementation, taking about 30 times longer to compute spectrograms. (For reference, I'm working on a Intel(R) Core(TM) i5-10210U CPU @ 1.60GHz.) I have tried switching to the parallel_stft branch and setting Note: When I run my script with
Could this be the reason why I am not seeing any improvement? Thanks, |
Hi, @oliskir, Can you try to disable TF eager execution to see if there is any difference? |
Thanks for the suggestion @JPery . Disabling eager execution did the trick: audio duration: 3.0 s eager execution enabled:WARNING:tensorflow:Setting parallel_iterations > 1 has no effect when executing eagerly. Consider calling map_fn with tf.function to execute fn in parallel.
eager execution disabled:
|
I understand that parallel_stft feature will eventually be merged into the master branch of Kapre? |
Hi, @oliskir. This is an issue at tensorflow's level. I don't know if they're working on it but it's a reported issue, which I mentioned here. I don't know what @keunwoochoi wants to do, but, imho, we should wait until this issue is fixed in tensorflow. This is why the parallel implementation is offered in different branch. |
Hi!
As I comented in #98, I added a parallel STFT implementation based on the map_fn function following the indications of @zaccharieramzi here.
I've added a
use_parallel_stft
param (disabled by default) that allows to use this function. I've put this param in as many functions as I can. I also added test cases for every function I can, including an specific test that checks that the result of thetf.signal.stft
is equals to the result of theparallel_stft
function.Hope this could serve us well meanwhile tensorflow resolves its issues with the fft implementation.