Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CI: fix examples - patch download MNIST #6357

Merged
merged 6 commits into from
Mar 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions .github/workflows/ci_test-full.yml
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,9 @@ jobs:
# NOTE: do not include coverage report here, see: https://github.com/nedbat/coveragepy/issues/1003
coverage run --source pytorch_lightning -m pytest pytorch_lightning tests -v --durations=50 --junitxml=junit/test-results-${{ runner.os }}-${{ matrix.python-version }}-${{ matrix.requires }}.xml

# todo: put this back just when TorchVision can download datasets
#- name: Examples
# run: |
# python -m pytest pl_examples -v --durations=10
- name: Examples
run: |
python -m pytest pl_examples -v --durations=10

- name: Upload pytest test results
uses: actions/upload-artifact@v2
Expand Down
16 changes: 9 additions & 7 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,12 @@ jobs:
python -m pytest benchmarks -v --maxfail=2 --durations=0
displayName: 'Testing: benchmarks'

# todo: put this back just when TorchVision can download datasets
#- bash: |
# python -m pytest pl_examples -v --maxfail=2 --durations=0
# python setup.py install --user --quiet
# bash pl_examples/run_ddp-example.sh
# pip uninstall -y pytorch-lightning
# displayName: 'Examples'
- bash: |
python -m pytest pl_examples -v --maxfail=2 --durations=0
python setup.py install --user --quiet
bash pl_examples/run_ddp-example.sh
cd pl_examples/basic_examples
bash submit_ddp_job.sh
bash submit_ddp2_job.sh
pip uninstall -y pytorch-lightning
displayName: 'Examples'
16 changes: 16 additions & 0 deletions pl_examples/__init__.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,30 @@
import os
from urllib.error import HTTPError

from six.moves import urllib

from pytorch_lightning.utilities import _module_available

# TorchVision hotfix https://github.com/pytorch/vision/issues/1938
opener = urllib.request.build_opener()
opener.addheaders = [('User-agent', 'Mozilla/5.0')]
urllib.request.install_opener(opener)
Borda marked this conversation as resolved.
Show resolved Hide resolved

_EXAMPLES_ROOT = os.path.dirname(__file__)
_PACKAGE_ROOT = os.path.dirname(_EXAMPLES_ROOT)
_DATASETS_PATH = os.path.join(_PACKAGE_ROOT, 'Datasets')

_TORCHVISION_AVAILABLE = _module_available("torchvision")
_TORCHVISION_MNIST_AVAILABLE = True
_DALI_AVAILABLE = _module_available("nvidia.dali")

if _TORCHVISION_AVAILABLE:
try:
from torchvision.datasets.mnist import MNIST
MNIST(_DATASETS_PATH, download=True)
except HTTPError:
_TORCHVISION_MNIST_AVAILABLE = False

LIGHTNING_LOGO = """
####
###########
Expand Down
4 changes: 2 additions & 2 deletions pl_examples/basic_examples/autoencoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
from torch.utils.data import DataLoader, random_split

import pytorch_lightning as pl
from pl_examples import _DATASETS_PATH, _TORCHVISION_AVAILABLE, cli_lightning_logo
from pl_examples import _DATASETS_PATH, _TORCHVISION_AVAILABLE, _TORCHVISION_MNIST_AVAILABLE, cli_lightning_logo

if _TORCHVISION_AVAILABLE:
if _TORCHVISION_AVAILABLE and _TORCHVISION_MNIST_AVAILABLE:
from torchvision import transforms
from torchvision.datasets.mnist import MNIST
else:
Expand Down
4 changes: 2 additions & 2 deletions pl_examples/basic_examples/backbone_image_classifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
from torch.utils.data import DataLoader, random_split

import pytorch_lightning as pl
from pl_examples import _DATASETS_PATH, _TORCHVISION_AVAILABLE, cli_lightning_logo
from pl_examples import _DATASETS_PATH, _TORCHVISION_AVAILABLE, _TORCHVISION_MNIST_AVAILABLE, cli_lightning_logo

if _TORCHVISION_AVAILABLE:
if _TORCHVISION_AVAILABLE and _TORCHVISION_MNIST_AVAILABLE:
from torchvision import transforms
from torchvision.datasets.mnist import MNIST
else:
Expand Down
12 changes: 9 additions & 3 deletions pl_examples/basic_examples/dali_image_classifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,15 @@
from torch.utils.data import random_split

import pytorch_lightning as pl
from pl_examples import _DALI_AVAILABLE, _DATASETS_PATH, _TORCHVISION_AVAILABLE, cli_lightning_logo

if _TORCHVISION_AVAILABLE:
from pl_examples import (
_DALI_AVAILABLE,
_DATASETS_PATH,
_TORCHVISION_AVAILABLE,
_TORCHVISION_MNIST_AVAILABLE,
cli_lightning_logo,
)

if _TORCHVISION_AVAILABLE and _TORCHVISION_MNIST_AVAILABLE:
from torchvision import transforms
from torchvision.datasets.mnist import MNIST
else:
Expand Down
4 changes: 2 additions & 2 deletions pl_examples/basic_examples/mnist_datamodule.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@

from torch.utils.data import DataLoader, random_split

from pl_examples import _DATASETS_PATH, _TORCHVISION_AVAILABLE
from pl_examples import _DATASETS_PATH, _TORCHVISION_AVAILABLE, _TORCHVISION_MNIST_AVAILABLE
from pytorch_lightning import LightningDataModule

if _TORCHVISION_AVAILABLE:
if _TORCHVISION_AVAILABLE and _TORCHVISION_MNIST_AVAILABLE:
from torchvision import transforms as transform_lib
from torchvision.datasets import MNIST
else:
Expand Down
12 changes: 8 additions & 4 deletions pl_examples/domain_templates/generative_adversarial_net.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,19 @@
import torch
import torch.nn as nn
import torch.nn.functional as F # noqa
import torchvision
import torchvision.transforms as transforms
from torch.utils.data import DataLoader
from torchvision.datasets import MNIST

from pl_examples import cli_lightning_logo
from pl_examples import _TORCHVISION_AVAILABLE, _TORCHVISION_MNIST_AVAILABLE, cli_lightning_logo
from pytorch_lightning.core import LightningDataModule, LightningModule
from pytorch_lightning.trainer import Trainer

if _TORCHVISION_AVAILABLE and _TORCHVISION_MNIST_AVAILABLE:
import torchvision
import torchvision.transforms as transforms
from torchvision.datasets import MNIST
else:
from tests.helpers.datasets import MNIST


class Generator(nn.Module):
"""
Expand Down
4 changes: 2 additions & 2 deletions pytorch_lightning/callbacks/pruning.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@
import logging
from copy import deepcopy
from functools import partial
from typing import Any, Callable, List, Optional, Tuple, Union, Dict
from typing import Any, Callable, Dict, List, Optional, Tuple, Union

import torch
import torch.nn.utils.prune as pytorch_prune
from torch import nn

from pytorch_lightning.callbacks.base import Callback
from pytorch_lightning.core.lightning import LightningModule
from pytorch_lightning.utilities.distributed import rank_zero_only, rank_zero_debug
from pytorch_lightning.utilities.distributed import rank_zero_debug, rank_zero_only
from pytorch_lightning.utilities.exceptions import MisconfigurationException

log = logging.getLogger(__name__)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from abc import ABC, abstractmethod
from typing import Any, Callable, Iterable, Optional, TYPE_CHECKING, Union, Dict
from typing import Any, Callable, Dict, Iterable, Optional, TYPE_CHECKING, Union

import torch
from torch.nn import Module
Expand Down
8 changes: 4 additions & 4 deletions tests/utilities/test_parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,25 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import pytest
import inspect

import pytest

from pytorch_lightning.utilities.parsing import (
AttributeDict,
clean_namespace,
collect_init_args,
flatten_dict,
get_init_args,
is_picklable,
lightning_getattr,
lightning_hasattr,
lightning_setattr,
parse_class_init_keys,
get_init_args,
collect_init_args,
str_to_bool,
str_to_bool_or_str,
)


unpicklable_function = lambda: None


Expand Down