Skip to content

Commit

Permalink
Enable Github CI (#762)
Browse files Browse the repository at this point in the history
* Add GitHub actions

* Add contrib dependencies

* Optional install for pynvml

* Check python version for pynvml

* Update unittests.yml

* Disable fail fast strategy

* Update test_gpu_info.py

* Update test_gpu_info.py

* Update test_gpu_info.py

* add conda and nightlies

* Add Python 3.8 and allow more parallel runs

* Update unittests.yml

* Update unittests.yml

* Update unittests.yml

* Update unittests.yml

* Update unittests.yml

* Update unittests.yml

* Update unittests.yml

* Update unittests.yml

* Update unittests.yml

* Update unittests.yml

* Update unittests.yml

* Update unittests.yml

* Make examples different steps

* Update unittests.yml

* Update unittests.yml

* Update unittests.yml

* Update test_gpu_info.py

Co-authored-by: vfdev <vfdev.5@gmail.com>
  • Loading branch information
justusschock and vfdev-5 committed Feb 1, 2020
1 parent 6d80eeb commit 918746b
Show file tree
Hide file tree
Showing 2 changed files with 111 additions and 4 deletions.
104 changes: 104 additions & 0 deletions .github/workflows/unittests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
on: [pull_request]

jobs:
build:
runs-on: ubuntu-latest
strategy:
max-parallel: 10
fail-fast: false
matrix:
python-version: [3.5, 3.6, 3.7, 3.8]
pytorch-channel: [pytorch, pytorch-nightly]

steps:
- uses: actions/checkout@v1
- name: Setup Conda
run: |
wget https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh -O miniconda.sh
bash miniconda.sh -b -p $HOME/miniconda
export PATH="$HOME/miniconda/bin:$PATH"
conda config --set always_yes yes --set changeps1 no
conda update -q conda
# Useful for debugging any issues with conda
conda info -a
conda create -q -n test-environment pytorch cpuonly torchvision python=${{ matrix.python-version }} -c ${{ matrix.pytorch-channel }}
- name: Install dependencies
run: |
export PATH="$HOME/miniconda/bin:$PATH"
source activate test-environment
pip install -U pip wheel;
# Contrib dependencies
pip install tqdm scikit-learn matplotlib tensorboardX visdom polyaxon-client mlflow neptune-client tensorboard
if [[ ${{ matrix.python-version }} != 3.5 ]]; then pip install pynvml; fi
pip install numpy pytest codecov pytest-cov pytest-xdist
pip install .
# example dependencies
pip install pandas gym
- name: Run Tests
run: |
export PATH="$HOME/miniconda/bin:$PATH"
source activate test-environment
CUDA_VISIBLE_DEVICES="" py.test --tx 4*popen//python=python${{ matrix.python-version }} --cov ignite --cov-report term-missing -vvv tests/
# - name: Upload coverage to Codecov
# uses: codecov/codecov-action@v1.0.2
# with:
# token: ${{secrets.CODECOV_TOKEN}} #required
# file: ./coverage.xml #optional
# flags: unittests #optional
# name: codecov-rising #optional

- name: Run MNIST Examples
run: |
export PATH="$HOME/miniconda/bin:$PATH"
source activate test-environment
# MNIST
# 1) mnist.py
python examples/mnist/mnist.py --epochs=1
# 2) mnist_with_visdom.py
python -c "from visdom.server import download_scripts; download_scripts()" # download scripts : https://github.com/facebookresearch/visdom/blob/master/py/server.py#L929
python -m visdom.server &
sleep 10
python examples/mnist/mnist_with_visdom.py --epochs=1
kill %1
# 3) mnist_with_tensorboardx.py
python examples/mnist/mnist_with_tensorboardx.py --epochs=1
- name: Run MNIST Example With Crash
continue-on-error: true
run: |
export PATH="$HOME/miniconda/bin:$PATH"
source activate test-environment
# 4) mnist_save_resume_engine.py
python examples/mnist/mnist_save_resume_engine.py --epochs=1 --crash_iteration 700
- name: Resume MNIST from previous crash
run: |
export PATH="$HOME/miniconda/bin:$PATH"
source activate test-environment
python examples/mnist/mnist_save_resume_engine.py --epochs=1 --resume_from=/tmp/mnist_save_resume/checkpoint_550.pth
- name: Run GAN example
run: |
export PATH="$HOME/miniconda/bin:$PATH"
source activate test-environment
# DCGAN
python examples/gan/dcgan.py --dataset fake --dataroot /tmp/fakedata --output-dir /tmp/outputs-dcgan --batch-size 2 --epochs 2 --workers 0
- name: Run RL Examples
run: |
export PATH="$HOME/miniconda/bin:$PATH"
source activate test-environment
# RL
# 1) Actor-Critic
python examples/reinforcement_learning/actor_critic.py --max-episodes=2
# 2) Reinforce
python examples/reinforcement_learning/reinforce.py --max-episodes=2
- name: Run Neural Style Example
run: |
export PATH="$HOME/miniconda/bin:$PATH"
source activate test-environment
#fast-neural-style
#train
mkdir -p ~/.cache/torch/checkpoints/ && wget "https://download.pytorch.org/models/vgg16-397923af.pth" -O ~/.cache/torch/checkpoints/vgg16-397923af.pth
python examples/fast_neural_style/neural_style.py train --epochs 1 --cuda 0 --dataset test --dataroot . --image_size 32 --style_image examples/fast_neural_style/images/style_images/mosaic.jpg --style_size 32
11 changes: 7 additions & 4 deletions tests/ignite/contrib/metrics/test_gpu_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import pytest
from unittest.mock import Mock, patch

python_below_36 = (sys.version[0] == '3' and int(sys.version[2]) < 6) or int(sys.version[0]) < 2


@pytest.fixture
def no_site_packages():
Expand All @@ -23,14 +25,15 @@ def no_site_packages():
sys.modules['pynvml'] = pynvml_module


@pytest.mark.skipif(sys.version[0] == "2", reason="No pynvml for python 2.7")
@pytest.mark.skipif(python_below_36,
reason="No pynvml for python < 3.6")
def test_no_pynvml_package(no_site_packages):

with pytest.raises(RuntimeError, match="This contrib module requires pynvml to be installed."):
GpuInfo()


@pytest.mark.skipif(sys.version[0] == "2" or torch.cuda.is_available(), reason="No pynvml for python 2.7")
@pytest.mark.skipif(python_below_36 or torch.cuda.is_available(), reason="No pynvml for python < 3.6")
def test_no_gpu():

with pytest.raises(RuntimeError, match="This contrib module requires available GPU"):
Expand Down Expand Up @@ -73,8 +76,8 @@ def _test_gpu_info(device='cpu'):
assert int(util_report['gpu_util']) == engine.state.metrics['gpu:0 util(%)']


@pytest.mark.skipif(sys.version[0] == "2" or not (torch.cuda.is_available()),
reason="No pynvml for python 2.7 and no GPU")
@pytest.mark.skipif(python_below_36 or not (torch.cuda.is_available()),
reason="No pynvml for python < 3.6 and no GPU")
def test_gpu_info():
_test_gpu_info(device='cuda')

Expand Down

0 comments on commit 918746b

Please sign in to comment.