Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make kaldi selective #1342

Merged
merged 4 commits into from
Mar 3, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion build_tools/setup_helpers/extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ def _get_build(var):


_BUILD_SOX = _get_build("BUILD_SOX")
_BUILD_KALDI = _get_build("BUILD_KALDI")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because we currently default to build Kaldi, in case the environment variable is missing, we need to default to true for this.

Please update the _get_build to allow override of default value.

_BUILD_TRANSDUCER = _get_build("BUILD_TRANSDUCER")


Expand Down Expand Up @@ -68,7 +69,7 @@ def build_extension(self, ext):
'-DCMAKE_VERBOSE_MAKEFILE=ON',
f"-DPython_INCLUDE_DIR={distutils.sysconfig.get_python_inc()}",
f"-DBUILD_SOX:BOOL={'ON' if _BUILD_SOX else 'OFF'}",
"-DBUILD_KALDI:BOOL=ON",
f"-DBUILD_KALDI:BOOL={'ON' if _BUILD_KALDI else 'OFF'}",
f"-DBUILD_TRANSDUCER:BOOL={'ON' if _BUILD_TRANSDUCER else 'OFF'}",
"-DBUILD_TORCHAUDIO_PYTHON_EXTENSION:BOOL=ON",
"-DBUILD_LIBTORCHAUDIO:BOOL=OFF",
Expand Down
4 changes: 2 additions & 2 deletions test/torchaudio_unittest/common_utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
skipIfNoCuda,
skipIfNoExec,
skipIfNoModule,
skipIfNoExtension,
skipIfNoKaldi,
skipIfNoSox,
skipIfNoSoxBackend,
)
Expand All @@ -31,5 +31,5 @@

__all__ = ['get_asset_path', 'get_whitenoise', 'get_sinusoid', 'set_audio_backend',
'TempDirMixin', 'HttpServerMixin', 'TestBaseMixin', 'PytorchTestCase', 'TorchaudioTestCase',
'skipIfNoCuda', 'skipIfNoExec', 'skipIfNoModule', 'skipIfNoExtension', 'skipIfNoSox',
'skipIfNoCuda', 'skipIfNoExec', 'skipIfNoModule', 'skipIfNoKaldi', 'skipIfNoSox',
'skipIfNoSoxBackend', 'get_wav_data', 'normalize_wav', 'load_wav', 'save_wav', 'load_params']
12 changes: 3 additions & 9 deletions test/torchaudio_unittest/common_utils/case_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
import torchaudio
from torchaudio._internal.module_utils import (
is_module_available,
is_sox_available
is_sox_available,
is_kaldi_available
)

from .backend_utils import set_audio_backend
Expand Down Expand Up @@ -99,11 +100,4 @@ def skipIfNoModule(module, display_name=None):
'sox' not in torchaudio.list_audio_backends(), 'Sox backend not available')
skipIfNoCuda = unittest.skipIf(not torch.cuda.is_available(), reason='CUDA not available')
skipIfNoSox = unittest.skipIf(not is_sox_available(), reason='Sox not available')


def skipIfNoExtension(test_item):
if is_module_available('torchaudio._torchaudio'):
return test_item
if 'TORCHAUDIO_TEST_FAIL_IF_NO_EXTENSION' in os.environ:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

follow-up (@mthrok): Revive this mechanism with new semantic.

$ grep TORCHAUDIO_TEST_FAIL_IF_NO_EXTENSIO -r .circleci/
.circleci/unittest/linux/scripts/run_test.sh:export TORCHAUDIO_TEST_FAIL_IF_NO_EXTENSION=1

raise RuntimeError('torchaudio C++ extension is not available.')
return unittest.skip('torchaudio C++ extension is not available')(test_item)
skipIfNoKaldi = unittest.skipIf(not is_kaldi_available(), reason='Kaldi not available')
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ def test_vad_different_items(self):
self.assert_batch_consistency(
F.vad, waveforms, sample_rate=sample_rate)

@common_utils.skipIfNoExtension
@common_utils.skipIfNoKaldi
def test_compute_kaldi_pitch(self):
sample_rate = 44100
n_channels = 2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,7 @@ def func(tensor):
tensor = common_utils.get_whitenoise(sample_rate=44100)
self._assert_consistency(func, tensor)

@common_utils.skipIfNoExtension
@common_utils.skipIfNoKaldi
def test_compute_kaldi_pitch(self):
if self.dtype != torch.float32 or self.device != torch.device('cpu'):
raise unittest.SkipTest("Only float32, cpu is supported.")
Expand Down
4 changes: 4 additions & 0 deletions torchaudio/_internal/module_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ def wrapped(*args, **kwargs):
return decorator


def is_kaldi_available():
return is_module_available('torchaudio._torchaudio') and torch.ops.torchaudio.is_kaldi_available()


def is_sox_available():
return is_module_available('torchaudio._torchaudio') and torch.ops.torchaudio.is_sox_available()

Expand Down
4 changes: 4 additions & 0 deletions torchaudio/csrc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ if (BUILD_TORCHAUDIO_PYTHON_EXTENSION)
target_compile_definitions(_torchaudio PRIVATE INCLUDE_SOX)
endif()

if (BUILD_KALDI)
target_compile_definitions(_torchaudio PRIVATE INCLUDE_KALDI)
endif()

target_include_directories(
_torchaudio
PRIVATE
Expand Down
9 changes: 9 additions & 0 deletions torchaudio/csrc/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,19 @@ bool is_sox_available() {
#endif
}

bool is_kaldi_available() {
#ifdef INCLUDE_KALDI
return true;
#else
return false;
#endif
}

} // namespace

TORCH_LIBRARY_FRAGMENT(torchaudio, m) {
m.def("torchaudio::is_sox_available", &is_sox_available);
m.def("torchaudio::is_kaldi_available", &is_kaldi_available);
}

} // namespace torchaudio