Skip to content

Commit 45d671a

Browse files
authored
CI: split tests-examples (Lightning-AI#990)
* CI: split tests-examples * tests without template * comment depends * CircleCI typo * add doctest * update test req. * CI tests * setup macOS * longer train * lover pred acc * fix model * rename default model * lower tests acc * typo * imports * fix test optimizer * update calls * fix Win * lower Drone image * fix call * pytorch image * fix test * add dev image * add dev image * update image * drone volume * lint * update test notes * rename tests/models >> tests/base * group models * conftest * optim imports * typos * fix import * fix tests * install AMP * tests * fix import
1 parent ced662f commit 45d671a

40 files changed

+298
-282
lines changed

.circleci/config.yml

+21-4
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ references:
1111
name: Install Dependences
1212
command: |
1313
pip install "$TORCH_VERSION" --user
14-
# this is temporal fix til test-tube is not merged and released
1514
pip install -r requirements.txt --user
1615
sudo pip install pytest pytest-cov pytest-flake8
1716
pip install -r ./tests/requirements.txt --user
@@ -21,7 +20,16 @@ references:
2120
name: Testing
2221
command: |
2322
python --version ; pip --version ; pip list
24-
py.test pytorch_lightning tests pl_examples -v --doctest-modules --junitxml=test-reports/pytest_junit.xml
23+
py.test pytorch_lightning tests -v --doctest-modules --junitxml=test-reports/pytest_junit.xml
24+
no_output_timeout: 15m
25+
26+
examples: &examples
27+
run:
28+
name: PL Examples
29+
command: |
30+
pip install -r ./pl_examples/requirements.txt --user
31+
python --version ; pip --version ; pip list
32+
py.test pl_examples -v --doctest-modules --junitxml=test-reports/pytest_junit.xml
2533
no_output_timeout: 15m
2634

2735
install_pkg: &install_pkg
@@ -84,10 +92,8 @@ jobs:
8492
- TORCH_VERSION: "torch"
8593
steps: &steps
8694
- checkout
87-
8895
- *install_deps
8996
- *tests
90-
9197
- store_test_results:
9298
path: test-reports
9399
- store_artifacts:
@@ -121,6 +127,16 @@ jobs:
121127
- TORCH_VERSION: "torch>=1.4, <1.5"
122128
steps: *steps
123129

130+
Examples:
131+
docker:
132+
- image: circleci/python:3.7
133+
environment:
134+
- TORCH_VERSION: "torch"
135+
steps:
136+
- checkout
137+
- *install_deps
138+
- *examples
139+
124140
Install-pkg:
125141
docker:
126142
- image: circleci/python:3.7
@@ -141,3 +157,4 @@ workflows:
141157
- PyTorch-v1.3
142158
- PyTorch-v1.4
143159
- Install-pkg
160+
- Examples

.drone.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ name: torch-GPU
66

77
steps:
88
- name: testing
9-
image: nvcr.io/nvidia/pytorch:20.02-py3
9+
image: pytorch/pytorch:1.4-cuda10.1-cudnn7-runtime
1010
environment:
1111
SLURM_LOCALID: 0
1212
CODECOV_TOKEN:
@@ -16,12 +16,12 @@ steps:
1616
- pip install pip -U
1717
- pip --version
1818
- nvidia-smi
19-
#- pip install torch==1.3
19+
- bash ./tests/install_AMP.sh
2020
- pip install -r requirements.txt --user
2121
- pip install coverage pytest pytest-cov pytest-flake8 codecov
2222
- pip install -r ./tests/requirements.txt --user
2323
- pip list
2424
- python -c "import torch ; print(' & '.join([torch.cuda.get_device_name(i) for i in range(torch.cuda.device_count())]) if torch.cuda.is_available() else 'only CPU')"
25-
- coverage run --source pytorch_lightning -m py.test pytorch_lightning tests pl_examples -v --doctest-modules # --flake8
25+
- coverage run --source pytorch_lightning -m py.test pytorch_lightning tests -v --doctest-modules # --flake8
2626
- coverage report
2727
- codecov --token $CODECOV_TOKEN # --pr $DRONE_PULL_REQUEST --build $DRONE_BUILD_NUMBER --branch $DRONE_BRANCH --commit $DRONE_COMMIT --tag $DRONE_TAG

.github/workflows/ci-testing.yml

+8-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
python-version: [3.6, 3.7]
2424
requires: ['minimal', 'latest']
2525

26-
# https://stackoverflow.com/a/59076067/4521646
26+
# Timeout: https://stackoverflow.com/a/59076067/4521646
2727
timeout-minutes: 20
2828
steps:
2929
- uses: actions/checkout@v2
@@ -32,6 +32,12 @@ jobs:
3232
with:
3333
python-version: ${{ matrix.python-version }}
3434

35+
# Github Actions: Run step on specific OS: https://stackoverflow.com/a/57948488/4521646
36+
- name: Setup macOS
37+
if: runner.os == 'macOS'
38+
run: |
39+
brew install libomp # https://github.com/pytorch/pytorch/issues/20030
40+
3541
- name: Set min. dependencies
3642
if: matrix.requires == 'minimal'
3743
run: |
@@ -71,7 +77,7 @@ jobs:
7177
run: |
7278
# tox --sitepackages
7379
# flake8 .
74-
coverage run --source pytorch_lightning -m py.test pytorch_lightning tests pl_examples -v --doctest-modules --junitxml=junit/test-results-${{ runner.os }}-${{ matrix.python-version }}.xml
80+
coverage run --source pytorch_lightning -m py.test pytorch_lightning tests -v --doctest-modules --junitxml=junit/test-results-${{ runner.os }}-${{ matrix.python-version }}.xml
7581
coverage report
7682
7783
- name: Upload pytest test results

.markdownlint.yml

-2
This file was deleted.

.run_local_tests.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@ rm -rf ./tests/cometruns*
1212
rm -rf ./tests/wandb*
1313
rm -rf ./tests/tests/*
1414
rm -rf ./lightning_logs
15-
coverage run --source pytorch_lightning -m py.test pytorch_lightning tests pl_examples -v --doctest-modules --flake8
16-
coverage report -m
15+
python -m coverage run --source pytorch_lightning -m py.test pytorch_lightning tests pl_examples -v --doctest-modules --flake8
16+
python -m coverage report -m

environment.yml

+2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
# This is Conda environment file
12
# Usage: `conda env update -f environment.yml`
3+
24
channels:
35
- conda-forge
46
- pytorch

pl_examples/basic_examples/lightning_module_template.py

+18-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,24 @@
1919

2020
class LightningTemplateModel(LightningModule):
2121
"""
22-
Sample model to show how to define a template
22+
Sample model to show how to define a template.
23+
24+
Example:
25+
26+
>>> # define simple Net for MNIST dataset
27+
>>> params = dict(
28+
... drop_prob=0.2,
29+
... batch_size=2,
30+
... in_features=28 * 28,
31+
... learning_rate=0.001 * 8,
32+
... optimizer_name='adam',
33+
... data_root='./datasets',
34+
... out_features=10,
35+
... hidden_dim=1000,
36+
... )
37+
>>> from argparse import Namespace
38+
>>> hparams = Namespace(**params)
39+
>>> model = LightningTemplateModel(hparams)
2340
"""
2441

2542
def __init__(self, hparams):

pl_examples/full_examples/semantic_segmentation/models/unet/model.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ class UNet(nn.Module):
99
Link - https://arxiv.org/abs/1505.04597
1010
1111
Parameters:
12-
num_classes (int) - Number of output classes required (default 19 for KITTI dataset)
13-
bilinear (bool) - Whether to use bilinear interpolation or transposed
14-
convolutions for upsampling.
12+
num_classes (int) - Number of output classes required (default 19 for KITTI dataset)
13+
bilinear (bool) - Whether to use bilinear interpolation or transposed
14+
convolutions for upsampling.
1515
'''
1616

1717
def __init__(self, num_classes=19, bilinear=False):

pytorch_lightning/core/lightning.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
from typing import Any, Callable, Dict, List, Optional, Tuple, Union
88

99
import torch
10-
from torch import Tensor
1110
import torch.distributed as torch_distrib
11+
from torch import Tensor
1212
from torch.nn.parallel import DistributedDataParallel
1313
from torch.optim import Adam
1414
from torch.optim.optimizer import Optimizer

requirements-extra.txt

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# extended list of package dependencies to reach full functionality
2+
13
neptune-client>=0.4.4
24
comet-ml>=1.0.56
35
mlflow>=1.0.0

requirements.txt

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# the default package dependencies
2+
13
tqdm>=4.41.0
24
numpy>=1.16.4
35
torch>=1.1

setup.cfg

+8-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ norecursedirs =
55
build
66
python_files =
77
test_*.py
8-
doctest_plus = disabled
8+
# doctest_plus = disabled
99
addopts = --strict
1010
markers =
1111
slow
@@ -41,7 +41,7 @@ ignore =
4141
# setup.cfg or tox.ini
4242
[check-manifest]
4343
ignore =
44-
.travis.yml
44+
*.yml
4545
tox.ini
4646
.github
4747
.github/*
@@ -51,3 +51,9 @@ ignore =
5151
license_file = LICENSE
5252
# long_description = file:README.md
5353
# long_description_content_type = text/markdown
54+
55+
[pydocstyle]
56+
convention = pep257
57+
# D104, D107: Ignore missing docstrings in __init__ files and methods.
58+
# D202: Ignore a blank line after docstring (collision with Python Black in decorators)
59+
add-ignore = D104, D107, D202

tests/Dockerfile

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
ARG TORCH_VERSION=1.4
2+
ARG CUDA_VERSION=10.1
3+
4+
FROM pytorch/pytorch:${TORCH_VERSION}-cuda${CUDA_VERSION}-cudnn7-runtime
5+
6+
# Install AMP
7+
RUN bash ./tests/install_AMP.sh

tests/README.md

+3-5
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ To run all tests do the following:
1313
git clone https://github.com/PyTorchLightning/pytorch-lightning
1414
cd pytorch-lightning
1515

16-
# install module locally
17-
pip install -e .
16+
# install AMP support
17+
bash tests/install_AMP.sh
1818

1919
# install dev deps
2020
pip install -r tests/requirements.txt
@@ -36,15 +36,13 @@ Make sure to run coverage on a GPU machine with at least 2 GPUs and NVIDIA apex
3636
cd pytorch-lightning
3737

3838
# generate coverage (coverage is also installed as part of dev dependencies under tests/requirements.txt)
39-
pip install coverage
4039
coverage run --source pytorch_lightning -m py.test pytorch_lightning tests examples -v --doctest-modules
4140

4241
# print coverage stats
4342
coverage report -m
4443

45-
# exporting resulys
44+
# exporting results
4645
coverage xml
47-
codecov -t 17327163-8cca-4a5d-86c8-ca5f2ef700bc -v
4846
```
4947

5048

tests/base/__init__.py

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
"""Models for testing."""
2+
3+
import torch
4+
5+
from tests.base.models import TestModelBase, DictHparamsModel
6+
from tests.base.mixins import (
7+
LightEmptyTestStep,
8+
LightValidationStepMixin,
9+
LightValidationMixin,
10+
LightValidationStepMultipleDataloadersMixin,
11+
LightValidationMultipleDataloadersMixin,
12+
LightTestStepMixin,
13+
LightTestMixin,
14+
LightTestStepMultipleDataloadersMixin,
15+
LightTestMultipleDataloadersMixin,
16+
LightTestFitSingleTestDataloadersMixin,
17+
LightTestFitMultipleTestDataloadersMixin,
18+
LightValStepFitSingleDataloaderMixin,
19+
LightValStepFitMultipleDataloadersMixin,
20+
LightTrainDataloader,
21+
LightTestDataloader,
22+
LightInfTrainDataloader,
23+
LightInfValDataloader,
24+
LightInfTestDataloader,
25+
LightTestOptimizerWithSchedulingMixin,
26+
LightTestMultipleOptimizersWithSchedulingMixin,
27+
LightTestOptimizersWithMixedSchedulingMixin,
28+
LightTestReduceLROnPlateauMixin
29+
)
30+
31+
32+
class LightningTestModel(LightTrainDataloader,
33+
LightValidationMixin,
34+
LightTestMixin,
35+
TestModelBase):
36+
"""Most common test case. Validation and test dataloaders."""
37+
38+
def on_training_metrics(self, logs):
39+
logs['some_tensor_to_test'] = torch.rand(1)
40+
41+
42+
class LightningTestModelWithoutHyperparametersArg(LightningTestModel):
43+
""" without hparams argument in constructor """
44+
45+
def __init__(self):
46+
import tests.base.utils as tutils
47+
48+
# the user loads the hparams in some other way
49+
hparams = tutils.get_default_hparams()
50+
super().__init__(hparams)
51+
52+
53+
class LightningTestModelWithUnusedHyperparametersArg(LightningTestModelWithoutHyperparametersArg):
54+
""" has hparams argument in constructor but is not used """
55+
56+
def __init__(self, hparams):
57+
super().__init__()

tests/models/debug.py renamed to tests/base/debug.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88

99
# from test_models import assert_ok_test_acc, load_model, \
10-
# clear_save_dir, get_test_tube_logger, get_hparams, init_save_dir, \
10+
# clear_save_dir, get_default_testtube_logger, get_default_hparams, init_save_dir, \
1111
# init_checkpoint_callback, reset_seed, set_random_master_port
1212

1313

File renamed without changes.

tests/models/base.py renamed to tests/base/models.py

+3-37
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import os
22
from collections import OrderedDict
3+
from typing import Dict
34

45
import torch
56
import torch.nn as nn
@@ -8,7 +9,6 @@
89
from torch.utils.data import DataLoader
910
from torchvision import transforms
1011
from torchvision.datasets import MNIST
11-
from typing import Dict
1212

1313
try:
1414
from test_tube import HyperOptArgumentParser
@@ -174,9 +174,8 @@ def configure_optimizers(self):
174174
optimizer = optim.LBFGS(self.parameters(), lr=self.hparams.learning_rate)
175175
else:
176176
optimizer = optim.Adam(self.parameters(), lr=self.hparams.learning_rate)
177-
178-
# test returning only 1 list instead of 2
179-
return optimizer
177+
scheduler = optim.lr_scheduler.CosineAnnealingLR(optimizer, T_max=10)
178+
return [optimizer], [scheduler]
180179

181180
def prepare_data(self):
182181
transform = transforms.Compose([transforms.ToTensor(),
@@ -201,36 +200,3 @@ def _dataloader(self, train):
201200
)
202201

203202
return loader
204-
205-
@staticmethod
206-
def add_model_specific_args(parent_parser, root_dir): # pragma: no-cover
207-
"""
208-
Parameters you define here will be available to your model through self.hparams
209-
:param parent_parser:
210-
:param root_dir:
211-
:return:
212-
"""
213-
parser = HyperOptArgumentParser(strategy=parent_parser.strategy, parents=[parent_parser])
214-
215-
# param overwrites
216-
# parser.set_defaults(gradient_clip_val=5.0)
217-
218-
# network params
219-
parser.opt_list('--drop_prob', default=0.2, options=[0.2, 0.5], type=float, tunable=False)
220-
parser.add_argument('--in_features', default=28 * 28, type=int)
221-
parser.add_argument('--out_features', default=10, type=int)
222-
# use 500 for CPU, 50000 for GPU to see speed difference
223-
parser.add_argument('--hidden_dim', default=50000, type=int)
224-
# data
225-
parser.add_argument('--data_root', default=os.path.join(root_dir, 'mnist'), type=str)
226-
# training params (opt)
227-
parser.opt_list('--learning_rate', default=0.001 * 8, type=float,
228-
options=[0.0001, 0.0005, 0.001, 0.005], tunable=False)
229-
parser.opt_list('--optimizer_name', default='adam', type=str,
230-
options=['adam'], tunable=False)
231-
# if using 2 nodes with 4 gpus each the batch size here
232-
# (256) will be 256 / (2*8) = 16 per gpu
233-
parser.opt_list('--batch_size', default=256 * 8, type=int,
234-
options=[32, 64, 128, 256], tunable=False,
235-
help='batch size will be divided over all GPUs being used across all nodes')
236-
return parser

0 commit comments

Comments
 (0)