Skip to content

Commit

Permalink
Merge remote-tracking branch 'remotes/adefossez/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
jlami committed Jun 6, 2024
2 parents e976d93 + 8174c5d commit 5c97ac7
Show file tree
Hide file tree
Showing 16 changed files with 55 additions and 22 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# Demucs Music Source Separation

[![Support Ukraine](https://img.shields.io/badge/Support-Ukraine-FFD500?style=flat&labelColor=005BBB)](https://opensource.fb.com/support-ukraine)
![tests badge](https://github.com/facebookresearch/demucs/workflows/tests/badge.svg)
![linter badge](https://github.com/facebookresearch/demucs/workflows/linter/badge.svg)


**Important:** As I am no longer working at Meta, **this repository is not maintained anymore**.
I've created a fork at [github.com/adefossez/demucs](https://github.com/adefossez/demucs). Note that this project is not actively maintained anymore
and only important bug fixes will be processed on the new repo. Please do not open issues for feature request or if Demucs doesn't work perfectly for your use case :)
**This is the officially maintained Demucs** now that I (Alexandre Défossez) have left Meta to join [Kyutai](https://twitter.com/kyutai_labs).
Note that I'm not actively working on Demucs anymore, so expect slow replies and no new feature for now.



This is the 4th release of Demucs (v4), featuring Hybrid Transformer based source separation.
**For the classic Hybrid Demucs (v3):** [Go this commit][demucs_v3].
Expand Down
2 changes: 1 addition & 1 deletion demucs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.

__version__ = "4.1.0a2"
__version__ = "4.1.0a3"
1 change: 1 addition & 0 deletions demucs/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

import subprocess

from . import audio_legacy
import torch as th
import torchaudio as ta

Expand Down
2 changes: 1 addition & 1 deletion demucs/apply.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def __init__(self, models: tp.List[Model],
assert other.samplerate == first.samplerate
assert other.audio_channels == first.audio_channels
if segment is not None:
if not isinstance(other, HTDemucs) and segment > other.segment:
if not isinstance(other, HTDemucs) or segment <= other.segment:
other.segment = segment

self.audio_channels = first.audio_channels
Expand Down
1 change: 1 addition & 0 deletions demucs/audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import lameenc
import julius
import numpy as np
from . import audio_legacy
import torch
import torchaudio as ta
import typing as tp
Expand Down
17 changes: 17 additions & 0 deletions demucs/audio_legacy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# This file is to extend support for torchaudio 2.1

import importlib
import os
import sys
import warnings

if not "torchaudio" in sys.modules:
os.environ["TORCHAUDIO_USE_BACKEND_DISPATCHER"] = "0"
elif os.getenv("TORCHAUDIO_USE_BACKEND_DISPATCHER", default="1") == "1":
if sys.modules["torchaudio"].__version__ >= "2.1":
os.environ["TORCHAUDIO_USE_BACKEND_DISPATCHER"] = "0"
importlib.reload(sys.modules["torchaudio"])
warnings.warn(
"TORCHAUDIO_USE_BACKEND_DISPATCHER is set to 0 and torchaudio is reloaded.",
ImportWarning,
)
10 changes: 6 additions & 4 deletions demucs/hdemucs.py
Original file line number Diff line number Diff line change
Expand Up @@ -776,16 +776,18 @@ def forward(self, mix):
# demucs issue #435 ##432
# NOTE: in this case z already is on cpu
# TODO: remove this when mps supports complex numbers
x_is_mps = x.device.type == "mps"
if x_is_mps:
x_is_mps_xpu = x.device.type in ["mps", "xpu"]
x_device = x.device
if x_is_mps_xpu:
x = x.cpu()

zout = self._mask(z, x)
x = self._ispec(zout, length)

# back to mps device
if x_is_mps:
x = x.to('mps')
if x_is_mps_xpu:
x = x.to(x_device)


if self.hybrid:
xt = xt.view(B, S, -1, length)
Expand Down
9 changes: 5 additions & 4 deletions demucs/htdemucs.py
Original file line number Diff line number Diff line change
Expand Up @@ -629,8 +629,9 @@ def forward(self, mix):
# demucs issue #435 ##432
# NOTE: in this case z already is on cpu
# TODO: remove this when mps supports complex numbers
x_is_mps = x.device.type == "mps"
if x_is_mps:
x_is_mps_xpu = x.device.type in ["mps", "xpu"]
x_device = x.device
if x_is_mps_xpu:
x = x.cpu()

zout = self._mask(z, x)
Expand All @@ -643,8 +644,8 @@ def forward(self, mix):
x = self._ispec(zout, length)

# back to mps device
if x_is_mps:
x = x.to("mps")
if x_is_mps_xpu:
x = x.to(x_device)

if self.use_train_segment:
if self.training:
Expand Down
1 change: 1 addition & 0 deletions demucs/repitch.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import subprocess as sp
import tempfile

from . import audio_legacy
import torch
import torchaudio as ta

Expand Down
8 changes: 7 additions & 1 deletion demucs/separate.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,13 @@ def get_parser():
'Default is "{track}/{stem}.{ext}".')
parser.add_argument("-d",
"--device",
default="cuda" if th.cuda.is_available() else "cpu",
default=(
"cuda"
if th.cuda.is_available()
else "mps"
if th.backends.mps.is_available()
else "cpu"
),
help="Device to use, default is cuda if available else cpu")
parser.add_argument("--shifts",
default=1,
Expand Down
8 changes: 4 additions & 4 deletions demucs/spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
def spectro(x, n_fft=512, hop_length=None, pad=0):
*other, length = x.shape
x = x.reshape(-1, length)
is_mps = x.device.type == 'mps'
if is_mps:
is_mps_xpu = x.device.type in ['mps', 'xpu']
if is_mps_xpu:
x = x.cpu()
z = th.stft(x,
n_fft * (1 + pad),
Expand All @@ -32,8 +32,8 @@ def ispectro(z, hop_length=None, length=None, pad=0):
n_fft = 2 * freqs - 2
z = z.view(-1, freqs, frames)
win_length = n_fft // (1 + pad)
is_mps = z.device.type == 'mps'
if is_mps:
is_mps_xpu = z.device.type in ['mps', 'xpu']
if is_mps_xpu:
z = z.cpu()
x = th.istft(z,
n_fft,
Expand Down
1 change: 1 addition & 0 deletions demucs/train.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import hydra
from hydra.core.global_hydra import GlobalHydra
from omegaconf import OmegaConf
from . import audio_legacy
import torch
from torch import nn
import torchaudio
Expand Down
1 change: 1 addition & 0 deletions demucs/wav.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

import musdb
import julius
from . import audio_legacy
import torch as th
from torch import distributed
import torchaudio as ta
Expand Down
4 changes: 3 additions & 1 deletion docs/release.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Release notes for Demucs

## V4.1.0a1, TBD
## V4.1.0a, TBD

Get models list

Expand All @@ -14,6 +14,8 @@ Added `--other-method`: method to get `no_{STEM}`, add up all the other stems (a

Added type `HTDemucs` to type alias `AnyModel`.

Improving recent torchaudio versions support (Thanks @CarlGao4)

## V4.0.1, 8th of September 2023

**From this version, Python 3.7 is no longer supported. This is not a problem since the latest PyTorch 2.0.0 no longer support it either.**
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ openunmix
pyyaml
submitit
torch>=1.8.1
torchaudio>=0.8,<2.1
torchaudio>=0.8,<2.2
tqdm
treetable
soundfile>=0.10.3;sys_platform=="win32"
2 changes: 1 addition & 1 deletion requirements_minimal.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ lameenc>=1.2
openunmix
pyyaml
torch>=1.8.1
torchaudio>=0.8,<2.1
torchaudio>=0.8,<2.2
tqdm

0 comments on commit 5c97ac7

Please sign in to comment.