facebookresearch / demucs

Code for the paper Hybrid Spectrogram and Waveform Source Separation
MIT License
8.18k stars 1.03k forks source link

RuntimeError: Couldn't find appropriate backend to handle uri #570

Open TaakoMagnusen opened 10 months ago

TaakoMagnusen commented 10 months ago

πŸ› 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
TaakoMagnusen commented 10 months ago

ffmpeg was install via brew like brew install ffmpeg and is available in the path, so unsure what's going on

CarlGao4 commented 10 months ago

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

TaakoMagnusen commented 10 months ago

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

CarlGao4 commented 10 months ago

Writing mp3 uses other libraries instead of torchaudio

diealone commented 10 months ago

Hello how can fixed that bug to be able to use torch and separate the tracks in wav format ? Any ideas thanks a lot everybody.

CarlGao4 commented 10 months ago

You can downgrade pytorch to 2.0.1, which uses the legacy backend handler

MrSimmo commented 8 months ago

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

diealone commented 8 months ago

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: @.***>

samuelHaruka commented 7 months ago

This works.Thanks soooo much

CarlGao4 commented 7 months ago

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)

bastien8060 commented 7 months ago

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

CarlGao4 commented 7 months ago

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

bastien8060 commented 7 months ago

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

Shivansh1980 commented 6 months ago

on windows: pip install torch==2.0.1 is not working. It is giving this error:

ERROR: Could not find a version that satisfies the requirement torch==2.0.1 (from versions: 2.2.0, 2.2.1)
ERROR: No matching distribution found for torch==2.0.1

Tried for both torchaudio and torch and even though i have installed soundfile and sox using pip but its still showing no backend available. ffmpeg i have installed through choco and added it to the path but its not able to locate any backend.

ValueError: ("Unsupported backend 'ffmpeg' specified; ", 'please select one of [] instead.')

CarlGao4 commented 6 months ago

You need to install torch following the instructions on https://pytorch.org/get-started/previous-versions/#v201

Amahseyn commented 6 months ago

pip uninstall PySoundFile && pip install PySoundFile

tgrushka commented 4 months ago

None of the above works for me.

You need to install torch following the instructions on https://pytorch.org/get-started/previous-versions/#v201

Nope, not on any Python version after 3.11!

Nothing works, after installing conda and trying everything in docs/mac.md (which looks like it hasn't been updated in some time) and every combination of the above on my M1 Max MacBook Pro with Sonoma.

conda install pytorch==2.0.1 torchvision==0.15.2 torchaudio==2.0.2 -c pytorch

Channels:
 - pytorch
 - defaults
Platform: osx-arm64
Collecting package metadata (repodata.json): done
Solving environment: - warning  libmamba Added empty dependency for problem type SOLVER_RULE_UPDATE
failed

LibMambaUnsatisfiableError: Encountered problems while solving:
  - package torchvision-0.15.2-py310_cpu requires python >=3.10,<3.11.0a0, but none of the providers can be installed

Could not solve for environment specs
The following packages are incompatible
β”œβ”€ pin-1 is installable and it requires
β”‚  └─ python 3.12.* , which can be installed;
└─ torchvision 0.15.2  is not installable because there are no viable options
   β”œβ”€ torchvision 0.15.2 would require
   β”‚  └─ python >=3.10,<3.11.0a0 , which conflicts with any installable versions previously reported;
   β”œβ”€ torchvision 0.15.2 would require
   β”‚  └─ python >=3.11,<3.12.0a0 , which conflicts with any installable versions previously reported;
   β”œβ”€ torchvision 0.15.2 would require
   β”‚  └─ python >=3.8,<3.9.0a0 , which conflicts with any installable versions previously reported;
   └─ torchvision 0.15.2 would require
      └─ python >=3.9,<3.10.0a0 , which conflicts with any installable versions previously reported.
CarlGao4 commented 4 months ago

Yes, to use torch 2.0.1, you can't use Python 3.12 or greater. Only 3.8 to 3.11 is available.

erzakiev commented 4 months ago

@bastien8060 thanks! This helped

halfong commented 3 months ago

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

Works for me

smolinde commented 2 months ago

I found a fix! Either in pip or anaconda, uninstall PySoundFile and make sure soundfile is installed. For some reason it works.

empz commented 1 month ago

I'm experiencing this issue on Ubuntu 22.04. It's definitely something related to the dependencies. When installing PyTorch 2.4.0 using conda, everything works. But then, when trying to use pip and a venv, it doesn't. So the conda installation of PyTorch is including something that the pip alternative does not...

pustar commented 4 weeks ago

for torch 2.3.0, torchaudio 2.3.0:

pip install soundfile==0.12.1

worked for me