Skip to content

Commit 449b6ab

Browse files
authored
Use environment variable for switching SoX dep (#669)
* Use env var for switching SoX build and default to not * Update README * Fix packaging/CI script
1 parent 17bc15f commit 449b6ab

File tree

6 files changed

+83
-34
lines changed

6 files changed

+83
-34
lines changed

.circleci/unittest/linux/scripts/install.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@ printf "Installing PyTorch with %s\n" "${cudatoolkit}"
2020
conda install -y -c pytorch-nightly pytorch "${cudatoolkit}"
2121

2222
printf "* Installing torchaudio\n"
23-
python setup.py develop
23+
BUILD_SOX=1 python setup.py develop

.circleci/unittest/windows/scripts/install.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@ printf "Installing PyTorch with %s\n" "${cudatoolkit}"
2020
conda install -y -c pytorch-nightly pytorch "${cudatoolkit}"
2121

2222
printf "* Installing torchaudio\n"
23-
IS_CONDA=true python setup.py develop
23+
python setup.py develop

README.md

Lines changed: 59 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -27,29 +27,16 @@ to use and feel like a natural extension.
2727
Dependencies
2828
------------
2929
* pytorch (nightly version needed for development)
30-
* libsox v14.3.2 or above
30+
* libsox v14.3.2 or above (only required when building from source)
3131
* [optional] vesis84/kaldi-io-for-python commit cb46cb1f44318a5d04d4941cf39084c5b021241e or above
3232

33-
Quick install on
34-
OSX (Homebrew):
35-
```bash
36-
brew install sox
37-
```
38-
Linux (Ubuntu):
39-
```bash
40-
sudo apt-get install sox libsox-dev libsox-fmt-all
41-
```
42-
Anaconda
43-
```bash
44-
conda install -c conda-forge sox
45-
```
46-
4733
Installation
4834
------------
4935

50-
### Binaries
36+
### Binary Distibutions
5137

5238
To install the latest version using anaconda, run:
39+
5340
```
5441
conda install -c pytorch torchaudio
5542
```
@@ -64,26 +51,48 @@ pip install torchaudio -f https://download.pytorch.org/whl/torch_stable.html
6451
torch from PyPI. If you need a different torch configuration, preinstall torch
6552
before running this command.)
6653

67-
At the moment, there is no automated nightly build process, but we occasionally
68-
build nightlies based on PyTorch nightlies by hand following the instructions in
69-
[packaging](packaging). To install the latest nightly via pip, run:
54+
### Nightly build
55+
56+
Note that nightly build is build on PyTorch's nightly build. Therefore, you need to install the latest PyTorch when you use nightly build of torchaudio.
57+
58+
**pip**
7059

7160
```
7261
pip install numpy
7362
pip install --pre torchaudio -f https://download.pytorch.org/whl/nightly/torch_nightly.html
7463
```
7564

76-
To install the latest nightly via conda, run:
65+
**conda**
7766

7867
```
7968
conda install -y -c pytorch-nightly torchaudio
8069
```
8170

82-
8371
### From Source
8472

8573
If your system configuration is not among the supported configurations
86-
above, you can build from source.
74+
above, you can build torchaudio from source.
75+
76+
This will require libsox v14.3.2 or above.
77+
78+
<Details><Summary>Click here for the examples on how to install SoX</Summary>
79+
80+
OSX (Homebrew):
81+
```bash
82+
brew install sox
83+
```
84+
85+
Linux (Ubuntu):
86+
```bash
87+
sudo apt-get install sox libsox-dev libsox-fmt-all
88+
```
89+
90+
Anaconda
91+
```bash
92+
conda install -c conda-forge sox
93+
```
94+
95+
</Details>
8796

8897
```bash
8998
# Linux
@@ -93,8 +102,33 @@ python setup.py install
93102
MACOSX_DEPLOYMENT_TARGET=10.9 CC=clang CXX=clang++ python setup.py install
94103
```
95104

96-
If while building from within an anaconda environment you come across errors similar to the following:
105+
Alternatively, the build process can build SoX (and codecs such as libmad, lame and flac) statically and torchaudio can link them, by setting environment variable `BUILD_SOX=1`.
106+
The build process will fetch and build SoX, liblame, libmad, flac before building extension.
97107

108+
```bash
109+
# Linux
110+
BUILD_SOX=1 python setup.py install
111+
112+
# OSX
113+
BUILD_SOX=1 MACOSX_DEPLOYMENT_TARGET=10.9 CC=clang CXX=clang++ python setup.py install
114+
```
115+
116+
This is known to work on linux and unix distributions such as Ubuntu and CentOS 7 and macOS.
117+
If you try this on a new system and found a solution to make it work, feel free to share it by opening and issue.
118+
119+
#### Troubleshooting
120+
121+
<Details><Summary>checking build system type... ./config.guess: unable to guess system type</Summary>
122+
123+
Since the configuration file for codecs are old, they cannot correctly detect the new environments, such as Jetson Aarch. You need to replace the `config.guess` file in `./third_party/tmp/lame-3.99.5/config.guess` and/or `./third_party/tmp/libmad-0.15.1b/config.guess` with [the latest one](https://github.com/gcc-mirror/gcc/blob/master/config.guess).
124+
125+
See also: [#658](https://github.com/pytorch/audio/issues/658)
126+
127+
</Details>
128+
129+
<Details><Summary>Undefined reference to `tgetnum' when using `BUILD_SOX`</Summary>
130+
131+
If while building from within an anaconda environment you come across errors similar to the following:
98132

99133
```
100134
../bin/ld: console.c:(.text+0xc1): undefined reference to `tgetnum'
@@ -107,6 +141,8 @@ Install `ncurses` from `conda-forge` before running `python setup.py install`:
107141
conda install -c conda-forge ncurses
108142
```
109143

144+
</Details>
145+
110146

111147
Quick Usage
112148
-----------

build_tools/setup_helpers/extension.py

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import os
12
import platform
23
import subprocess
34
from pathlib import Path
@@ -18,9 +19,21 @@
1819
_TP_BASE_DIR = _ROOT_DIR / 'third_party'
1920
_TP_INSTALL_DIR = _TP_BASE_DIR / 'build'
2021

21-
# Temporary fix for building in fbcode
22-
# at the moment, we have to use external sox in fbcode
23-
_BUILD_DEPS = not (_ROOT_DIR / '.use_external_sox').exists()
22+
23+
def _get_build_sox():
24+
val = os.environ.get('BUILD_SOX', '0')
25+
trues = ['1', 'true', 'TRUE', 'on', 'ON', 'yes', 'YES']
26+
falses = ['0', 'false', 'FALSE', 'off', 'OFF', 'no', 'NO']
27+
if val in trues:
28+
return True
29+
if val not in falses:
30+
print(
31+
f'WARNING: Unexpected environment variable value `BUILD_SOX={val}`. '
32+
f'Expected one of {trues + falses}')
33+
return False
34+
35+
36+
_BUILD_SOX = _get_build_sox()
2437

2538

2639
def _get_eca(debug):
@@ -52,14 +65,14 @@ def _get_include_dirs():
5265
dirs = [
5366
str(_ROOT_DIR),
5467
]
55-
if _BUILD_DEPS:
68+
if _BUILD_SOX:
5669
dirs.append(str(_TP_INSTALL_DIR / 'include'))
5770
return dirs
5871

5972

6073
def _get_extra_objects():
6174
objs = []
62-
if _BUILD_DEPS:
75+
if _BUILD_SOX:
6376
# NOTE: The order of the library listed bellow matters.
6477
#
6578
# (the most important thing is that dependencies come after a library
@@ -71,7 +84,7 @@ def _get_extra_objects():
7184

7285

7386
def _get_libraries():
74-
return [] if _BUILD_DEPS else ['sox']
87+
return [] if _BUILD_SOX else ['sox']
7588

7689

7790
def _build_codecs():
@@ -106,6 +119,6 @@ def get_ext_modules(debug=False):
106119

107120
class BuildExtension(TorchBuildExtension):
108121
def build_extension(self, ext):
109-
if ext.name == _EXT_NAME and _BUILD_DEPS:
122+
if ext.name == _EXT_NAME and _BUILD_SOX:
110123
_configure_third_party()
111124
super().build_extension(ext)

packaging/build_wheel.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@ if [[ "$OSTYPE" == "msys" ]]; then
1515
python_tag="$(echo "cp$PYTHON_VERSION" | tr -d '.')"
1616
python setup.py bdist_wheel --plat-name win_amd64 --python-tag $python_tag
1717
else
18-
python setup.py bdist_wheel
18+
BUILD_SOX=1 python setup.py bdist_wheel
1919
fi

packaging/torchaudio/build.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
#!/usr/bin/env bash
22
set -ex
33

4-
python setup.py install --single-version-externally-managed --record=record.txt
4+
BUILD_SOX=1 python setup.py install --single-version-externally-managed --record=record.txt

0 commit comments

Comments
 (0)