demucs: RuntimeError: Couldn't find appropriate backend to handle uri
π Bug Report
Running demucs on my M1 Max Macbook Pro i get an error:
β― python3 -m demucs -d mps --two-stems=vocals ~/Desktop/03\ -\ 3OH\!3\ -\ Dont\ Trust\ Me.mp3
Important: the default model was recently changed to `htdemucs` the latest Hybrid Transformer Demucs model. In some cases, this model can actually perform worse than previous models. To get back the old default model use `-n mdx_extra_q`.
Selected model is a bag of 1 models. You will see that many progress bars per track.
Separated tracks will be stored in /Users/silman/repo/karaoke-gen/separated/htdemucs
Separating track /Users/silman/Desktop/03 - 3OH!3 - Dont Trust Me.mp3
100%|ββββββββββββββββββββββββββββββββββββββββββββββ| 193.04999999999998/193.04999999999998 [00:09<00:00, 19.45seconds/s]
Traceback (most recent call last):
File "<frozen runpy>", line 198, in _run_module_as_main
File "<frozen runpy>", line 88, in _run_code
File "/Users/silman/.local/lib/python3.11/site-packages/demucs/__main__.py", line 10, in <module>
main()
File "/Users/silman/.local/lib/python3.11/site-packages/demucs/separate.py", line 206, in main
save_audio(sources.pop(model.sources.index(args.stem)), str(stem), **kwargs)
File "/Users/silman/.local/lib/python3.11/site-packages/demucs/audio.py", line 260, in save_audio
ta.save(str(path), wav, sample_rate=samplerate,
File "/Users/silman/.local/lib/python3.11/site-packages/torchaudio/_backend/utils.py", line 287, in save
backend = dispatcher(uri, format, backend)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/silman/.local/lib/python3.11/site-packages/torchaudio/_backend/utils.py", line 220, in dispatcher
raise RuntimeError(f"Couldn't find appropriate backend to handle uri {uri} and format {format}.")
RuntimeError: Couldn't find appropriate backend to handle uri separated/htdemucs/03 - 3OH!3 - Dont Trust Me/vocals.wav and format None.
this happens even if i use -d cpu or change the stems choice, the same error happens with .flac files as well
Your Environment
M1 Max Macbook Pro with 64 GB RAM, 24 Core GPU on MacOS Ventura 13.6
β― python -V
Python 3.11.5
torch 2.1.0
torchaudio 2.1.0
β― which ffmpeg
/opt/homebrew/bin/ffmpeg
β― ffmpeg -version
ffmpeg version 6.0 Copyright (c) 2000-2023 the FFmpeg developers
built with Apple clang version 14.0.3 (clang-1403.0.22.14.1)
configuration: --prefix=/opt/homebrew/Cellar/ffmpeg/6.0_1 --enable-shared --enable-pthreads --enable-version3 --cc=clang --host-cflags= --host-ldflags= --enable-ffplay --enable-gnutls --enable-gpl --enable-libaom --enable-libaribb24 --enable-libbluray --enable-libdav1d --enable-libjxl --enable-libmp3lame --enable-libopus --enable-librav1e --enable-librist --enable-librubberband --enable-libsnappy --enable-libsrt --enable-libsvtav1 --enable-libtesseract --enable-libtheora --enable-libvidstab --enable-libvmaf --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libxvid --enable-lzma --enable-libfontconfig --enable-libfreetype --enable-frei0r --enable-libass --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libspeex --enable-libsoxr --enable-libzmq --enable-libzimg --disable-libjack --disable-indev=jack --enable-videotoolbox --enable-audiotoolbox --enable-neon
β― which sox
/opt/homebrew/bin/sox
β― sox --version
sox: SoX v
About this issue
- Original URL
- State: open
- Created 8 months ago
- Reactions: 3
- Comments: 16 (6 by maintainers)
I had this problem (under MacOS with PyTorch 2.1); ran this command to downgrade torchaudio and PyTorch which fixed it for me - now I can output to wav files:
python3 -m pip install torchaudio==2.0.1 -f https://download.pytorch.org/whl/torch_stable.html
installing
soundfilefixes it, and autodetects the format for me. On any version >2.0it seems adding
--mp3fixes the error and allows me to separate both flac and mp3. But this isnβt listed as a required argument to the toolPyTorch changed the method to handle backends in 2.1.0, please try downgrading to 2.0.1
I actually tried it on Ubuntu 23.10. Might have messed up my PyTorch versions, between my different environments if you say so.
But I think this should be the preferred solution either way, for anyone experiencing the issue. As it doesnβt require neither downgrading or modifying the application code
Added on Feb. 6, 2024: You can also fix this by setting the environment variable
TORCHAUDIO_USE_BACKEND_DISPATCHER=0if you are using 2.1.x (2.2 and above canβt be solved using this)This works.Thanks soooo much
Thanks a lot
Le sam. 6 janv. 2024, 19:25, MrSimmo @.***> a Γ©crit :
Writing mp3 uses other libraries instead of torchaudio