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)

Most upvoted comments

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 soundfile fixes it, and autodetects the format for me. On any version >2.0

it seems adding --mp3 fixes the error and allows me to separate both flac and mp3. But this isn’t listed as a required argument to the tool

PyTorch changed the method to handle backends in 2.1.0, please try downgrading to 2.0.1

installing soundfile fixes it, and autodetects the format for me. On any version >2.0

This should work on Windows, but not macOS and Linux unless your PyTorch version is greater or equal to 2.2.0

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=0 if 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 :

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

β€” Reply to this email directly, view it on GitHub https://github.com/facebookresearch/demucs/issues/570#issuecomment-1879775447, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACY4R6AV76QPCQTDIEQHAGTYNGJKTAVCNFSM6AAAAAA7KDGG62VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQNZZG43TKNBUG4 . You are receiving this because you commented.Message ID: @.***>

Writing mp3 uses other libraries instead of torchaudio