Skip to content

Reduce HTDemucs inference overhead across backends - #790

Merged
0xShug0 merged 2 commits into
mainfrom
perf/htdemucs-cuda-pipeline
Oct 4, 2026
Merged

0xShug0 merged 2 commits into
mainfrom
perf/htdemucs-cuda-pipeline

Conversation

@0xShug0

@0xShug0 0xShug0 commented Oct 4, 2026 •

Copy link
Copy Markdown
Owner

Changes

  • Rewrite frequency transposed convolution using the existing ConvTranspose1dModule, with zero gaps keeping time frames independent. The framework selects the backend lowering.
  • Split time-branch GroupNorm reductions across channels.
  • Respect the session thread count in host OpenMP loops.

Both graph rewrites are enabled across backends, including Metal, without an opt-in flag. Only HTDemucs model files change; no framework, ggml, or server changes.

CUDA validation

Warm inference on the same 133-second stereo input, RTX 5090, eight CPU threads. C++ uses the Q8_0 package with default runtime storage; Python uses original weights with shifts=0 to match C++. No precision overrides.

Path Inference RTF
C++ before 2.407 s 0.01810
C++ after 1.059 s 0.00796
Official Python 1.089 s 0.00819

About 56% less C++ inference time. Timings exclude HTTP serialization/transfer; the original baseline was measured earlier, not in an interleaved A/B run.

All four stems retain their lengths and finite samples. First and warm request WAVs are byte-identical. Compared with old C++, waveform cosine is 0.9999987/0.9999997 for drums/other and 0.99826/0.99758 for near-silent bass/vocals. Floating-point drift remains; this is not bit-exact parity.

CPU and Vulkan validation

Separate eight-second case, Q8_0 package, eight CPU threads, one first request followed by one warm server request per configuration.

Backend Warm before Warm after
CPU 5.056 s 5.407 s
Vulkan (RTX 5090) 248 ms 148 ms

Both produce four finite, nonzero stems with the expected lengths and byte-identical first/warm outputs. Vulkan is about 40% faster; CPU is about 7% slower.

The old CPU 2D-transpose implementation ignores the batch dimension that HTDemucs uses for time frames. The rewrite avoids that unsupported usage. Against official Python on this case, CPU drums/other cosine improves from 0.683/0.924 to 0.999974/0.999998. Retaining the old convolution while changing only GroupNorm reproduces the old output. CPU timing therefore compares paths with different correctness, not equivalent output.

The near-silent bass/vocal stems also move closer to Python on CPU and Vulkan, but residual quantization/numerical differences remain. These are ordinary-settings output checks, not a universal parity guarantee.

Metal is enabled for both rewrites but untested. The six-stem model shares these paths but has not been measured or validated.

Fixes #785. No measured Metal speedup is claimed.

@0xShug0 0xShug0 changed the title Reduce HTDemucs CUDA inference overhead Reduce HTDemucs inference overhead across backends Oct 4, 2026
@0xShug0

0xShug0 commented Oct 4, 2026 •

Copy link
Copy Markdown
Owner Author

133s input

Runtime First inference Warm inference Warm RTF RMSE vs Python
C++ CUDA before PR 2.553 s 2.348 s 0.01766 0.00021527
C++ CUDA after PR 1.263 s 1.062 s 0.00798 0.00021601
C++ Vulkan before PR 3.391 s 3.239 s 0.02436 0.00181412
C++ Vulkan after PR 1.873 s 1.665 s 0.01252 0.00022085
Python CUDA 1.449 s 1.086 s 0.00816 0 (reference)
Runtime First inference Warm inference Warm RTF RMSE vs Python
C++ Metal before PR 69.51 s 69.87 s 0.525 0.00074578
C++ Metal after PR 19.96 s 19.91 s 0.150 0.00074559
Python MPS 10.30 s 9.81 s 0.074 0 (reference)

@0xShug0
0xShug0 merged commit 24b69c9 into main Oct 4, 2026
6 checks passed
@0xShug0
0xShug0 deleted the perf/htdemucs-cuda-pipeline branch October 4, 2026 21:25
@shakfu shakfu mentioned this pull request Oct 8, 2026
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.

HTDemucs on Metal is ~7× slower than PyTorch MPS (70 s for a 133 s track on M1 Max)

1 participant