Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
Torchaudio
Commits
3c448374
Unverified
Commit
3c448374
authored
Mar 03, 2021
by
Caroline Chen
Committed by
GitHub
Mar 03, 2021
Browse files
Make kaldi selective in build (#1342)
parent
5521f6c7
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
44 additions
and
15 deletions
+44
-15
build_tools/setup_helpers/extension.py
build_tools/setup_helpers/extension.py
+6
-2
test/torchaudio_unittest/common_utils/__init__.py
test/torchaudio_unittest/common_utils/__init__.py
+2
-2
test/torchaudio_unittest/common_utils/case_utils.py
test/torchaudio_unittest/common_utils/case_utils.py
+3
-9
test/torchaudio_unittest/functional/batch_consistency_test.py
.../torchaudio_unittest/functional/batch_consistency_test.py
+1
-1
test/torchaudio_unittest/functional/torchscript_consistency_impl.py
...audio_unittest/functional/torchscript_consistency_impl.py
+1
-1
torchaudio/_internal/module_utils.py
torchaudio/_internal/module_utils.py
+17
-0
torchaudio/csrc/CMakeLists.txt
torchaudio/csrc/CMakeLists.txt
+4
-0
torchaudio/csrc/utils.cpp
torchaudio/csrc/utils.cpp
+9
-0
torchaudio/functional/functional.py
torchaudio/functional/functional.py
+1
-0
No files found.
build_tools/setup_helpers/extension.py
View file @
3c448374
...
...
@@ -18,7 +18,10 @@ _ROOT_DIR = _THIS_DIR.parent.parent.resolve()
_TORCHAUDIO_DIR
=
_ROOT_DIR
/
'torchaudio'
def
_get_build
(
var
):
def
_get_build
(
var
,
default
=
False
):
if
var
not
in
os
.
environ
:
return
default
val
=
os
.
environ
.
get
(
var
,
'0'
)
trues
=
[
'1'
,
'true'
,
'TRUE'
,
'on'
,
'ON'
,
'yes'
,
'YES'
]
falses
=
[
'0'
,
'false'
,
'FALSE'
,
'off'
,
'OFF'
,
'no'
,
'NO'
]
...
...
@@ -32,6 +35,7 @@ def _get_build(var):
_BUILD_SOX
=
_get_build
(
"BUILD_SOX"
)
_BUILD_KALDI
=
_get_build
(
"BUILD_KALDI"
,
True
)
_BUILD_TRANSDUCER
=
_get_build
(
"BUILD_TRANSDUCER"
)
...
...
@@ -68,7 +72,7 @@ class CMakeBuild(build_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"
,
...
...
test/torchaudio_unittest/common_utils/__init__.py
View file @
3c448374
...
...
@@ -15,7 +15,7 @@ from .case_utils import (
skipIfNoCuda
,
skipIfNoExec
,
skipIfNoModule
,
skipIfNo
Extension
,
skipIfNo
Kaldi
,
skipIfNoSox
,
skipIfNoSoxBackend
,
)
...
...
@@ -31,5 +31,5 @@ from .parameterized_utils import (
__all__
=
[
'get_asset_path'
,
'get_whitenoise'
,
'get_sinusoid'
,
'set_audio_backend'
,
'TempDirMixin'
,
'HttpServerMixin'
,
'TestBaseMixin'
,
'PytorchTestCase'
,
'TorchaudioTestCase'
,
'skipIfNoCuda'
,
'skipIfNoExec'
,
'skipIfNoModule'
,
'skipIfNo
Extension
'
,
'skipIfNoSox'
,
'skipIfNoCuda'
,
'skipIfNoExec'
,
'skipIfNoModule'
,
'skipIfNo
Kaldi
'
,
'skipIfNoSox'
,
'skipIfNoSoxBackend'
,
'get_wav_data'
,
'normalize_wav'
,
'load_wav'
,
'save_wav'
,
'load_params'
]
test/torchaudio_unittest/common_utils/case_utils.py
View file @
3c448374
...
...
@@ -10,7 +10,8 @@ from torch.testing._internal.common_utils import TestCase as PytorchTestCase
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
...
...
@@ -99,11 +100,4 @@ skipIfNoSoxBackend = unittest.skipIf(
'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
:
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'
)
test/torchaudio_unittest/functional/batch_consistency_test.py
View file @
3c448374
...
...
@@ -206,7 +206,7 @@ class TestFunctional(common_utils.TorchaudioTestCase):
self
.
assert_batch_consistency
(
F
.
vad
,
waveforms
,
sample_rate
=
sample_rate
)
@
common_utils
.
skipIfNo
Extension
@
common_utils
.
skipIfNo
Kaldi
def
test_compute_kaldi_pitch
(
self
):
sample_rate
=
44100
n_channels
=
2
...
...
test/torchaudio_unittest/functional/torchscript_consistency_impl.py
View file @
3c448374
...
...
@@ -548,7 +548,7 @@ class Functional(common_utils.TestBaseMixin):
tensor
=
common_utils
.
get_whitenoise
(
sample_rate
=
44100
)
self
.
_assert_consistency
(
func
,
tensor
)
@
common_utils
.
skipIfNo
Extension
@
common_utils
.
skipIfNo
Kaldi
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."
)
...
...
torchaudio/_internal/module_utils.py
View file @
3c448374
...
...
@@ -60,6 +60,23 @@ def deprecated(direction: str, version: Optional[str] = None):
return
decorator
def
is_kaldi_available
():
return
is_module_available
(
'torchaudio._torchaudio'
)
and
torch
.
ops
.
torchaudio
.
is_kaldi_available
()
def
requires_kaldi
():
if
is_kaldi_available
():
def
decorator
(
func
):
return
func
else
:
def
decorator
(
func
):
@
wraps
(
func
)
def
wrapped
(
*
args
,
**
kwargs
):
raise
RuntimeError
(
f
'
{
func
.
__module__
}
.
{
func
.
__name__
}
requires kaldi'
)
return
wrapped
return
decorator
def
is_sox_available
():
return
is_module_available
(
'torchaudio._torchaudio'
)
and
torch
.
ops
.
torchaudio
.
is_sox_available
()
...
...
torchaudio/csrc/CMakeLists.txt
View file @
3c448374
...
...
@@ -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
...
...
torchaudio/csrc/utils.cpp
View file @
3c448374
...
...
@@ -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
torchaudio/functional/functional.py
View file @
3c448374
...
...
@@ -1114,6 +1114,7 @@ def apply_codec(
return
augmented
@
_mod_utils
.
requires_kaldi
()
def
compute_kaldi_pitch
(
waveform
:
torch
.
Tensor
,
sample_rate
:
float
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment