Views
No views yet
.mlpackage you can drop into a macOS or iOS app and run with MLModel.convert.py, ~600 LoC) that solves the three blockers you hit otherwise:complex64 → real-valued STFT/ISTFT.coremltools can't trace nn.MultiheadAttention → manual decomposition.scatter_add is fragile → pre-computed OLA index buffer..mlpackage that takes raw stereo audio and outputs four stems (vocals, drums, bass, other) at 44.1 kHz.[vocals, drums, bass, other] (DJ/UI convention).1git clone https://github.com/dexxdean/htdemucs-coreml
2cd htdemucs-coreml
3python3 -m venv venv && source venv/bin/activate
4pip install -r requirements.txt
5
6# default: 10 s segments, FP32, ~400 MB
7python convert.py
8
9# half size, ~200 MB, slight numerical drift but inaudible in practice
10python convert.py --fp16
11
12# shorter segments if you want lower latency / smaller buffers
13python convert.py --segment 7HTDemucs_CoreML.mlpackage (or HTDemucs_CoreML_FP16.mlpackage).1import CoreML
2import AVFoundation
3
4// 1. Load the model.
5let url = Bundle.main.url(forResource: "HTDemucs_CoreML", withExtension: "mlpackage")!
6let config = MLModelConfiguration()
7config.computeUnits = .cpuAndGPU // see "Compute units" below
8let model = try MLModel(contentsOf: url, configuration: config)
9
10// 2. Feed a (1, 2, 441000) Float32 MLMultiArray named "audio".
11// Output is a (1, 4, 2, 441000) Float32 array named "sources",
12// in the order [vocals, drums, bass, other].AVAudioEngine playback is in examples/swift/StemSeparator.swift.| Input name | audio |
| Input shape | (1, 2, segment_samples) Float32 |
| Output name | sources |
| Output shape | (1, 4, 2, segment_samples) Float32 |
| Output order | vocals, drums, bass, other |
| Sample rate | 44 100 Hz, stereo |
| Default segment | 441 000 samples (10 s) |
| Min. deployment | macOS 14 / iOS 17 |
.cpuAndGPU (the default baked into the model). Forcing .all or .cpuAndNeuralEngine may produce silent garbage on some shapes — the validation step in convert.py will warn if numerical drift is large.| Variant | Size | Notes |
|---|---|---|
| FP32, 10 s | ~400 MB | Default, full reference quality. |
| FP16, 10 s | ~200 MB | Inaudible quality difference for music separation. |
| FP32, 7.8 s | ~310 MB | Closer to john-rocky's segment length. |
CONVERSION_NOTES.md for the technical deep-dive on the three workarounds (real STFT, manual MHA, OLA scatter).LICENSE.demucs Python package at conversion time from Meta's official release. You must comply with Demucs' MIT license when redistributing the resulting .mlpackage — keep the attribution in ATTRIBUTION.md alongside the model and in your app's about/legal screen.HTDemucs_CoreML.mlpackage was chosen to avoid any confusion with Apple-internal model names (e.g., MusicSourceSeparation).1@inproceedings{rouard2023hybrid,
2 title={Hybrid Transformers for Music Source Separation},
3 author={Rouard, Simon and Massa, Francisco and D{\'e}fossez, Alexandre},
4 booktitle={ICASSP 2023},
5 year={2023}
6}