Skip to content

[blog] Add Demucs ONNX export blog - #410

Merged
JoergAtGithub merged 1 commit into
mixxxdj:websitefrom
dhunstack:demucsblog
Oct 27, 2025
Merged

[blog] Add Demucs ONNX export blog#410
JoergAtGithub merged 1 commit into
mixxxdj:websitefrom
dhunstack:demucsblog

Conversation

@dhunstack

@dhunstack dhunstack commented Oct 23, 2025

Copy link
Copy Markdown
Contributor

Blog documenting the "Converting Demucs v4 (Hybrid Transformer) AI model to ONNX format" GSOC project.

preview

@JoergAtGithub

Copy link
Copy Markdown
Member

Please fix the pre-commit issues first (additional space at line end and missing new line at file end)

Comment thread content/news/XXXX-XX-XX-gsoc2025-demucs-to-onnx-dhunstack.md
Comment thread content/news/XXXX-XX-XX-gsoc2025-demucs-to-onnx-dhunstack.md Outdated
Comment thread content/news/XXXX-XX-XX-gsoc2025-demucs-to-onnx-dhunstack.md Outdated
Comment thread content/news/XXXX-XX-XX-gsoc2025-demucs-to-onnx-dhunstack.md
@dhunstack
dhunstack force-pushed the demucsblog branch 12 times, most recently from 23311ce to 20f3274 Compare October 24, 2025 11:58
Comment thread content/news/XXXX-XX-XX-gsoc2025-demucs-to-onnx-dhunstack.md Outdated

@daschuer daschuer left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow, this is really impressive. Thank you.
I have left some comments to make it more accessible for people not that deep into the AI topic.

Comment thread content/news/XXXX-XX-XX-gsoc2025-demucs-to-onnx-dhunstack.md Outdated
Comment thread content/news/XXXX-XX-XX-gsoc2025-demucs-to-onnx-dhunstack.md Outdated
Comment thread content/news/XXXX-XX-XX-gsoc2025-demucs-to-onnx-dhunstack.md Outdated
Comment thread content/news/XXXX-XX-XX-gsoc2025-demucs-to-onnx-dhunstack.md Outdated
Comment thread content/news/XXXX-XX-XX-gsoc2025-demucs-to-onnx-dhunstack.md Outdated
- Operates directly on the raw waveform (real-valued input).
- Uses temporal convolutions and Transformer blocks to learn how each instrument evolves over time.

##### **Time-Frequency Domain Branch**

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am missing a paragraph like this (my rookie understanding)

The FFT is used to demangle the row of samples to the original bits of sound. Micro oscillations (sinusoid) like emitted of a certain bras sheet of a trumpet. The sum of these sinusoids can be converted back to the streams of sound samples.

The Demux model takes all these resinoids and compares it to the training data and decide which of them belongs to which instrument. This way it can create one stream for each instrument.

@dhunstack dhunstack Oct 25, 2025

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this blog, I've tried to not talk much about the internal DL architecture, instead focusing only on the export related issues with Demucs. A discussion on the mechanisms of Demucs's layers might be too complex (and too much information) for this blog.
I've referred to convolution and Transformer layers, whose internal mechanisms are well described mathematically but the math doesn't have an easy interpretation. Hence why the AI models are referred to as black boxes.
I can link to the actual research paper though, if you suggest that'd be helpful - https://arxiv.org/pdf/2211.08553

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your new version reads already good. Thank you.


#### Real-Valued STFT and ISTFT Rewrites

Because complex values appear **only** in the initial STFT and final ISTFT layers, our solution was to **reimplement these operations** in a real-valued form.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does not sound correct. Isn't the sine/coin notation just a different notation of the same complex value?

@JoergAtGithub JoergAtGithub Oct 24, 2025

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is correct and uses the common mathematical terms. You could use the polar representation (magnitude and phase) instead of real-value + imaginary value. But to explain this work the later fits better.
sine/cosine are operations - not a representation.
Maybe a simple drawing like https://en.wikipedia.org/wiki/Complex_number#/media/File:Complex_number_illustration_modarg.svg would help the reader to understand the difference between magnitude, amplitude and phase?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't struggling to understand the complex number itself.

For my understanding the sentences is misleading, because the complex-valued nature of the operation must still exists conceptually. It looks like the rewritten STFT avoids using complex tensors, by using a sinus and a cosinus temsor pair that is representing the same info.

z=a+bi=reiθ=r(cosθ+isinθ)

Is that understanding correct?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. Yeah the underlying math is same, but the implementation performs the operations separately for real part and imaginary part, so avoiding any complex tensor data type.
Would you think this statement might be a better fit?
Because complex tensors appear **only** in the initial STFT and final ISTFT layers, our solution was to **reimplement these operations** using only real tensors.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your explanation is very good, thank you. Unfortunately it is not integrated in the proposal. Here a try:

Suggested change
Because complex values appear **only** in the initial STFT and final ISTFT layers, our solution was to **reimplement these operations** in a real-valued form.
Because complex tensors appear **only** in the initial STFT and final ISTFT layers, our solution was to **reimplement these operations** using separate real tensors for the real and the imagine part of the original complex values, while keeping the underlying math unchanged.

- The original ISTFT combines complex values through real + imaginary synthesis.
- We reconstructed the time-domain signal by performing the same series of **overlap-add** and **cosine/sine inverse convolutions**, again using only real-valued tensors.

By carefully ensuring numerical equivalence to PyTorch’s implementation, we achieved perfect parity (MSE < 1e-4) between the original and rewritten layers.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice :-)


## Benchmark Results

The quality of the model is expected to be equal or slightly worse when exported to ONNX. While there are plenty of ways of measuring the benchmarks models (another blog post incoming), we've chosen to measure our models with `SI-SDR` metric, Scale Invariant Signal To Distortion Ratio, on the MusDB dataset. This is the standard metric on which researchers report their source separation model's performance.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add other sentence with example db values? What would be perfect what is expected?

@JoergAtGithub JoergAtGithub Oct 24, 2025

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The numerical values for Demucs are in the table below. I don't think additional numbers will improve the text here.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I struggle to understand which value is better. Is 0 dB the optimum?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@daschuer
I can probably add a line here that higher dB values are better.
This page is a great way to get familiarized with the SI-SDR metric - https://source-separation.github.io/tutorial/basics/evaluation.html
This is a table for SDR evaluation of Demucs compared to other models - https://github.com/facebookresearch/demucs?tab=readme-ov-file#comparison-of-accuracy

The evaluation of source separated tracks is an important topic in itself. The above URL I've mentioned talks about evaluation of ML models, but doesn't discuss the topic of quality assessment for exported models, which has multiple potential sources of quality degradation. Which is why I've added the comment for (another blog post incoming) in the text.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That works for me. Thank you.

Interesting links. You may add another sentence summarisimg your good explanations here.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Idea: for the subject part you may add two files for compassion python vs. c++.

math: yes
comments: yes

Disclaimer: *This blog post primarily serves as the documentation for the [Google Summer of Code](https://summerofcode.withgoogle.com/programs/2025/projects/lRQpeA7K) 2025 project: "Converting Demucs v4 (Hybrid Transformer) AI model to ONNX format".*

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be great to have an eye catching vision statement at the very beginning. Something like:

Imagine you could load a track and .....

@daschuer

Copy link
Copy Markdown
Member

This type of AI has nothing to do with Chat-GPT. I can imagine that people do not know this. So maybe you may ad short paragraph about pattern recognition. And a brief compare about language models and Audio models.

Comment thread content/news/XXXX-XX-XX-gsoc2025-demucs-to-onnx-dhunstack.md Outdated
Comment thread content/news/XXXX-XX-XX-gsoc2025-demucs-to-onnx-dhunstack.md Outdated
@Eve00000

Copy link
Copy Markdown
Contributor

impressive! thank you.

@ywwg

ywwg commented Oct 24, 2025

Copy link
Copy Markdown
Member

This project is amazing. This is real, groundbreaking work being done in Mixxx! I love that most of it is merged already, too :)

Comment thread content/news/XXXX-XX-XX-gsoc2025-demucs-to-onnx-dhunstack.md Outdated
@dhunstack

Copy link
Copy Markdown
Contributor Author

@daschuer @JoergAtGithub I've edited in your suggestions in the blog

@Eve00000

Copy link
Copy Markdown
Contributor

@dhunstack, I hope you understand that it will take me some time to really understand what & how you did it.
I,m very curious and keen to test out your work but I’m already convinced our users will love what you created.

@dhunstack
dhunstack force-pushed the demucsblog branch 2 times, most recently from 5ea291f to b3acee2 Compare October 26, 2025 02:41

@acolombier acolombier left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is looking already very good! Just a small nit, but otherwise I think this is ready to go!

Comment thread content/news/XXXX-XX-XX-gsoc2025-demucs-to-onnx-dhunstack.md Outdated

@daschuer daschuer left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am really exited about your project after reading this Blog. Thank you. LGTM.

@daschuer

Copy link
Copy Markdown
Member

@acolombier Can you take care for merging? @dhunstack needs a stable link for his submission before the deadline, tomorrow October 27, 2025 8 PM CET.

Comment thread content/news/XXXX-XX-XX-gsoc2025-demucs-to-onnx-dhunstack.md Outdated
@dhunstack
dhunstack force-pushed the demucsblog branch 2 times, most recently from 2f9d09c to 2b3af21 Compare October 26, 2025 19:55
Comment thread content/news/XXXX-XX-XX-gsoc2025-demucs-to-onnx-dhunstack.md Outdated
Comment thread content/news/XXXX-XX-XX-gsoc2025-demucs-to-onnx-dhunstack.md Outdated
Comment thread content/news/XXXX-XX-XX-gsoc2025-demucs-to-onnx-dhunstack.md Outdated
@dhunstack
dhunstack force-pushed the demucsblog branch 4 times, most recently from 70daf44 to 081f098 Compare October 27, 2025 06:36
Blog documenting the "Converting Demucs v4 (Hybrid Transformer) AI model
to ONNX format" GSOC project.

Signed-off-by: Anmol Mishra <anmolmishra1997@gmail.com>
@JoergAtGithub

Copy link
Copy Markdown
Member

Thank you very much for this great contribution! It was a pleasure to work with you on this GSoC project!

@JoergAtGithub
JoergAtGithub merged commit c7055b0 into mixxxdj:website Oct 27, 2025
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants