Hybrid Transformer Demucs (htdemucs) music source separation (drums, bass, other, vocals) as nine ONNX graphs run in sequence. Prepared from StemSplitio/htdemucs-onnx (htdemucs_fp16weights.onnx) so the model fits comfortably in GPU memory, notably under DirectML.
The source export has about 25,000 nodes, most of them runtime shape arithmetic (Shape, Range, ScatterND, ...). Its intermediate tensors total about 16.5 GB per 7.8 s chunk. DirectML allocated close to that, so the model failed with E_OUTOFMEMORY on a 16 GB card.
mix pinned to [1, 2, 343980] (7.8 s, stereo, 44.1 kHz), as the model already requires.onnxconverter-common, with inputs and outputs kept fp32. InstanceNormalization, LayerNormalization, Softmax, ReduceMean and Erf stay fp32.Measured on one 7.8 s music chunk against the source model (fp32 activations):
| stem | SNR vs source |
|---|---|
| drums | 61.2 dB |
| bass | 63.1 dB |
| other | 58.1 dB |
| vocals | 62.4 dB |
On CPU, peak process memory fell from 6.45 GB to 3.88 GB at similar speed.
part0.onnx … part8.onnx: the graphs, 173 MB in total.parts.json: runs in order. Each entry lists file, inputs and outputs (tensor names). An entry's inputs are graph input mix or outputs of earlier parts.SHA256SUMSInput mix: float32 [1, 2, 343980]. Output of the last part: float32 [1, 4, 2, 343980], with stems in the order drums, bass, other, vocals. Longer audio is processed in overlapping chunks, as with the source model (its infer.py uses 25% overlap with a linear crossfade).
import json, onnxruntime as ort
parts = json.load(open("parts.json"))
env = {"mix": mix} # float32 [1, 2, 343980]
for p in parts:
s = ort.InferenceSession(p["file"], providers=["DmlExecutionProvider", "CPUExecutionProvider"])
env.update(zip(p["outputs"], s.run(p["outputs"], {k: env[k] for k in p["inputs"]})))
stems = env[parts[-1]["outputs"][0]]
To bound GPU memory across a whole song, load one part at a time: run every chunk through it, release it, then load the next.
MIT, as the source export. HTDemucs by Alexandre Défossez, Simon Rouard et al. (facebookresearch/demucs, MIT). ONNX export by StemSplitio.
part0.onnx 45 MBpart8.onnx 34 MBpart4.onnx 30 MBpart6.onnx 20 MBpart1.onnx 18 MBpart3.onnx 16 MBpart2.onnx 8 MBpart5.onnx 2 MBpart7.onnx 552.1 kBStemSplitio/htdemucs-onnx