diff --git a/.github/workflows/nano_howto_guides_tests.yml b/.github/workflows/nano_howto_guides_tests.yml new file mode 100644 index 000000000000..4e023241c176 --- /dev/null +++ b/.github/workflows/nano_howto_guides_tests.yml @@ -0,0 +1,50 @@ +name: Nano Unit Tests for How-To Guides Notebooks + +on: + # Triggers the workflow on push or pull request events but only for the main branch + push: + branches: [ main ] + pull_request: + branches: [ main ] + paths: + #- 'python/nano/**' + - '.github/workflows/nano_howto_guides_tests.yml' + +# A workflow run is made up of one or more jobs that can run sequentially or in parallel +jobs: + nano-howto-guides-inference-test: + # The type of runner that the job will run on + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: ["ubuntu-20.04"] + python-version: ["3.7"] + + # Steps represent a sequence of tasks that will be executed as part of the job + steps: + # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it + - uses: actions/checkout@v2 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python-version }} + - name: Install dependencies + run: | + python -m pip install --upgrade pip + python -m pip install --upgrade setuptools==58.0.4 + python -m pip install --upgrade wheel + + - name: Run unit tests for Inference PyTorch how-to guides + shell: bash + run: | + $CONDA/bin/conda create -n howto-guides-inference-pytorch -y python==3.7.10 setuptools=58.0.4 + source $CONDA/bin/activate howto-guides-inference-pytorch + $CONDA/bin/conda info + bash python/nano/dev/build_and_install.sh linux default false pytorch + source bigdl-nano-init + bash python/nano/tutorial/notebook/inference/pytorch/run-nano-howto-guides-inference-pytorch-tests.sh + source $CONDA/bin/deactivate + $CONDA/bin/conda remove -n howto-guides-inference-pytorch --all + env: + ANALYTICS_ZOO_ROOT: ${{ github.workspace }} \ No newline at end of file diff --git a/python/nano/tutorial/notebook/inference/pytorch/run-nano-howto-guides-inference-pytorch-tests.sh b/python/nano/tutorial/notebook/inference/pytorch/run-nano-howto-guides-inference-pytorch-tests.sh new file mode 100644 index 000000000000..79dc52e14dcf --- /dev/null +++ b/python/nano/tutorial/notebook/inference/pytorch/run-nano-howto-guides-inference-pytorch-tests.sh @@ -0,0 +1,24 @@ +#!/bin/bash + +# export ANALYTICS_ZOO_ROOT=${ANALYTICS_ZOO_ROOT} +# export NANO_HOME=${ANALYTICS_ZOO_ROOT}/python/nano/src +export NANO_HOWTO_GUIDES_TEST_DIR=${ANALYTICS_ZOO_ROOT}/python/nano/tutorial/notebook/inference/pytorch + +set -e + +# the number of batches to run is limited for testing purposes +sed -i 's/Trainer(max_epochs=1)/Trainer(max_epochs=1, fast_dev_run=True)/' $NANO_HOWTO_GUIDES_TEST_DIR/quantize_pytorch_inference_inc.ipynb $NANO_HOWTO_GUIDES_TEST_DIR/quantize_pytorch_inference_pot.ipynb + +# comment out the install command for bigdl-nano[pytorch] +sed -i 's/!pip install --pre --upgrade bigdl-nano\[pytorch]/#!pip install --pre --upgrade bigdl-nano[pytorch]/' $NANO_HOWTO_GUIDES_TEST_DIR/* + +echo "Start testing" +start=$(date "+%s") + +python -m pytest -s --nbmake --nbmake-timeout=600 --nbmake-kernel=python3 ${NANO_HOWTO_GUIDES_TEST_DIR} + +now=$(date "+%s") +time=$((now-start)) + +echo "BigDL-Nano how-to guides tests finished." +echo "Time used: $time seconds"