Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

Commit

Permalink
[DOC] Fix warnings in tutorials and turn on -W (#19624)
Browse files Browse the repository at this point in the history
  • Loading branch information
szha committed Dec 8, 2020
1 parent f8d3c14 commit 6cbd3ae
Show file tree
Hide file tree
Showing 82 changed files with 1,333 additions and 1,243 deletions.
40 changes: 22 additions & 18 deletions ci/docker/runtime_functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -712,6 +712,7 @@ sanity_cpp() {

sanity_python() {
set -ex
export DMLC_LOG_STACK_TRACE_DEPTH=100
python3 -m pylint --rcfile=ci/other/pylintrc --ignore-patterns=".*\.so$$,.*\.dll$$,.*\.dylib$$" python/mxnet
OMP_NUM_THREADS=$(expr $(nproc) / 4) pytest -n 4 tests/tutorials/test_sanity_tutorials.py
}
Expand All @@ -728,7 +729,7 @@ cd_unittest_ubuntu() {
export MXNET_SUBGRAPH_VERBOSE=0
export MXNET_ENABLE_CYTHON=0
export CD_JOB=1 # signal this is a CD run so any unecessary tests can be skipped
export DMLC_LOG_STACK_TRACE_DEPTH=10
export DMLC_LOG_STACK_TRACE_DEPTH=100

local mxnet_variant=${1:?"This function requires a mxnet variant as the first argument"}

Expand Down Expand Up @@ -767,7 +768,7 @@ unittest_ubuntu_python3_cpu() {
export MXNET_STORAGE_FALLBACK_LOG_VERBOSE=0
export MXNET_SUBGRAPH_VERBOSE=0
export MXNET_ENABLE_CYTHON=0
export DMLC_LOG_STACK_TRACE_DEPTH=10
export DMLC_LOG_STACK_TRACE_DEPTH=100
OMP_NUM_THREADS=$(expr $(nproc) / 4) pytest -m 'not serial' -k 'not test_operator' -n 4 --durations=50 --cov-report xml:tests_unittest.xml --verbose tests/python/unittest
MXNET_ENGINE_TYPE=NaiveEngine \
OMP_NUM_THREADS=$(expr $(nproc) / 4) pytest -m 'not serial' -k 'test_operator' -n 4 --durations=50 --cov-report xml:tests_unittest.xml --cov-append --verbose tests/python/unittest
Expand All @@ -781,7 +782,7 @@ unittest_ubuntu_python3_cpu_mkldnn() {
export MXNET_STORAGE_FALLBACK_LOG_VERBOSE=0
export MXNET_SUBGRAPH_VERBOSE=0
export MXNET_ENABLE_CYTHON=0
export DMLC_LOG_STACK_TRACE_DEPTH=10
export DMLC_LOG_STACK_TRACE_DEPTH=100
OMP_NUM_THREADS=$(expr $(nproc) / 4) pytest -m 'not serial' -k 'not test_operator' -n 4 --durations=50 --cov-report xml:tests_unittest.xml --verbose tests/python/unittest
MXNET_ENGINE_TYPE=NaiveEngine \
OMP_NUM_THREADS=$(expr $(nproc) / 4) pytest -m 'not serial' -k 'test_operator' -n 4 --durations=50 --cov-report xml:tests_unittest.xml --cov-append --verbose tests/python/unittest
Expand All @@ -797,7 +798,7 @@ unittest_ubuntu_python3_gpu() {
export MXNET_SUBGRAPH_VERBOSE=0
export CUDNN_VERSION=${CUDNN_VERSION:-7.0.3}
export MXNET_ENABLE_CYTHON=0
export DMLC_LOG_STACK_TRACE_DEPTH=10
export DMLC_LOG_STACK_TRACE_DEPTH=100
MXNET_GPU_MEM_POOL_TYPE=Unpooled \
OMP_NUM_THREADS=$(expr $(nproc) / 4) pytest -m 'not serial' -k 'not test_operator and not test_amp_init.py' -n 4 --durations=50 --cov-report xml:tests_gpu.xml --verbose tests/python/gpu
MXNET_GPU_MEM_POOL_TYPE=Unpooled \
Expand All @@ -816,7 +817,7 @@ unittest_ubuntu_python3_gpu_cython() {
export CUDNN_VERSION=${CUDNN_VERSION:-7.0.3}
export MXNET_ENABLE_CYTHON=1
export MXNET_ENFORCE_CYTHON=1
export DMLC_LOG_STACK_TRACE_DEPTH=10
export DMLC_LOG_STACK_TRACE_DEPTH=100
check_cython
MXNET_GPU_MEM_POOL_TYPE=Unpooled \
OMP_NUM_THREADS=$(expr $(nproc) / 4) pytest -m 'not serial' -k 'not test_operator and not test_amp_init.py' -n 4 --durations=50 --cov-report xml:tests_gpu.xml --verbose tests/python/gpu
Expand All @@ -834,7 +835,7 @@ unittest_ubuntu_python3_gpu_nocudnn() {
export MXNET_SUBGRAPH_VERBOSE=0
export CUDNN_OFF_TEST_ONLY=true
export MXNET_ENABLE_CYTHON=0
export DMLC_LOG_STACK_TRACE_DEPTH=10
export DMLC_LOG_STACK_TRACE_DEPTH=100
MXNET_GPU_MEM_POOL_TYPE=Unpooled \
OMP_NUM_THREADS=$(expr $(nproc) / 4) pytest -m 'not serial' -k 'not test_operator and not test_amp_init.py' -n 4 --durations=50 --cov-report xml:tests_gpu.xml --verbose tests/python/gpu
MXNET_GPU_MEM_POOL_TYPE=Unpooled \
Expand All @@ -846,13 +847,15 @@ unittest_ubuntu_python3_gpu_nocudnn() {

unittest_cpp() {
set -ex
export DMLC_LOG_STACK_TRACE_DEPTH=100
build/tests/mxnet_unit_tests
}

unittest_centos7_cpu() {
set -ex
source /opt/rh/rh-python36/enable
cd /work/mxnet
export DMLC_LOG_STACK_TRACE_DEPTH=100
OMP_NUM_THREADS=$(expr $(nproc) / 4) python -m pytest -m 'not serial' -k 'not test_operator' -n 4 --durations=50 --cov-report xml:tests_unittest.xml --verbose tests/python/unittest
MXNET_ENGINE_TYPE=NaiveEngine \
OMP_NUM_THREADS=$(expr $(nproc) / 4) python -m pytest -m 'not serial' -k 'test_operator' -n 4 --durations=50 --cov-report xml:tests_unittest.xml --cov-append --verbose tests/python/unittest
Expand All @@ -865,7 +868,7 @@ unittest_centos7_gpu() {
source /opt/rh/rh-python36/enable
cd /work/mxnet
export CUDNN_VERSION=${CUDNN_VERSION:-7.0.3}
export DMLC_LOG_STACK_TRACE_DEPTH=10
export DMLC_LOG_STACK_TRACE_DEPTH=100
MXNET_GPU_MEM_POOL_TYPE=Unpooled \
OMP_NUM_THREADS=$(expr $(nproc) / 4) pytest -m 'not serial' -k 'not test_operator and not test_amp_init.py' -n 4 --durations=50 --cov-report xml:tests_gpu.xml --cov-append --verbose tests/python/gpu
MXNET_GPU_MEM_POOL_TYPE=Unpooled \
Expand All @@ -879,7 +882,7 @@ integrationtest_ubuntu_cpu_onnx() {
set -ex
export PYTHONPATH=./python/
export MXNET_SUBGRAPH_VERBOSE=0
export DMLC_LOG_STACK_TRACE_DEPTH=10
export DMLC_LOG_STACK_TRACE_DEPTH=100
python3 tests/python/unittest/onnx/backend_test.py
OMP_NUM_THREADS=$(expr $(nproc) / 4) pytest -n 4 tests/python/unittest/onnx/mxnet_export_test.py
OMP_NUM_THREADS=$(expr $(nproc) / 4) pytest -n 4 tests/python/unittest/onnx/test_models.py
Expand All @@ -894,7 +897,7 @@ integrationtest_ubuntu_cpu_dist_kvstore() {
export MXNET_STORAGE_FALLBACK_LOG_VERBOSE=0
export MXNET_SUBGRAPH_VERBOSE=0
export MXNET_USE_OPERATOR_TUNING=0
export DMLC_LOG_STACK_TRACE_DEPTH=10
export DMLC_LOG_STACK_TRACE_DEPTH=100
cd tests/nightly/
python3 ../../tools/launch.py -n 7 --launcher local python3 dist_sync_kvstore.py --type=gluon_step_cpu
python3 ../../tools/launch.py -n 7 --launcher local python3 dist_sync_kvstore.py --type=gluon_sparse_step_cpu
Expand All @@ -910,6 +913,7 @@ integrationtest_ubuntu_cpu_dist_kvstore() {

integrationtest_ubuntu_gpu_dist_kvstore() {
set -ex
export DMLC_LOG_STACK_TRACE_DEPTH=100
pushd .
cd /work/mxnet/python
pip3 install -e .
Expand All @@ -929,7 +933,7 @@ integrationtest_ubuntu_gpu_byteps() {
git clone -b v0.2.3 https://github.com/bytedance/byteps ~/byteps
export MXNET_STORAGE_FALLBACK_LOG_VERBOSE=0
export MXNET_SUBGRAPH_VERBOSE=0
export DMLC_LOG_STACK_TRACE_DEPTH=10
export DMLC_LOG_STACK_TRACE_DEPTH=100
cd tests/nightly/

export NVIDIA_VISIBLE_DEVICES=0
Expand All @@ -952,7 +956,7 @@ test_ubuntu_cpu_python3() {
set -ex
pushd .
export MXNET_LIBRARY_PATH=/work/build/libmxnet.so
export DMLC_LOG_STACK_TRACE_DEPTH=10
export DMLC_LOG_STACK_TRACE_DEPTH=100
VENV=mxnet_py3_venv
virtualenv -p `which python3` $VENV
source $VENV/bin/activate
Expand All @@ -976,7 +980,7 @@ unittest_ubuntu_python3_arm() {
export MXNET_STORAGE_FALLBACK_LOG_VERBOSE=0
export MXNET_SUBGRAPH_VERBOSE=0
export MXNET_ENABLE_CYTHON=0
export DMLC_LOG_STACK_TRACE_DEPTH=10
export DMLC_LOG_STACK_TRACE_DEPTH=100
python3 -m pytest -n 2 --verbose tests/python/unittest/test_engine.py
}

Expand Down Expand Up @@ -1010,31 +1014,31 @@ test_rat_check() {
nightly_test_KVStore_singleNode() {
set -ex
export PYTHONPATH=./python/
export DMLC_LOG_STACK_TRACE_DEPTH=10
export DMLC_LOG_STACK_TRACE_DEPTH=100
tests/nightly/test_kvstore.py
}

#Test Large Tensor Size
nightly_test_large_tensor() {
set -ex
export PYTHONPATH=./python/
export DMLC_LOG_STACK_TRACE_DEPTH=10
export DMLC_LOG_STACK_TRACE_DEPTH=100
pytest --timeout=0 --forked tests/nightly/test_np_large_array.py
}

#Tests Model backwards compatibility on MXNet
nightly_model_backwards_compat_test() {
set -ex
export PYTHONPATH=/work/mxnet/python/
export DMLC_LOG_STACK_TRACE_DEPTH=10
export DMLC_LOG_STACK_TRACE_DEPTH=100
./tests/nightly/model_backwards_compatibility_check/model_backward_compat_checker.sh
}

#Backfills S3 bucket with models trained on earlier versions of mxnet
nightly_model_backwards_compat_train() {
set -ex
export PYTHONPATH=./python/
export DMLC_LOG_STACK_TRACE_DEPTH=10
export DMLC_LOG_STACK_TRACE_DEPTH=100
./tests/nightly/model_backwards_compatibility_check/train_mxnet_legacy_models.sh
}

Expand All @@ -1043,7 +1047,7 @@ nightly_tutorial_test_ubuntu_python3_gpu() {
cd /work/mxnet/docs
export BUILD_VER=tutorial
export MXNET_DOCS_BUILD_MXNET=0
export DMLC_LOG_STACK_TRACE_DEPTH=10
export DMLC_LOG_STACK_TRACE_DEPTH=100
make html
export MXNET_STORAGE_FALLBACK_LOG_VERBOSE=0
export MXNET_SUBGRAPH_VERBOSE=0
Expand All @@ -1055,7 +1059,7 @@ nightly_tutorial_test_ubuntu_python3_gpu() {

nightly_estimator() {
set -ex
export DMLC_LOG_STACK_TRACE_DEPTH=10
export DMLC_LOG_STACK_TRACE_DEPTH=100
cd /work/mxnet/tests/nightly/estimator
export PYTHONPATH=/work/mxnet/python/
pytest test_estimator_cnn.py
Expand Down
Binary file added docs/python_docs/_static/autograd_gradient.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion docs/python_docs/python/Makefile_sphinx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ endif # $(NUMJOBS)
# End number of processors detection

# You can set these variables from the command line.
SPHINXOPTS = -j$(NPROCS) -c ../scripts --keep-going
SPHINXOPTS = -j$(NPROCS) -c ../scripts --keep-going -W
SPHINXBUILD = sphinx-build
PAPER =
BUILDDIR = _build
Expand Down
1 change: 0 additions & 1 deletion docs/python_docs/python/api/gluon/rnn/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ Build-in recurrent neural network layers are provided in the following two modul
:nosignatures:

mxnet.gluon.rnn
mxnet.gluon.contrib.rnn

.. currentmodule:: mxnet.gluon

Expand Down
35 changes: 30 additions & 5 deletions docs/python_docs/python/api/kvstore/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,34 @@
specific language governing permissions and limitations
under the License.
mxnet.kvstore
=============
KVStore: Communication for Distributed Training
===============================================
.. currentmodule:: mxnet.kvstore

.. automodule:: mxnet.kvstore
:members:
:autosummary:

Horovod
=======

.. autosummary::
:toctree: generated/

Horovod

BytePS
======

.. autosummary::
:toctree: generated/

BytePS


KVStore Interface
=================

.. autosummary::
:toctree: generated/

KVStore
KVStoreBase
KVStoreServer
1 change: 1 addition & 0 deletions docs/python_docs/python/api/npx/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ More operators
sigmoid
smooth_l1
softmax
log_softmax
topk
waitall
load
Expand Down
12 changes: 6 additions & 6 deletions docs/python_docs/python/tutorials/deploy/export/onnx.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ In this tutorial, we will learn how to use MXNet to ONNX exporter on pre-trained
## Prerequisites

To run the tutorial you will need to have installed the following python modules:
- [MXNet >= 1.3.0](/get_started)
- [MXNet >= 1.3.0](https://mxnet.apache.org/get_started)
- [onnx]( https://github.com/onnx/onnx#installation) v1.2.1 (follow the install guide)

*Note:* MXNet-ONNX importer and exporter follows version 7 of ONNX operator set which comes with ONNX v1.2.1.
Expand All @@ -44,7 +44,7 @@ logging.basicConfig(level=logging.INFO)

## Downloading a model from the MXNet model zoo

We download the pre-trained ResNet-18 [ImageNet](http://www.image-net.org/) model from the [MXNet Model Zoo](/api/python/docs/api/gluon/model_zoo/index.html).
We download the pre-trained ResNet-18 [ImageNet](http://www.image-net.org/) model from the [MXNet Model Zoo](../../../api/gluon/model_zoo/index.rst).
We will also download synset file to match labels.

```{.python .input}
Expand All @@ -59,7 +59,7 @@ Now, we have downloaded ResNet-18 symbol, params and synset file on the disk.

## MXNet to ONNX exporter API

Let us describe the MXNet's `export_model` API.
Let us describe the MXNet's `export_model` API.

```{.python .input}
help(onnx_mxnet.export_model)
Expand All @@ -74,7 +74,7 @@ export_model(sym, params, input_shape, input_type=<type 'numpy.float32'>, onnx_f
Exports the MXNet model file, passed as a parameter, into ONNX model.
Accepts both symbol,parameter objects as well as json and params filepaths as input.
Operator support and coverage - https://cwiki.apache.org/confluence/display/MXNET/MXNet-ONNX+Integration
Parameters
----------
sym : str or symbol object
Expand All @@ -89,7 +89,7 @@ export_model(sym, params, input_shape, input_type=<type 'numpy.float32'>, onnx_f
Path where to save the generated onnx file
verbose : Boolean
If true will print logs of the model conversion
Returns
-------
onnx_file_path : str
Expand Down Expand Up @@ -145,6 +145,6 @@ model_proto = onnx.load_model(converted_model_path)
checker.check_graph(model_proto.graph)
```

If the converted protobuf format doesn't qualify to ONNX proto specifications, the checker will throw errors, but in this case it successfully passes.
If the converted protobuf format doesn't qualify to ONNX proto specifications, the checker will throw errors, but in this case it successfully passes.

This method confirms exported model protobuf is valid. Now, the model is ready to be imported in other frameworks for inference!
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ Apache MXNet is an open-source deep learning framework that provides a comprehen

#### Tensors A.K.A Arrays

Tensors give us a generic way of describing $n$-dimensional **arrays** with an arbitrary number of axes. Vectors, for example, are first-order tensors, and matrices are second-order tensors. Tensors with more than two orders(axes) do not have special mathematical names. The [ndarray](https://mxnet.apache.org/versions/1.7/api/python/docs/api/ndarray/index.html) package in MXNet provides a tensor implementation. This class is similar to NumPy's ndarray with additional features. First, MXNet’s `NDArray` supports fast execution on a wide range of hardware configurations, including CPU, GPU, and multi-GPU machines where as NumPy only supports CPU computation. Second, MXNet’s `NDArray` executes code lazily, allowing it to automatically parallelize multiple operations across the available hardware.
Tensors give us a generic way of describing $n$-dimensional **arrays** with an arbitrary number of axes. Vectors, for example, are first-order tensors, and matrices are second-order tensors. Tensors with more than two orders(axes) do not have special mathematical names. The [NP](../../../api/np/index.rst) package in MXNet provides a NumPy-compatible tensor implementation, `np.ndarray` with additional features. First, MXNet’s `np.ndarray` supports fast execution on a wide range of hardware configurations, including CPU, GPU, and multi-GPU machines where as NumPy only supports CPU computation. Second, MXNet’s `np.ndarray` executes code lazily, allowing it to automatically parallelize multiple operations across the available hardware.

You will get familiar to arrays in the [next section](1-nparray.md) of this crash course.
You will get familiar to arrays in the [next section](./1-nparray.ipynb) of this crash course.

### Computing paradigms

Expand All @@ -44,9 +44,9 @@ You will get familiar to arrays in the [next section](1-nparray.md) of this cras
Neural network designs like [ResNet-152](https://www.cv-foundation.org/openaccess/content_cvpr_2016/papers/He_Deep_Residual_Learning_CVPR_2016_paper.pdf) have a fair degree of regularity. They consist of _blocks_ of repeated (or at least similarly designed) layers; these blocks then form the basis of more complex network designs. A block can be a single layer, a component consisting of multiple layers, or the entire complex neural network itself! One benefit of working with the block abstraction is that you can combine blocks into larger artifacts; often recursively. By defining code to generate blocks of arbitrary complexity on demand, you can write surprisingly compact code and still implement complex neural networks.


From a programming standpoint, a block is represented by a class and [Block](https://mxnet.apache.org/versions/1.7/api/python/docs/api/gluon/nn/index.html#mxnet.gluon.nn.Block) is the base class for all neural networks layers in MXNet. Any subclass of it must define a forward propagation function that transforms its input into output and must store any necessary parameters if required.
From a programming standpoint, a block is represented by a class and [Block](../../../api/gluon/block.rst#mxnet.gluon.Block) is the base class for all neural networks layers in MXNet. Any subclass of it must define a forward propagation function that transforms its input into output and must store any necessary parameters if required.

You will see more about blocks in [Array](1-nparray.md) and [Create neural network](2-create-nn.md) sections.
You will see more about blocks in [Array](./1-nparray.ipynb) and [Create neural network](./2-create-nn.ipynb) sections.

#### HybridBlock

Expand All @@ -62,7 +62,7 @@ You can learn more about the difference between symbolic vs. imperative programm

When designing MXNet, developers considered whether it was possible to harness the benefits of both imperative and symbolic programming. The developers believed that users should be able to develop and debug using pure imperative programming, while having the ability to convert most programs into symbolic programming to be run when product-level computing performance and deployment are required.

In hybrid programming, you can build models using either the [HybridBlock](https://mxnet.apache.org/versions/1.7/api/python/docs/api/gluon/hybrid_block.html) or the [HybridSequential](https://mxnet.apache.org/versions/1.6/api/python/docs/api/gluon/nn/index.html#mxnet.gluon.nn.HybridSequential) and [HybridConcurrent](https://mxnet.incubator.apache.org/versions/1.7/api/python/docs/api/gluon/contrib/index.html#mxnet.gluon.contrib.nn.HybridConcurrent) classes. By default, they are executed in the same way Block or Sequential and Concurrent classes are executed in imperative programming. When the `hybridize` function is called, Gluon will convert the program’s execution into the style used in symbolic programming. This allows one to optimize the compute-intensive components without sacrifices in the way a model is implemented. In fact, most models can make use of hybrid programming’s execution style.
In hybrid programming, you can build models using either the [HybridBlock](../../../api/gluon/hybrid_block.rst#mxnet.gluon.HybridBlock) or the [HybridSequential](../../../api/gluon/nn/index.rst#mxnet.gluon.nn.HybridSequential) and [HybridConcatenate](../../../api/gluon/nn/index.rst#mxnet.gluon.nn.HybridConcatenate) classes. By default, they are executed in the same way [Block](../../../api/gluon/block.rst#mxnet.gluon.Block) or [Sequential](../../../api/gluon/nn/index.rst#mxnet.gluon.nn.Sequential) and [Concurrent](../../../api/gluon/nn/index.rst#mxnet.gluon.nn.Concatenate) classes are executed in imperative programming. When the `hybridize` function is called, Gluon will convert the program’s execution into the style used in symbolic programming. This allows one to optimize the compute-intensive components without sacrifices in the way a model is implemented. In fact, most models can make use of hybrid programming’s execution style.

You will learn more about hybrid blocks and use them in the upcoming sections of the course.

Expand All @@ -72,7 +72,7 @@ Gluon is an imperative high-level front end API in MXNet for deep learning that

## Next steps

Dive deeper on [array representations](1-nparray.md) in MXNet.
Dive deeper on [array representations](./1-nparray.ipynb) in MXNet.

## References
1. [Dive into Deep Learning](http://d2l.ai/)

0 comments on commit 6cbd3ae

Please sign in to comment.