Skip to content

Commit 3557e88

Browse files
authored
update to torch 1.8.0 (#79)
* remove bg_iterator from data test * test 1.8.0 * remove in-place for 1.8 jit * remove soundfile backend deprecation * update setup.py requirements * add 1.7.0 tests * add tqdm * update outdir behaviour * report device * add another cli test * relax requirement * update version * remove 1.7.0 support * also from setup.py
1 parent ab132ed commit 3557e88

File tree

12 files changed

+20
-25
lines changed

12 files changed

+20
-25
lines changed

.github/workflows/test_unittests.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
strategy:
1212
matrix:
1313
python-version: [3.6, 3.7, 3.8]
14-
pytorch-version: ["1.7.0"]
14+
pytorch-version: ["1.8.0"]
1515

1616
# Timeout: https://stackoverflow.com/a/59076067/4521646
1717
timeout-minutes: 10
@@ -34,6 +34,8 @@ jobs:
3434
python -m pip install coverage codecov --upgrade-strategy only-if-needed --quiet
3535
if [ $TORCH_INSTALL == "1.7.0" ]; then
3636
INSTALL="torch==1.7.0+cpu torchaudio==0.7.0 -f https://download.pytorch.org/whl/torch_stable.html"
37+
elif [ $TORCH_INSTALL == "1.8.0" ]; then
38+
INSTALL="torch==1.8.0+cpu torchaudio==0.8.0 -f https://download.pytorch.org/whl/torch_stable.html"
3739
else
3840
INSTALL="--pre torch torchaudio -f https://download.pytorch.org/whl/nightly/cpu/torch_nightly.html"
3941
fi

openunmix/cli.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,14 +113,13 @@ def separate():
113113
"for deployment.",
114114
)
115115
args = parser.parse_args()
116-
torchaudio.USE_SOUNDFILE_LEGACY_INTERFACE = False
117116

118117
if args.audio_backend != "stempeg":
119118
torchaudio.set_audio_backend(args.audio_backend)
120119

121120
use_cuda = not args.no_cuda and torch.cuda.is_available()
122121
device = torch.device("cuda" if use_cuda else "cpu")
123-
122+
print("Using ", device)
124123
# parsing the output dict
125124
aggregate_dict = None if args.aggregate is None else json.loads(args.aggregate)
126125

@@ -173,7 +172,7 @@ def separate():
173172
else:
174173
outdir = Path(Path(input_file).stem + "_" + model_path.stem)
175174
else:
176-
outdir = Path(args.outdir)
175+
outdir = Path(args.outdir) / Path(input_file).stem
177176
outdir.mkdir(exist_ok=True, parents=True)
178177

179178
# write out estimates

openunmix/data.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import torch.utils.data
88
import torchaudio
99
import tqdm
10-
from torchaudio.datasets.utils import bg_iterator
1110

1211

1312
def load_info(path: str) -> dict:
@@ -941,7 +940,6 @@ def __len__(self):
941940

942941
args, _ = parser.parse_known_args()
943942

944-
torchaudio.USE_SOUNDFILE_LEGACY_INTERFACE = False
945943
torchaudio.set_audio_backend(args.audio_backend)
946944

947945
train_dataset, valid_dataset, args = load_datasets(parser, args)
@@ -970,6 +968,5 @@ def __len__(self):
970968
num_workers=4,
971969
)
972970

973-
train_sampler = bg_iterator(train_sampler, 4)
974971
for x, y in tqdm.tqdm(train_sampler):
975-
pass
972+
print(x.shape)

openunmix/model.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,8 @@ def forward(self, x: Tensor) -> Tensor:
124124
# crop
125125
x = x[..., : self.nb_bins]
126126
# shift and scale input to mean=0 std=1 (across all bins)
127-
x += self.input_mean
128-
x *= self.input_scale
127+
x = x + self.input_mean
128+
x = x * self.input_scale
129129

130130
# to (nb_frames*nb_samples, nb_channels*nb_bins)
131131
# and encode to (nb_frames*nb_samples, hidden_size)

openunmix/transforms.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ def forward(self, x: Tensor) -> Tensor:
9696
# pack batch
9797
x = x.view(-1, shape[-1])
9898

99-
stft_f = torch.stft(
99+
complex_stft = torch.stft(
100100
x,
101101
n_fft=self.n_fft,
102102
hop_length=self.n_hop,
@@ -105,8 +105,9 @@ def forward(self, x: Tensor) -> Tensor:
105105
normalized=False,
106106
onesided=True,
107107
pad_mode="reflect",
108+
return_complex=True,
108109
)
109-
110+
stft_f = torch.view_as_real(complex_stft)
110111
# unpack batch
111112
stft_f = stft_f.view(shape[:-1] + stft_f.shape[-3:])
112113
return stft_f
@@ -158,7 +159,7 @@ def forward(self, X: Tensor, length: Optional[int] = None) -> Tensor:
158159
X = X.reshape(-1, shape[-3], shape[-2], shape[-1])
159160

160161
y = torch.istft(
161-
X,
162+
torch.view_as_complex(X),
162163
n_fft=self.n_fft,
163164
hop_length=self.n_hop,
164165
window=self.window,

openunmix/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ def preprocess(
295295
audio = torch.repeat_interleave(audio, 2, dim=1)
296296

297297
if rate != model_rate:
298-
print("resampling")
298+
warnings.warn("resample to model sample rate")
299299
# we have to resample to model samplerate if needed
300300
# this makes sure we resample input only once
301301
resampler = torchaudio.transforms.Resample(

scripts/train.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,6 @@ def main():
202202

203203
args, _ = parser.parse_known_args()
204204

205-
torchaudio.USE_SOUNDFILE_LEGACY_INTERFACE = False
206205
torchaudio.set_audio_backend(args.audio_backend)
207206
use_cuda = not args.no_cuda and torch.cuda.is_available()
208207
print("Using GPU:", use_cuda)

setup.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from setuptools import setup, find_packages
22

3-
umx_version = "1.1.0"
3+
umx_version = "1.1.1"
44

55
with open("README.md", encoding="utf-8") as fh:
66
long_description = fh.read()
@@ -18,17 +18,18 @@
1818
python_requires=">=3.6",
1919
install_requires=[
2020
"numpy",
21-
"torchaudio>=0.7.0",
22-
"torch>=1.7.0",
21+
"torchaudio>=0.8.0",
22+
"torch>=1.8.0",
2323
],
2424
extras_require={
2525
"asteroid": ["asteroid-filterbanks>=0.3.2"],
2626
"tests": [
2727
"pytest",
2828
"musdb>=0.4.0",
2929
"museval>=0.4.0",
30-
"onnx",
3130
"asteroid-filterbanks>=0.3.2",
31+
"onnx",
32+
"tqdm",
3233
],
3334
"stempeg": ["stempeg"],
3435
"evaluation": ["musdb>=0.4.0", "museval>=0.4.0"],

tests/cli_test.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ python -m pip install -e .['stempeg'] --quiet
22

33
# run umx on url
44
coverage run -a `which umx` https://samples.ffmpeg.org/A-codecs/wavpcm/test-96.wav --audio-backend stempeg
5+
coverage run -a `which umx` https://samples.ffmpeg.org/A-codecs/wavpcm/test-96.wav --audio-backend stempeg --outdir out --niter 0

tests/test_datasets.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ def test_musdb():
1717

1818

1919
def test_trackfolder_fix(torch_backend):
20-
torchaudio.USE_SOUNDFILE_LEGACY_INTERFACE = False
2120
torchaudio.set_audio_backend(torch_backend)
2221

2322
train_dataset = data.FixedSourcesTrackFolderDataset(
@@ -33,7 +32,6 @@ def test_trackfolder_fix(torch_backend):
3332

3433

3534
def test_trackfolder_var(torch_backend):
36-
torchaudio.USE_SOUNDFILE_LEGACY_INTERFACE = False
3735
torchaudio.set_audio_backend(torch_backend)
3836

3937
train_dataset = data.VariableSourcesTrackFolderDataset(
@@ -48,7 +46,6 @@ def test_trackfolder_var(torch_backend):
4846

4947

5048
def test_sourcefolder(torch_backend):
51-
torchaudio.USE_SOUNDFILE_LEGACY_INTERFACE = False
5249
torchaudio.set_audio_backend(torch_backend)
5350

5451
train_dataset = data.SourceFolderDataset(

0 commit comments

Comments
 (0)