-
Notifications
You must be signed in to change notification settings - Fork 6.8k
[MXNET-545] Fix broken cython build #10951
Changes from 37 commits
9d47eed
b3a9784
feecd35
fcc41a0
771a9b6
df1a291
0000950
86d1c90
f8a7b8c
646ea91
64057b3
5aaa8ad
1f4d53a
d252bea
cbae43d
be0744a
40ba9de
b5b0a54
c798d38
206e706
939e9ce
6df4e28
741d088
b32b8a6
9a526ec
17286a4
0d4a2aa
238f40c
7284615
57c3410
48039a2
96ed71f
991dd8c
d779ec9
5922f88
2fbe3fe
ed1e126
430f38d
e3ad1ca
58c2754
d0ef6fe
8140a4d
5093d83
868b170
bf798c9
4bca56c
e602d88
7dd3fa6
d80fc68
bc838c8
8cb0e62
94f5427
f6cee03
c505bf0
17f6c70
8ccc5f2
c6d1e49
786b2fd
e02cc4f
fc6f843
aa64c42
c90570c
a2bb2e1
d89de2f
2297f34
2cc7e85
2b8628c
efd5bd2
927ca1a
d02b89b
df89ef3
17a702c
8375dfe
d5f6fe6
c1480f5
fdf344f
7036d9b
e81dba9
92ea420
fcf5986
064f56f
b30ba00
aea2d41
9965e4c
371a8c6
9adca4d
09efb2b
61387bc
10d817c
adce15e
d7bdf63
83f5a1e
550ae4a
2253b76
95f42bd
f42fd0a
4ed7657
e81093a
9c836bc
4be2da6
0dce3f9
ec37d87
d5de9c4
11e30ca
d8c435c
bc526f2
25a3dfd
e300834
8dbc12f
10bc51e
a6005c7
db80ee7
a5ad3c0
1443088
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,6 +33,18 @@ clean_repo() { | |
git submodule update --init --recursive | ||
} | ||
|
||
check_cython() { | ||
set -ex | ||
local python_ver=$1 | ||
if [ "$(echo -e 'import mxnet as mx\nprint(mx.nd._internal.NDArrayBase.__module__)' | python${python_ver})" != "mxnet._cy${python_ver}.ndarray" ]; then | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we use python -c and move it before the conditional? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I couldn't figure out how to run multiline code with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess doesn't make a difference. Can we store in a variable with propper name? It's difficult to read inside the if condition. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I updated the code trying to be more clear. |
||
echo "ERROR: cython is not used." | ||
return 1 | ||
else | ||
echo "NOTE: cython is used." | ||
return 0 | ||
fi | ||
} | ||
|
||
build_ccache_wrappers() { | ||
set -ex | ||
|
||
|
@@ -343,6 +355,11 @@ build_ubuntu_cpu_openblas() { | |
-j$(nproc) | ||
|
||
report_ccache_usage | ||
|
||
export CC="gcc" | ||
export CXX="g++" | ||
make cython PYTHON=python2 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ccache doesn't work? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
make cython PYTHON=python3 | ||
} | ||
|
||
build_ubuntu_cpu_clang39() { | ||
|
@@ -484,6 +501,9 @@ build_ubuntu_gpu_cuda91_cudnn7() { | |
USE_CPP_PACKAGE=1 \ | ||
USE_DIST_KVSTORE=1 \ | ||
-j$(nproc) | ||
|
||
make cython PYTHON=python2 | ||
make cython PYTHON=python3 | ||
} | ||
|
||
build_ubuntu_amalgamation() { | ||
|
@@ -575,6 +595,19 @@ unittest_ubuntu_python3_cpu() { | |
nosetests-3.4 $NOSE_COVERAGE_ARGUMENTS --with-xunit --xunit-file nosetests_quantization.xml --verbose tests/python/quantization | ||
} | ||
|
||
unittest_ubuntu_python3_cython_cpu() { | ||
set -ex | ||
export PYTHONPATH=./python/ | ||
# MXNET_MKLDNN_DEBUG is buggy and produces false positives | ||
# /~https://github.com/apache/incubator-mxnet/issues/10026 | ||
#export MXNET_MKLDNN_DEBUG=1 # Ignored if not present | ||
export MXNET_STORAGE_FALLBACK_LOG_VERBOSE=0 | ||
export MXNET_ENFORCE_CYTHON=1 | ||
check_cython 3 | ||
nosetests-3.4 --with-xunit --xunit-file nosetests_unittest.xml --verbose tests/python/unittest | ||
nosetests-3.4 --with-xunit --xunit-file nosetests_quantization.xml --verbose tests/python/quantization | ||
} | ||
|
||
unittest_ubuntu_python3_cpu_mkldnn() { | ||
set -ex | ||
export PYTHONPATH=./python/ | ||
|
@@ -596,6 +629,18 @@ unittest_ubuntu_python2_gpu() { | |
nosetests-2.7 $NOSE_COVERAGE_ARGUMENTS --with-xunit --xunit-file nosetests_gpu.xml --verbose tests/python/gpu | ||
} | ||
|
||
unittest_ubuntu_python2_cython_gpu() { | ||
set -ex | ||
export PYTHONPATH=./python/ | ||
# MXNET_MKLDNN_DEBUG is buggy and produces false positives | ||
# /~https://github.com/apache/incubator-mxnet/issues/10026 | ||
#export MXNET_MKLDNN_DEBUG=1 # Ignored if not present | ||
export MXNET_STORAGE_FALLBACK_LOG_VERBOSE=0 | ||
export MXNET_ENFORCE_CYTHON=1 | ||
check_cython 2 | ||
nosetests-2.7 --with-xunit --xunit-file nosetests_gpu.xml --verbose tests/python/gpu | ||
} | ||
|
||
tutorialtest_ubuntu_python3_gpu() { | ||
set -ex | ||
cd /work/mxnet/docs | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -137,6 +137,19 @@ When USE_PROFILER is enabled in Makefile or CMake, the following environments ca | |
- If set to '0', profiler records the events of the symbolic operators. | ||
- If set to '1', profiler records the events of all operators. | ||
|
||
## Interface between Python and the C API | ||
|
||
* MXNET_ENABLE_CYTHON | ||
- Values: 0(false), 1(true) ```(default=1)``` | ||
- If set to 0, MXNet uses the ctypes to interface with the C API. | ||
- If set to 1, MXNet tries to use the cython modules for the ndarray and symbol. If it fails, the ctypes is used or an error occurs depending on MXNET_ENFORCE_CYTHON. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Cool! |
||
|
||
* MXNET_ENFORCE_CYTHON | ||
- Values: 0(false) or 1(true) ```(default=0)``` | ||
- This has an effect only if MXNET_ENABLE_CYTHON is 1. | ||
- If set to 0, MXNet fallbacks to the ctypes if importing the cython modules fails. | ||
- If set to 1, MXNet raises an error if importing the cython modules fails. | ||
|
||
## Other Environment Variables | ||
|
||
* MXNET_CUDNN_AUTOTUNE_DEFAULT | ||
|
@@ -146,7 +159,7 @@ When USE_PROFILER is enabled in Makefile or CMake, the following environments ca | |
- Performance tests are run to pick the convolution algo when value is 1 or 2 | ||
- Value of 1 chooses the best algo in a limited workspace | ||
- Value of 2 chooses the fastest algo whose memory requirements may be larger than the default workspace threshold | ||
|
||
|
||
* MXNET_GLUON_REPO | ||
- Values: String ```(default='https://apache-mxnet.s3-accelerate.dualstack.amazonaws.com/'``` | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -459,7 +459,16 @@ $ make -j $(nproc) USE_OPENCV=1 USE_BLAS=openblas | |
$ sudo apt-get install -y python-dev python-setuptools python-pip libgfortran3 | ||
``` | ||
|
||
**Step 2** Install the MXNet Python binding. | ||
**Step 2** Build cython modules (optional). | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we please add instructions for Mac and Windows users? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unfortunately I'm not familiar with Windows/Mac and also don't have environments to test. I think this needs help from others. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @sandeep-krishnamurthy maybe we can start with Linux only, and leverage other's help to support Mac and Windows? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes we can iteratively update. |
||
|
||
```bash | ||
$ sudo apt-get install -y cython | ||
$ make cython # You can set the python executable with `PYTHON` flag, e.g., make cython PYTHON=python3 | ||
``` | ||
|
||
Note that you can control the use of the cython modules at runtime via the environment variables `MXNET_ENABLE_CYTHON` and `MXNET_ENFORCE_CYTHON`. See [here](/faq/env_var.html) for details. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If user is building Cython in this step, then I think we can assume he wants to use Cython. Can we also provide steps to set the environment variables here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for good ideas. I updated the docs. |
||
|
||
**Step 3** Install the MXNet Python binding. | ||
|
||
```bash | ||
$ cd python | ||
|
@@ -468,13 +477,13 @@ $ pip install -e . | |
|
||
Note that the `-e` flag is optional. It is equivalent to `--editable` and means that if you edit the source files, these changes will be reflected in the package installed. | ||
|
||
**Step 3** Install [Graphviz](http://www.graphviz.org/). (Optional, needed for graph visualization using `mxnet.viz` package). | ||
**Step 4** Install [Graphviz](http://www.graphviz.org/). (Optional, needed for graph visualization using `mxnet.viz` package). | ||
```bash | ||
sudo apt-get install graphviz | ||
pip install graphviz | ||
``` | ||
|
||
**Step 4** Validate the installation by running simple MXNet code described [here](#validate-mxnet-installation). | ||
**Step 5** Validate the installation by running simple MXNet code described [here](#validate-mxnet-installation). | ||
|
||
</div><!-- END of build from source --> | ||
</div><!-- END of CPU --> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we have a default value for PYTHON?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, the default is just
python
. It is defined inmake/config.mk
.