2018-04-23 11:20:05 -07:00
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#pylint: disable=no-member, too-many-locals, too-many-branches, no-self-use, broad-except, lost-exception, too-many-nested-blocks, too-few-public-methods, invalid-name
"""
This file tests and ensures that all tutorials notebooks run
without warning or exception.
env variable MXNET_TUTORIAL_TEST_KERNEL controls which kernel to use
when running the notebook. e.g:
`export MXNET_TUTORIAL_TEST_KERNEL=python2`
env variable MXNET_TUTORIAL_TEST_NO_CACHE controls whether to clean the
temporary directory in which the notebook was run and re-download any
resource file. The default behaviour is to not clean the directory. Set to ' 1 '
to force clean the directory. e.g:
`export MXNET_TUTORIAL_TEST_NO_CACHE=1`
NB: in the real CI, the tests will re-download everything since they start from
a clean workspace.
"""
import os
import sys
2018-07-24 13:23:01 -07:00
sys . path . insert ( 0 , os . path . join ( os . path . dirname ( __file__ ) , ' .. ' , ' utils ' ) )
from notebook_test import run_notebook
2018-04-23 11:20:05 -07:00
2019-09-19 22:17:04 -07:00
# This is outdated and need to be completely redone.
2018-07-24 13:23:01 -07:00
TUTORIAL_DIR = os . path . join ( os . path . dirname ( __file__ ) , ' .. ' , ' .. ' , ' docs ' , ' _build ' , ' html ' , ' tutorials ' )
KERNEL = os . getenv ( ' MXNET_TUTORIAL_TEST_KERNEL ' , None )
NO_CACHE = os . getenv ( ' MXNET_TUTORIAL_TEST_NO_CACHE ' , False )
2018-04-23 11:20:05 -07:00
def _test_tutorial_nb ( tutorial ) :
2018-07-24 13:23:01 -07:00
""" Run tutorial Jupyter notebook to catch any execution error.
2018-04-23 11:20:05 -07:00
Parameters
----------
tutorial : str
2018-07-24 13:23:01 -07:00
the name of the tutorial to be tested
2018-04-23 11:20:05 -07:00
2018-07-24 13:23:01 -07:00
Returns
-------
True if there are no warnings or errors.
"""
return run_notebook ( tutorial , TUTORIAL_DIR , kernel = KERNEL , no_cache = NO_CACHE )
2018-04-23 11:20:05 -07:00
def test_basic_ndarray ( ) :
assert _test_tutorial_nb ( ' basic/ndarray ' )
def test_basic_ndarray_indexing ( ) :
assert _test_tutorial_nb ( ' basic/ndarray_indexing ' )
def test_basic_symbol ( ) :
assert _test_tutorial_nb ( ' basic/symbol ' )
def test_basic_module ( ) :
assert _test_tutorial_nb ( ' basic/module ' )
def test_basic_data ( ) :
assert _test_tutorial_nb ( ' basic/data ' )
2018-12-13 20:02:24 -08:00
def test_basic_reshape_transpose ( ) :
assert _test_tutorial_nb ( ' basic/reshape_transpose ' )
2018-04-23 11:20:05 -07:00
def test_gluon_customop ( ) :
assert _test_tutorial_nb ( ' gluon/customop ' )
2018-04-24 10:47:34 -07:00
def test_gluon_custom_layer ( ) :
assert _test_tutorial_nb ( ' gluon/custom_layer ' )
2019-06-19 15:38:05 -07:00
def test_gluon_transforms ( ) :
assert _test_tutorial_nb ( ' gluon/transforms ' )
2018-04-23 11:20:05 -07:00
def test_gluon_data_augmentation ( ) :
assert _test_tutorial_nb ( ' gluon/data_augmentation ' )
def test_gluon_datasets ( ) :
assert _test_tutorial_nb ( ' gluon/datasets ' )
def test_gluon_naming ( ) :
assert _test_tutorial_nb ( ' gluon/naming ' )
def test_gluon_ndarray ( ) :
assert _test_tutorial_nb ( ' gluon/ndarray ' )
def test_gluon_mnist ( ) :
assert _test_tutorial_nb ( ' gluon/mnist ' )
def test_gluon_autograd ( ) :
assert _test_tutorial_nb ( ' gluon/autograd ' )
def test_gluon_gluon ( ) :
assert _test_tutorial_nb ( ' gluon/gluon ' )
2019-06-14 09:55:41 -07:00
def test_gluon_multi_gpu ( ) :
assert _test_tutorial_nb ( ' gluon/multi_gpu ' )
2018-11-07 15:16:40 -08:00
def test_gluon_save_load_params ( ) :
2018-06-06 21:52:48 -07:00
assert _test_tutorial_nb ( ' gluon/save_load_params ' )
2018-04-23 11:20:05 -07:00
def test_gluon_hybrid ( ) :
assert _test_tutorial_nb ( ' gluon/hybrid ' )
2023-01-04 04:09:23 -08:00
# https://github.com/apache/mxnet/issues/16181
2019-09-16 17:26:13 -07:00
"""
2019-07-03 09:31:49 -07:00
def test_gluon_performance():
assert _test_tutorial_nb( ' gluon/performance ' )
2019-09-16 17:26:13 -07:00
"""
2018-05-17 21:25:56 -07:00
def test_gluon_pretrained_models ( ) :
assert _test_tutorial_nb ( ' gluon/pretrained_models ' )
2018-07-04 14:13:37 -07:00
def test_gluon_learning_rate_finder ( ) :
assert _test_tutorial_nb ( ' gluon/learning_rate_finder ' )
2018-06-26 09:54:06 -07:00
def test_gluon_learning_rate_schedules ( ) :
assert _test_tutorial_nb ( ' gluon/learning_rate_schedules ' )
2018-04-23 11:20:05 -07:00
2018-06-26 09:54:06 -07:00
def test_gluon_learning_rate_schedules_advanced ( ) :
assert _test_tutorial_nb ( ' gluon/learning_rate_schedules_advanced ' )
2018-11-07 15:16:40 -08:00
2018-11-15 15:08:19 -08:00
def test_gluon_info_gan ( ) :
assert _test_tutorial_nb ( ' gluon/info_gan ' )
2019-08-01 15:09:04 -07:00
def test_gluon_fit_api_fashion_mnist ( ) :
assert _test_tutorial_nb ( ' gluon/fit_api_tutorial ' )
2018-04-23 11:20:05 -07:00
def test_nlp_cnn ( ) :
assert _test_tutorial_nb ( ' nlp/cnn ' )
def test_onnx_super_resolution ( ) :
assert _test_tutorial_nb ( ' onnx/super_resolution ' )
2018-08-23 13:27:27 -07:00
def test_onnx_export_mxnet_to_onnx ( ) :
assert _test_tutorial_nb ( ' onnx/export_mxnet_to_onnx ' )
2018-04-23 11:20:05 -07:00
def test_onnx_fine_tuning_gluon ( ) :
assert _test_tutorial_nb ( ' onnx/fine_tuning_gluon ' )
def test_onnx_inference_on_onnx_model ( ) :
assert _test_tutorial_nb ( ' onnx/inference_on_onnx_model ' )
2018-07-24 13:23:01 -07:00
def test_python_linear_regression ( ) :
2018-04-23 11:20:05 -07:00
assert _test_tutorial_nb ( ' python/linear-regression ' )
2018-07-25 15:52:38 -07:00
def test_python_logistic_regression ( ) :
assert _test_tutorial_nb ( ' gluon/logistic_regression_explained ' )
2018-08-29 08:43:41 -07:00
def test_python_numpy_gotchas ( ) :
assert _test_tutorial_nb ( ' gluon/gotchas_numpy_in_mxnet ' )
2019-01-24 11:35:14 -08:00
def test_gluon_end_to_end ( ) :
assert _test_tutorial_nb ( ' gluon/gluon_from_experiment_to_deployment ' )
2018-04-23 11:20:05 -07:00
def test_python_mnist ( ) :
assert _test_tutorial_nb ( ' python/mnist ' )
def test_python_predict_image ( ) :
assert _test_tutorial_nb ( ' python/predict_image ' )
def test_python_data_augmentation ( ) :
assert _test_tutorial_nb ( ' python/data_augmentation ' )
def test_python_data_augmentation_with_masks ( ) :
assert _test_tutorial_nb ( ' python/data_augmentation_with_masks ' )
def test_python_kvstore ( ) :
assert _test_tutorial_nb ( ' python/kvstore ' )
2019-03-21 10:41:41 -07:00
def test_module_to_gluon ( ) :
assert _test_tutorial_nb ( ' python/module_to_gluon ' )
2018-04-23 11:20:05 -07:00
def test_python_types_of_data_augmentation ( ) :
assert _test_tutorial_nb ( ' python/types_of_data_augmentation ' )
2023-01-04 04:09:23 -08:00
#https://github.com/apache/mxnet/issues/16181
2019-09-16 17:26:13 -07:00
"""
2018-06-26 09:54:06 -07:00
def test_python_profiler():
assert _test_tutorial_nb( ' python/profiler ' )
2019-09-16 17:26:13 -07:00
"""
2018-04-23 11:20:05 -07:00
def test_sparse_row_sparse ( ) :
assert _test_tutorial_nb ( ' sparse/row_sparse ' )
def test_sparse_csr ( ) :
assert _test_tutorial_nb ( ' sparse/csr ' )
def test_sparse_train ( ) :
assert _test_tutorial_nb ( ' sparse/train ' )
2019-07-03 20:13:32 -07:00
def test_sparse_train_gluon ( ) :
assert _test_tutorial_nb ( ' sparse/train_gluon ' )
2018-04-23 11:20:05 -07:00
def test_speech_recognition_ctc ( ) :
assert _test_tutorial_nb ( ' speech_recognition/ctc ' )
def test_unsupervised_learning_gan ( ) :
assert _test_tutorial_nb ( ' unsupervised_learning/gan ' )
def test_vision_large_scale_classification ( ) :
assert _test_tutorial_nb ( ' vision/large_scale_classification ' )
2018-05-24 11:00:48 -07:00
def test_vision_cnn_visualization ( ) :
2018-07-24 13:23:01 -07:00
assert _test_tutorial_nb ( ' vision/cnn_visualization ' )
2018-08-27 11:59:13 -07:00
def test_control_flow ( ) :
assert _test_tutorial_nb ( ' control_flow/ControlFlowTutorial ' )
2019-05-20 20:21:26 -07:00
def test_amp ( ) :
assert _test_tutorial_nb ( ' amp/amp_tutorial ' )
2023-01-04 04:09:23 -08:00
# https://github.com/apache/mxnet/issues/16181
2019-09-16 17:26:13 -07:00
"""
2021-10-13 22:48:10 +02:00
def test_dnnl_quantization():
assert _test_tutorial_nb( ' dnnl/dnnl_quantization ' )
2019-09-16 17:26:13 -07:00
"""