Skip to content

Commit

Permalink
Pure package & base tests (#2418)
Browse files Browse the repository at this point in the history
* base tests

* pil

* wip

* wip

* wip

* ignore

* ignore

* win

* link

* win

* cpu

* Apply suggestions from code review

Co-authored-by: Adrian Wälchli <aedu.waelchli@gmail.com>

Co-authored-by: Adrian Wälchli <aedu.waelchli@gmail.com>
  • Loading branch information
Borda and awaelchli committed Jun 30, 2020
1 parent 145670f commit e268061
Show file tree
Hide file tree
Showing 8 changed files with 156 additions and 17 deletions.
87 changes: 87 additions & 0 deletions .github/workflows/ci-test-base.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
name: CI base testing

# see: https://help.github.com/en/actions/reference/events-that-trigger-workflows
on:
# Trigger the workflow on push or pull request,
# but only for the master branch
push:
branches:
- master
pull_request:
branches:
- master
# Trigger the workflow on push or pull request
# on: [push, pull_request]

jobs:
doctest:

runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
# max-parallel: 6
matrix:
os: [ubuntu-20.04, windows-2019, macOS-10.15]
python-version: [3.7]

# Timeout: https://stackoverflow.com/a/59076067/4521646
timeout-minutes: 20
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}

# Github Actions: Run step on specific OS: https://stackoverflow.com/a/57948488/4521646
- name: Setup macOS
if: runner.os == 'macOS'
run: |
brew install libomp # https://github.com/pytorch/pytorch/issues/20030
# Note: This uses an internal pip API and may not always work
# https://github.com/actions/cache/blob/master/examples.md#multiple-oss-in-a-workflow
- name: Get pip cache
id: pip-cache
run: |
python -c "from pip._internal.locations import USER_CACHE_DIR; print('::set-output name=dir::' + USER_CACHE_DIR)"
- name: Cache pip
uses: actions/cache@v1
with:
path: ${{ steps.pip-cache.outputs.dir }}
key: ${{ runner.os }}-${{ matrix.python-version }}-${{ matrix.requires }}-pip-${{ hashFiles('requirements/base.txt') }}
restore-keys: |
${{ runner.os }}-${{ matrix.python-version }}-${{ matrix.requires }}-pip-
- name: Install dependencies
run: |
python -m pip install --upgrade --user pip
pip install --requirement ./requirements/base.txt --quiet --find-links https://download.pytorch.org/whl/cpu/torch_stable.html --upgrade-strategy only-if-needed
pip install --requirement ./requirements/test.txt --quiet --upgrade-strategy only-if-needed
# pip install tox coverage
python --version
pip --version
pip list
shell: bash

- name: Cache datasets
uses: actions/cache@v1
with:
path: Datasets # This path is specific to Ubuntu
# Look to see if there is a cache hit for the corresponding requirements file
key: PL-dataset

- name: Test Package [only]
run: |
# NOTE: run coverage on tests does not propagare faler status for Win, https://github.com/nedbat/coveragepy/issues/1003
python -m pytest pytorch_lightning -v --junitxml=junit/test-results-${{ runner.os }}-${{ matrix.python-version }}-${{ matrix.requires }}.xml --ignore=pytorch_lightning/loggers/comet.py --ignore=pytorch_lightning/loggers/mlflow.py --ignore=pytorch_lightning/loggers/neptune.py --ignore=pytorch_lightning/loggers/test_tube.py --ignore=pytorch_lightning/loggers/wandb.py --ignore=pytorch_lightning/metrics/sklearns.py
# coverage report
- name: Upload pytest test results
uses: actions/upload-artifact@master
with:
name: pytest-results-${{ runner.os }}-${{ matrix.python-version }}-${{ matrix.requires }}
path: junit/test-results-${{ runner.os }}-${{ matrix.python-version }}-${{ matrix.requires }}.xml
# Use always() to always run this step to publish test results when there are test failures
if: always()
6 changes: 3 additions & 3 deletions .github/workflows/ci-testing.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: CI testing
name: CI complete testing

# see: https://help.github.com/en/actions/reference/events-that-trigger-workflows
on:
Expand Down Expand Up @@ -89,8 +89,8 @@ jobs:
- name: Install dependencies
run: |
# python -m pip install --upgrade --user pip
pip install -r requirements/base.txt -U -f https://download.pytorch.org/whl/torch_stable.html --quiet
HOROVOD_BUILD_ARCH_FLAGS="-mfma" pip install -r ./requirements/devel.txt --quiet
pip install --requirement requirements/base.txt --find-links https://download.pytorch.org/whl/cpu/torch_stable.html --quiet --upgrade-strategy only-if-needed
HOROVOD_BUILD_ARCH_FLAGS="-mfma" pip install --requirement ./requirements/devel.txt --quiet --upgrade-strategy "only-if-needed"
python --version
pip --version
pip list
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/code-formatting.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ jobs:
- name: Install dependencies
run: |
# python -m pip install --upgrade --user pip
pip install -r requirements/base.txt -U -f https://download.pytorch.org/whl/torch_stable.html --quiet
HOROVOD_BUILD_ARCH_FLAGS="-mfma" pip install -r ./requirements/devel.txt --quiet
pip install --requirement requirements/base.txt --upgrade-strategy only-if-needed --find-links https://download.pytorch.org/whl/cpu/torch_stable.html --quiet
HOROVOD_BUILD_ARCH_FLAGS="-mfma" pip install --requirement ./requirements/devel.txt --quiet
# pip install tox coverage
python --version ; pip --version ; pip list
shell: bash
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/docs-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ jobs:
- name: Install dependencies
run: |
# python -m pip install --upgrade --user pip
pip install -r requirements/base.txt -U -f https://download.pytorch.org/whl/torch_stable.html --quiet
pip install -r requirements/extra.txt
pip install -r requirements/docs.txt
pip install --requirement requirements/base.txt --upgrade-strategy only-if-needed --find-links https://download.pytorch.org/whl/cpu/torch_stable.html --quiet
pip install --requirement requirements/extra.txt
pip install --requirement requirements/docs.txt
python --version ; pip --version ; pip list
shell: bash

Expand Down Expand Up @@ -76,8 +76,8 @@ jobs:
- name: Install dependencies
run: |
pip install -r requirements/base.txt -U -f https://download.pytorch.org/whl/torch_stable.html --quiet
pip install -r requirements/docs.txt
pip install --requirement requirements/base.txt --upgrade-strategy only-if-needed --find-links https://download.pytorch.org/whl/cpu/torch_stable.html --quiet
pip install --requirement requirements/docs.txt
# install Texlive, see https://linuxconfig.org/how-to-install-latex-on-ubuntu-20-04-focal-fossa-linux
sudo apt-get update && sudo apt-get install -y texlive-latex-extra dvipng texlive-pictures
python --version ; pip --version ; pip list
Expand Down
5 changes: 2 additions & 3 deletions docs/source/weights_loading.rst
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,8 @@ But if you don't want to use the values saved in the checkpoint, pass in your ow

def __init__(self, in_dim, out_dim):
super().__init__()
self.in_dim = in_dim
self.out_dim = out_dim
self.l1 = nn.Linear(self.in_dim, self.out_dim)
self.save_hyperparameters()
self.l1 = nn.Linear(self.hparams.in_dim, self.hparams.out_dim)

you can restore the model like this

Expand Down
3 changes: 1 addition & 2 deletions pytorch_lightning/loggers/neptune.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from argparse import Namespace
from typing import Optional, List, Dict, Any, Union, Iterable

from PIL.Image import Image

try:
import neptune
Expand Down Expand Up @@ -312,7 +311,7 @@ def log_text(self, log_name: str, text: str, step: Optional[int] = None) -> None
@rank_zero_only
def log_image(self,
log_name: str,
image: Union[str, Image, Any],
image: Union[str, Any],
step: Optional[int] = None) -> None:
"""
Log image data in Neptune experiment
Expand Down
54 changes: 54 additions & 0 deletions pytorch_lightning/trainer/trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,60 @@ class Trainer(
TrainerDeprecatedAPITillVer0_9,
TrainerDeprecatedAPITillVer0_10,
):
"""
Example:
>>> import torch
>>> from torch.nn import functional as F
>>> from torch.utils.data import Dataset, DataLoader
>>> # Define model
>>> class SimpleModel(LightningModule):
... def __init__(self):
... super().__init__()
... self.l1 = torch.nn.Linear(in_features=64, out_features=4)
...
... def forward(self, x):
... return torch.relu(self.l1(x.view(x.size(0), -1)))
...
... def training_step(self, batch, batch_nb):
... x, y = batch
... loss = F.cross_entropy(self(x), y)
... return {'loss': loss, 'log': {'train_loss': loss}}
...
... def test_step(self, batch, batch_nb):
... x, y = batch
... loss = F.cross_entropy(self(x), y)
... return {'loss': loss, 'log': {'train_loss': loss}}
...
... def configure_optimizers(self):
... return torch.optim.Adam(self.parameters(), lr=0.02)
...
>>> # Define dataset
>>> class SimpleDataset(Dataset):
... def __init__(self, num_samples=200):
... self.input_seq = torch.randn(num_samples, 64)
... self.output_seq = torch.randint(0, 4, (num_samples,))
...
... def __len__(self):
... return len(self.input_seq)
...
... def __getitem__(self, item):
... return self.input_seq[item], self.output_seq[item]
...
>>> train_loader = DataLoader(SimpleDataset(), batch_size=8)
>>> model = SimpleModel()
>>> # Define Trainer and fit model
>>> trainer = Trainer(max_epochs=1, progress_bar_refresh_rate=0)
>>> trainer.fit(model, train_loader)
1
>>> trainer.test(model, train_loader) # doctest: +ELLIPSIS +NORMALIZE_WHITESPACE
--------------------------------------------------------------------------------
TEST RESULTS
...
--------------------------------------------------------------------------------
"""
DEPRECATED_IN_0_9 = ('use_amp', 'show_progress_bar', 'training_tqdm_dict', 'num_tpu_cores')

def __init__(
Expand Down
4 changes: 2 additions & 2 deletions requirements/base.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# the default package dependencies

numpy>=1.15 # because some BLAS compilation issues
tqdm>=4.41.0
torch>=1.3
tensorboard>=1.14
future>=0.17.1 # required for builtins in setup.py
# pyyaml>=3.13
PyYAML>=5.1 # OmegaConf requirement
PyYAML>=5.1 # OmegaConf requirement
tqdm>=4.41.0

0 comments on commit e268061

Please sign in to comment.