From b382496d4ceb3519f7f8f53cd261ac6b237c56ba Mon Sep 17 00:00:00 2001 From: moto <855818+mthrok@users.noreply.github.com> Date: Thu, 1 Jun 2023 14:35:03 -0400 Subject: [PATCH] Update tests and CI --- .github/scripts/unittest-linux/install.sh | 2 +- .github/scripts/unittest-windows/install.sh | 2 +- .github/workflows/unittest-linux-cpu.yml | 2 ++ .github/workflows/unittest-linux-gpu.yml | 2 +- .github/workflows/unittest-macos-cpu.yml | 2 ++ .../backend/dispatcher/sox/info_test.py | 4 +++- .../backend/dispatcher/sox/load_test.py | 3 +++ .../backend/dispatcher/sox/save_test.py | 10 +++++++++- .../backend/sox_io/info_test.py | 2 ++ .../backend/sox_io/load_test.py | 3 +++ .../backend/sox_io/save_test.py | 10 +++++++++- .../common_utils/__init__.py | 2 ++ .../common_utils/case_utils.py | 18 ++++++++++++++++++ .../sox_effect/dataset_test.py | 4 ++-- 14 files changed, 58 insertions(+), 8 deletions(-) diff --git a/.github/scripts/unittest-linux/install.sh b/.github/scripts/unittest-linux/install.sh index 885296219cd..70a8793c224 100755 --- a/.github/scripts/unittest-linux/install.sh +++ b/.github/scripts/unittest-linux/install.sh @@ -75,7 +75,7 @@ fi # Note: installing librosa via pip fail because it will try to compile numba. ( set -x - conda install -y -c conda-forge ${NUMBA_DEV_CHANNEL} 'librosa==0.10.0' parameterized 'requests>=2.20' 'ffmpeg>=5,<7' + conda install -y -c conda-forge ${NUMBA_DEV_CHANNEL} sox libvorbis 'librosa==0.10.0' parameterized 'requests>=2.20' 'ffmpeg>=5,<7' pip install kaldi-io SoundFile coverage pytest pytest-cov 'scipy==1.7.3' expecttest unidecode inflect Pillow sentencepiece pytorch-lightning 'protobuf<4.21.0' demucs tinytag pyroomacoustics flashlight-text git+https://github.com/kpu/kenlm ) # Install fairseq diff --git a/.github/scripts/unittest-windows/install.sh b/.github/scripts/unittest-windows/install.sh index 676de7e830a..f1b8c529a75 100644 --- a/.github/scripts/unittest-windows/install.sh +++ b/.github/scripts/unittest-windows/install.sh @@ -67,7 +67,7 @@ case "$(python --version)" in esac # Note: installing librosa via pip fail because it will try to compile numba. ( - conda install -y -c conda-forge ${NUMBA_DEV_CHANNEL} 'librosa==0.10.0' parameterized 'requests>=2.20' + conda install -y -c conda-forge ${NUMBA_DEV_CHANNEL} sox libvorbis 'librosa==0.10.0' parameterized 'requests>=2.20' # Need to disable shell check since this'll fail out if SENTENCEPIECE_DEPENDENCY is empty # shellcheck disable=SC2086 pip install \ diff --git a/.github/workflows/unittest-linux-cpu.yml b/.github/workflows/unittest-linux-cpu.yml index 6deb5412d0c..81da24deb63 100644 --- a/.github/workflows/unittest-linux-cpu.yml +++ b/.github/workflows/unittest-linux-cpu.yml @@ -49,6 +49,8 @@ jobs: export TORCHAUDIO_TEST_ALLOW_SKIP_IF_ON_PYTHON_310=true export TORCHAUDIO_TEST_ALLOW_SKIP_IF_NO_AUDIO_OUT_DEVICE=true export TORCHAUDIO_TEST_ALLOW_SKIP_IF_NO_MACOS=true + export TORCHAUDIO_TEST_ALLOW_SKIP_IF_NO_SOX_DECODER=true + export TORCHAUDIO_TEST_ALLOW_SKIP_IF_NO_SOX_ENCODER=true echo '::endgroup::' set -euxo pipefail diff --git a/.github/workflows/unittest-linux-gpu.yml b/.github/workflows/unittest-linux-gpu.yml index 7e8b27cf4d0..03da8688a46 100644 --- a/.github/workflows/unittest-linux-gpu.yml +++ b/.github/workflows/unittest-linux-gpu.yml @@ -59,7 +59,7 @@ jobs: python3 -m pip install -v -e . --no-use-pep517 # Install test tools - conda install -y --quiet -c conda-forge -c numba/label/dev 'librosa==0.10.0' parameterized 'requests>=2.20' 'ffmpeg>=5,<7' + conda install -y --quiet -c conda-forge -c numba/label/dev sox libvorbis 'librosa==0.10.0' parameterized 'requests>=2.20' 'ffmpeg>=5,<7' python3 -m pip install --quiet kaldi-io SoundFile coverage pytest pytest-cov 'scipy==1.7.3' transformers expecttest unidecode inflect Pillow sentencepiece pytorch-lightning 'protobuf<4.21.0' demucs tinytag flashlight-text git+https://github.com/kpu/kenlm/ python3 -m pip install --quiet git+https://github.com/pytorch/fairseq.git@e47a4c8 diff --git a/.github/workflows/unittest-macos-cpu.yml b/.github/workflows/unittest-macos-cpu.yml index 1324f1dbabc..f27ca77d5b2 100644 --- a/.github/workflows/unittest-macos-cpu.yml +++ b/.github/workflows/unittest-macos-cpu.yml @@ -48,6 +48,8 @@ jobs: export TORCHAUDIO_TEST_ALLOW_SKIP_IF_ON_PYTHON_310=true export TORCHAUDIO_TEST_ALLOW_SKIP_IF_NO_MOD_sentencepiece=true export TORCHAUDIO_TEST_ALLOW_SKIP_IF_NO_AUDIO_OUT_DEVICE=true + export TORCHAUDIO_TEST_ALLOW_SKIP_IF_NO_SOX_DECODER=true + export TORCHAUDIO_TEST_ALLOW_SKIP_IF_NO_SOX_ENCODER=true echo '::endgroup::' set -euxo pipefail diff --git a/test/torchaudio_unittest/backend/dispatcher/sox/info_test.py b/test/torchaudio_unittest/backend/dispatcher/sox/info_test.py index 7d87e375ee6..87d13fe5bcd 100644 --- a/test/torchaudio_unittest/backend/dispatcher/sox/info_test.py +++ b/test/torchaudio_unittest/backend/dispatcher/sox/info_test.py @@ -15,6 +15,7 @@ skipIfNoExec, skipIfNoModule, skipIfNoSox, + skipIfNoSoxDecoder, sox_utils, TempDirMixin, ) @@ -178,6 +179,7 @@ def test_amb(self, dtype, sample_rate, num_channels): assert info.bits_per_sample == bits_per_sample assert info.encoding == get_encoding("amb", dtype) + @skipIfNoSoxDecoder("amr_nb") def test_amr_nb(self): """`self._info` can check amr-nb file correctly""" duration = 1 @@ -256,7 +258,7 @@ def test_htk(self): assert info.encoding == "PCM_S" -@skipIfNoSox +@skipIfNoSoxDecoder("opus") class TestInfoOpus(PytorchTestCase): _info = partial(get_info_func(), backend="sox") diff --git a/test/torchaudio_unittest/backend/dispatcher/sox/load_test.py b/test/torchaudio_unittest/backend/dispatcher/sox/load_test.py index 58c6098a2c6..fa9654540b5 100644 --- a/test/torchaudio_unittest/backend/dispatcher/sox/load_test.py +++ b/test/torchaudio_unittest/backend/dispatcher/sox/load_test.py @@ -13,6 +13,7 @@ save_wav, skipIfNoExec, skipIfNoSox, + skipIfNoSoxDecoder, sox_utils, TempDirMixin, ) @@ -237,6 +238,7 @@ def test_vorbis_large(self, sample_rate, num_channels, quality_level): ), name_func=name_func, ) + @skipIfNoSoxDecoder("opus") def test_opus(self, bitrate, num_channels, compression_level): """`sox_io_backend.load` can load opus file correctly.""" ops_path = get_asset_path("io", f"{bitrate}_{compression_level}_{num_channels}ch.opus") @@ -281,6 +283,7 @@ def test_amb(self, dtype, sample_rate, num_channels, normalize): "amb", sample_rate, num_channels, bit_depth=bit_depth, duration=1, encoding=encoding, normalize=normalize ) + @skipIfNoSoxDecoder("amr_nb") def test_amr_nb(self): """`sox_io_backend.load` can load amr_nb format correctly.""" self.assert_format("amr-nb", sample_rate=8000, num_channels=1, bit_depth=32, duration=1) diff --git a/test/torchaudio_unittest/backend/dispatcher/sox/save_test.py b/test/torchaudio_unittest/backend/dispatcher/sox/save_test.py index eec476b6d24..afa63f69a1c 100644 --- a/test/torchaudio_unittest/backend/dispatcher/sox/save_test.py +++ b/test/torchaudio_unittest/backend/dispatcher/sox/save_test.py @@ -13,6 +13,7 @@ save_wav, skipIfNoExec, skipIfNoSox, + skipIfNoSoxEncoder, sox_utils, TempDirMixin, TorchaudioTestCase, @@ -253,6 +254,7 @@ def test_save_amb(self, enc_params): encoding, bits_per_sample = enc_params self.assert_save_consistency("amb", encoding=encoding, bits_per_sample=bits_per_sample, test_mode="path") + @skipIfNoSoxEncoder("amr_nb") def test_save_amr_nb(self): self.assert_save_consistency("amr-nb", num_channels=1, test_mode="path") @@ -269,12 +271,18 @@ def test_save_gsm(self): ("flac",), ("vorbis",), ("sph", "PCM_S", 16), - ("amr-nb",), ("amb", "PCM_S", 16), ], name_func=name_func, ) def test_save_large(self, format, encoding=None, bits_per_sample=None): + self._test_save_large(format, encoding, bits_per_sample) + + @skipIfNoSoxEncoder("amr_nb") + def test_save_large_amr_nb(self): + self._test_save_large("amr_nb") + + def _test_save_large(self, format, encoding=None, bits_per_sample=None): """`self._save` can save large files.""" sample_rate = 8000 one_hour = 60 * 60 * sample_rate diff --git a/test/torchaudio_unittest/backend/sox_io/info_test.py b/test/torchaudio_unittest/backend/sox_io/info_test.py index eea03133142..67782091cc8 100644 --- a/test/torchaudio_unittest/backend/sox_io/info_test.py +++ b/test/torchaudio_unittest/backend/sox_io/info_test.py @@ -10,6 +10,7 @@ save_wav, skipIfNoExec, skipIfNoSox, + skipIfNoSoxDecoder, sox_utils, TempDirMixin, ) @@ -196,6 +197,7 @@ def test_amb(self, dtype, sample_rate, num_channels): assert info.bits_per_sample == bits_per_sample assert info.encoding == get_encoding("amb", dtype) + @skipIfNoSoxDecoder("amr_nb") def test_amr_nb(self): """`sox_io_backend.info` can check amr-nb file correctly""" duration = 1 diff --git a/test/torchaudio_unittest/backend/sox_io/load_test.py b/test/torchaudio_unittest/backend/sox_io/load_test.py index ea168030777..2996885bd61 100644 --- a/test/torchaudio_unittest/backend/sox_io/load_test.py +++ b/test/torchaudio_unittest/backend/sox_io/load_test.py @@ -12,6 +12,7 @@ save_wav, skipIfNoExec, skipIfNoSox, + skipIfNoSoxDecoder, sox_utils, TempDirMixin, ) @@ -234,6 +235,7 @@ def test_vorbis_large(self, sample_rate, num_channels, quality_level): ), name_func=name_func, ) + @skipIfNoSoxDecoder("opus") def test_opus(self, bitrate, num_channels, compression_level): """`sox_io_backend.load` can load opus file correctly.""" ops_path = get_asset_path("io", f"{bitrate}_{compression_level}_{num_channels}ch.opus") @@ -278,6 +280,7 @@ def test_amb(self, dtype, sample_rate, num_channels, normalize): "amb", sample_rate, num_channels, bit_depth=bit_depth, duration=1, encoding=encoding, normalize=normalize ) + @skipIfNoSoxDecoder("amr_nb") def test_amr_nb(self): """`sox_io_backend.load` can load amr_nb format correctly.""" self.assert_format("amr-nb", sample_rate=8000, num_channels=1, bit_depth=32, duration=1) diff --git a/test/torchaudio_unittest/backend/sox_io/save_test.py b/test/torchaudio_unittest/backend/sox_io/save_test.py index a92b3d98cb6..f6e3ce60017 100644 --- a/test/torchaudio_unittest/backend/sox_io/save_test.py +++ b/test/torchaudio_unittest/backend/sox_io/save_test.py @@ -11,6 +11,7 @@ save_wav, skipIfNoExec, skipIfNoSox, + skipIfNoSoxEncoder, sox_utils, TempDirMixin, TorchaudioTestCase, @@ -265,6 +266,7 @@ def test_save_amb(self, enc_params): 7, ], ) + @skipIfNoSoxEncoder("amr-nb") def test_save_amr_nb(self, bit_rate): self.assert_save_consistency("amr-nb", compression=bit_rate, num_channels=1) @@ -281,12 +283,18 @@ def test_save_gsm(self): ("flac",), ("vorbis",), ("sph", "PCM_S", 16), - ("amr-nb",), ("amb", "PCM_S", 16), ], name_func=name_func, ) def test_save_large(self, format, encoding=None, bits_per_sample=None): + self._test_save_large(format, encoding, bits_per_sample) + + @skipIfNoSoxEncoder + def test_save_large_amr_nb(self): + self.test_save_large("amr_nb") + + def _test_save_large(self, format, encoding=None, bits_per_sample=None): """`sox_io_backend.save` can save large files.""" sample_rate = 8000 one_hour = 60 * 60 * sample_rate diff --git a/test/torchaudio_unittest/common_utils/__init__.py b/test/torchaudio_unittest/common_utils/__init__.py index 8c66f2149a4..6ac24102475 100644 --- a/test/torchaudio_unittest/common_utils/__init__.py +++ b/test/torchaudio_unittest/common_utils/__init__.py @@ -18,6 +18,8 @@ skipIfNoQengine, skipIfNoRIR, skipIfNoSox, + skipIfNoSoxDecoder, + skipIfNoSoxEncoder, skipIfPy310, skipIfRocm, TempDirMixin, diff --git a/test/torchaudio_unittest/common_utils/case_utils.py b/test/torchaudio_unittest/common_utils/case_utils.py index a094f5d64f0..54d35149229 100644 --- a/test/torchaudio_unittest/common_utils/case_utils.py +++ b/test/torchaudio_unittest/common_utils/case_utils.py @@ -234,6 +234,24 @@ def skipIfNoModule(module, display_name=None): reason="Sox features are not available.", key="NO_SOX", ) + + +def skipIfNoSoxDecoder(ext): + return _skipIf( + not torchaudio._extension._SOX_INITIALIZED or ext not in torchaudio.utils.sox_utils.list_read_formats(), + f'sox does not handle "{ext}" for read.', + key=f"NO_SOX_DECODER", + ) + + +def skipIfNoSoxEncoder(ext): + return _skipIf( + not torchaudio._extension._SOX_INITIALIZED or ext not in torchaudio.utils.sox_utils.list_write_formats(), + f'sox does not handle "{ext}" for read.', + key=f"NO_SOX_ENCODER", + ) + + skipIfNoRIR = _skipIf( not torchaudio._extension._IS_RIR_AVAILABLE, reason="RIR features are not available.", diff --git a/test/torchaudio_unittest/sox_effect/dataset_test.py b/test/torchaudio_unittest/sox_effect/dataset_test.py index ba3b6edf8e0..4e99fad9cfc 100644 --- a/test/torchaudio_unittest/sox_effect/dataset_test.py +++ b/test/torchaudio_unittest/sox_effect/dataset_test.py @@ -94,7 +94,7 @@ def test_apply_effects_file(self): loader = torch.utils.data.DataLoader( dataset, batch_size=32, - num_workers=16, + num_workers=4, worker_init_fn=init_random_seed, ) for batch in loader: @@ -115,7 +115,7 @@ def test_apply_effects_tensor(self): loader = torch.utils.data.DataLoader( dataset, batch_size=32, - num_workers=16, + num_workers=4, worker_init_fn=init_random_seed, ) for batch in loader: