Skip to content

Fixed mypy failures on the CI #5263

Fixed mypy failures on the CI

Fixed mypy failures on the CI #5263

Workflow file for this run

name: Run unit tests
on:
push:
branches:
- master
- "*.*.*"
paths:
- "ignite/**"
- "tests/ignite/**"
- "tests/run_cpu_tests.sh"
- "tests/run_code_style.sh"
- "examples/**.py"
- "requirements-dev.txt"
- ".github/workflows/unit-tests.yml"
pull_request:
paths:
- "ignite/**"
- "tests/ignite/**"
- "tests/run_cpu_tests.sh"
- "tests/run_code_style.sh"
- "examples/**.py"
- "requirements-dev.txt"
- ".github/workflows/unit-tests.yml"
workflow_dispatch:
concurrency:
# <workflow_name>-<branch_name>-<true || commit_sha (if branch is protected)>
group: unit-tests-${{ github.ref_name }}-${{ !(github.ref_protected) || github.sha }}
cancel-in-progress: true
jobs:
cpu-tests:
runs-on: ${{ matrix.os }}
timeout-minutes: 85
defaults:
run:
shell: bash
strategy:
max-parallel: 10
fail-fast: false
matrix:
os: [ubuntu-latest]
python-version: ["3.9", "3.10", "3.11", "3.12"]
pytorch-channel: [pytorch, pytorch-nightly]
include:
# includes a single build on windows
- os: windows-latest
pytorch-channel: pytorch
python-version: 3.11
skip-distrib-tests: 1
# includes a single build on macosx
- os: macos-latest
pytorch-channel: pytorch
python-version: 3.11
skip-distrib-tests: 1
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Get year & week number
id: get-date
run: |
echo "date=$(/bin/date "+%Y-%U")" >> $GITHUB_OUTPUT
- name: Get pip cache dir
id: pip-cache
run: |
pip install -U pip || python -m pip install -U pip
echo "pip_cache=$(pip cache dir)" >> $GITHUB_OUTPUT
- uses: actions/cache@v3
with:
path: |
${{ steps.pip-cache.outputs.pip_cache }}
key: ${{ steps.get-date.outputs.date }}-pytorch-${{ runner.os }}-${{ matrix.python-version }}-${{ matrix.pytorch-channel }}-${{ hashFiles('requirements-dev.txt') }}
restore-keys: |
${{ steps.get-date.outputs.date }}-pytorch-${{ runner.os }}-${{ matrix.python-version }}-${{ matrix.pytorch-channel }}-
- run: pip install pip wheel setuptools -Uqq
- name: Install PyTorch
if: ${{ matrix.pytorch-channel == 'pytorch' }}
run: pip install torch torchvision --index-url https://download.pytorch.org/whl/cpu
- name: Install PyTorch (nightly)
if: ${{ matrix.pytorch-channel == 'pytorch-nightly' }}
run: pip install torch torchvision --index-url https://download.pytorch.org/whl/nightly/cpu --pre
- name: Install dependencies
run: |
pip install -r requirements-dev.txt
python setup.py install
pip list
- name: Check code formatting
run: |
bash ./tests/run_code_style.sh install
bash ./tests/run_code_style.sh lint
- name: Run Mypy
# https://github.com/pytorch/ignite/pull/2780
#
if: ${{ matrix.os == 'ubuntu-latest' && matrix.pytorch-channel == 'pytorch-nightly'}}
run: |
bash ./tests/run_code_style.sh mypy
# Download MNIST: https://github.com/pytorch/ignite/issues/1737
# to "/tmp" for unit tests
- name: Download MNIST
uses: pytorch-ignite/download-mnist-github-action@master
with:
target_dir: /tmp
# Copy MNIST to "." for the examples
- name: Copy MNIST
run: |
cp -R /tmp/MNIST .
- name: Run Tests
uses: nick-fields/retry@v3
with:
max_attempts: 5
timeout_minutes: 15
shell: bash
command: SKIP_DISTRIB_TESTS=${{ matrix.skip-distrib-tests }} bash tests/run_cpu_tests.sh
new_command_on_retry: USE_LAST_FAILED=1 SKIP_DISTRIB_TESTS=${{ matrix.skip-distrib-tests }} bash tests/run_cpu_tests.sh
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
with:
file: ./coverage.xml
flags: cpu
fail_ci_if_error: false
- name: Run MNIST Examples
run: |
# MNIST
# 1) mnist.py
python examples/mnist/mnist.py --epochs=1
- name: Run MNIST with loggers Examples
if: ${{ matrix.os == 'ubuntu-latest' }}
run: |
# 2) mnist_with_visdom.py
python -c "from visdom.server.build 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.1) mnist_with_tensorboard.py with tbX
python examples/mnist/mnist_with_tensorboard.py --epochs=1
# 3.2) mnist_with_tensorboard.py with native torch tb
pip uninstall -y tensorboardX
python examples/mnist/mnist_with_tensorboard.py --epochs=1
- name: Run MNIST Example With Crash
if: ${{ matrix.os == 'ubuntu-latest' }}
continue-on-error: true
run: |
# 4) mnist_save_resume_engine.py
python examples/mnist/mnist_save_resume_engine.py --epochs=2 --crash_iteration 1100
- name: Resume MNIST from previous crash
if: ${{ matrix.os == 'ubuntu-latest' }}
run: |
python examples/mnist/mnist_save_resume_engine.py --epochs=2 --resume_from=/tmp/mnist_save_resume/checkpoint_1.pt
- name: Run GAN example
if: ${{ matrix.os == 'ubuntu-latest' }}
run: |
# 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
if: ${{ matrix.os == 'ubuntu-latest' }}
run: |
# 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
if: ${{ matrix.os == 'ubuntu-latest' }}
run: |
#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
- name: Run SR Example
if: ${{ matrix.os == 'ubuntu-latest' }}
run: |
# Super-Resolution
python examples/super_resolution/main.py --upscale_factor 3 --crop_size 180 --batch_size 4 --test_batch_size 100 --n_epochs 1 --lr 0.001 --threads 2 --debug