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

update min requirements - PL 1.1.1 #448

Merged
merged 8 commits into from
Dec 16, 2020
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
11 changes: 3 additions & 8 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,8 +339,8 @@ def package_list_from_file(file):
for ln in fp.readlines():
found = [ln.index(ch) for ch in list(',=<>#') if ch in ln]
pkg = ln[:min(found)] if found else ln
if pkg.rstrip():
mocked_packages.append(pkg.rstrip())
if pkg.strip():
mocked_packages.append(pkg.strip())
return mocked_packages


Expand All @@ -360,8 +360,7 @@ def package_list_from_file(file):
# replace PyPI packages by importing ones
MOCK_PACKAGES = [PACKAGE_MAPPING.get(pkg, pkg) for pkg in MOCK_PACKAGES]

MOCK_MANUAL_PACKAGES = []
autodoc_mock_imports = MOCK_PACKAGES + MOCK_MANUAL_PACKAGES
autodoc_mock_imports = MOCK_PACKAGES
# for mod_name in MOCK_REQUIRE_PACKAGES:
# sys.modules[mod_name] = mock.Mock()

Expand Down Expand Up @@ -441,10 +440,6 @@ def find_source():

import pytorch_lightning as pl
from pytorch_lightning import Trainer, LightningModule
from pytorch_lightning.utilities import NATIVE_AMP_AVALAIBLE
APEX_AVAILABLE = importlib.util.find_spec("apex") is not None
XLA_AVAILABLE = importlib.util.find_spec("torch_xla") is not None
TORCHVISION_AVAILABLE = importlib.util.find_spec("torchvision") is not None

"""
coverage_skip_undoc_in_source = True
2 changes: 1 addition & 1 deletion pl_bolts/callbacks/variational.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import math
import numpy as np

import numpy as np
import torch
from pytorch_lightning.callbacks import Callback

Expand Down
7 changes: 3 additions & 4 deletions pl_bolts/datamodules/binary_mnist_datamodule.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@

if _TORCHVISION_AVAILABLE:
from torchvision import transforms as transform_lib
from torchvision.datasets import MNIST
else: # pragma: no cover
else: # pragma: no-cover
warn_missing_pkg('torchvision')


Expand Down Expand Up @@ -64,8 +63,8 @@ def __init__(
"""
super().__init__(*args, **kwargs)

if not _TORCHVISION_AVAILABLE: # pragma: no cover
raise ModuleNotFoundError(
if not _TORCHVISION_AVAILABLE:
raise ModuleNotFoundError( # pragma: no-cover
'You want to use MNIST dataset loaded from `torchvision` which is not installed yet.'
)

Expand Down
4 changes: 2 additions & 2 deletions pl_bolts/datamodules/cifar10_datamodule.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
if _TORCHVISION_AVAILABLE:
from torchvision import transforms as transform_lib
from torchvision.datasets import CIFAR10
else: # pragma: no cover
warn_missing_pkg('torchvision')
else:
warn_missing_pkg('torchvision') # pragma: no-cover


class CIFAR10DataModule(LightningDataModule):
Expand Down
8 changes: 4 additions & 4 deletions pl_bolts/datamodules/cityscapes_datamodule.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
if _TORCHVISION_AVAILABLE:
from torchvision import transforms as transform_lib
from torchvision.datasets import Cityscapes
else: # pragma: no cover
warn_missing_pkg('torchvision')
else:
warn_missing_pkg('torchvision') # pragma: no-cover


class CityscapesDataModule(LightningDataModule):
Expand Down Expand Up @@ -80,8 +80,8 @@ def __init__(
"""
super().__init__(*args, **kwargs)

if not _TORCHVISION_AVAILABLE: # pragma: no cover
raise ModuleNotFoundError(
if not _TORCHVISION_AVAILABLE:
raise ModuleNotFoundError( # pragma: no-cover
'You want to use CityScapes dataset loaded from `torchvision` which is not installed yet.'
)

Expand Down
1 change: 0 additions & 1 deletion pl_bolts/datamodules/experience_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
Datamodules for RL models that rely on experiences generated during training
Based on implementations found here: https://github.com/Shmuma/ptan/blob/master/ptan/experience.py
"""
import importlib
from abc import ABC
from collections import deque, namedtuple
from typing import Callable, Iterable, List, Tuple
Expand Down
8 changes: 4 additions & 4 deletions pl_bolts/datamodules/fashion_mnist_datamodule.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
if _TORCHVISION_AVAILABLE:
from torchvision import transforms as transform_lib
from torchvision.datasets import FashionMNIST
else: # pragma: no cover
warn_missing_pkg('torchvision')
else:
warn_missing_pkg('torchvision') # pragma: no-cover


class FashionMNISTDataModule(LightningDataModule):
Expand Down Expand Up @@ -62,8 +62,8 @@ def __init__(
"""
super().__init__(*args, **kwargs)

if not _TORCHVISION_AVAILABLE: # pragma: no cover
raise ModuleNotFoundError(
if not _TORCHVISION_AVAILABLE:
raise ModuleNotFoundError( # pragma: no-cover
'You want to use fashion MNIST dataset loaded from `torchvision` which is not installed yet.'
)

Expand Down
8 changes: 4 additions & 4 deletions pl_bolts/datamodules/imagenet_datamodule.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@

if _TORCHVISION_AVAILABLE:
from torchvision import transforms as transform_lib
else: # pragma: no cover
warn_missing_pkg('torchvision')
else:
warn_missing_pkg('torchvision') # pragma: no-cover


class ImagenetDataModule(LightningDataModule):
Expand Down Expand Up @@ -69,8 +69,8 @@ def __init__(
"""
super().__init__(*args, **kwargs)

if not _TORCHVISION_AVAILABLE: # pragma: no cover
raise ModuleNotFoundError(
if not _TORCHVISION_AVAILABLE:
raise ModuleNotFoundError( # pragma: no-cover
'You want to use ImageNet dataset loaded from `torchvision` which is not installed yet.'
)

Expand Down
8 changes: 4 additions & 4 deletions pl_bolts/datamodules/mnist_datamodule.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
if _TORCHVISION_AVAILABLE:
from torchvision import transforms as transform_lib
from torchvision.datasets import MNIST
else: # pragma: no cover
warn_missing_pkg('torchvision')
else:
warn_missing_pkg('torchvision') # pragma: no-cover


class MNISTDataModule(LightningDataModule):
Expand Down Expand Up @@ -63,8 +63,8 @@ def __init__(
"""
super().__init__(*args, **kwargs)

if not _TORCHVISION_AVAILABLE: # pragma: no cover
raise ModuleNotFoundError(
if not _TORCHVISION_AVAILABLE:
raise ModuleNotFoundError( # pragma: no-cover
'You want to use MNIST dataset loaded from `torchvision` which is not installed yet.'
)

Expand Down
8 changes: 4 additions & 4 deletions pl_bolts/datamodules/sklearn_datamodule.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@

if _SKLEARN_AVAILABLE:
from sklearn.utils import shuffle as sk_shuffle
else: # pragma: no cover
warn_missing_pkg("sklearn")
else:
warn_missing_pkg("sklearn") # pragma: no-cover


class SklearnDataset(Dataset):
Expand Down Expand Up @@ -160,8 +160,8 @@ def __init__(
# shuffle x and y
if shuffle and _SKLEARN_AVAILABLE:
X, y = sk_shuffle(X, y, random_state=random_state)
elif shuffle and not _SKLEARN_AVAILABLE: # pragma: no cover
raise ModuleNotFoundError(
elif shuffle and not _SKLEARN_AVAILABLE:
raise ModuleNotFoundError( # pragma: no-cover
'You want to use shuffle function from `scikit-learn` which is not installed yet.'
)

Expand Down
8 changes: 4 additions & 4 deletions pl_bolts/datamodules/ssl_imagenet_datamodule.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@

if _TORCHVISION_AVAILABLE:
from torchvision import transforms as transform_lib
else: # pragma: no cover
warn_missing_pkg('torchvision')
else:
warn_missing_pkg('torchvision') # pragma: no-cover


class SSLImagenetDataModule(LightningDataModule): # pragma: no cover
Expand All @@ -29,8 +29,8 @@ def __init__(
):
super().__init__(*args, **kwargs)

if not _TORCHVISION_AVAILABLE: # pragma: no cover
raise ModuleNotFoundError(
if not _TORCHVISION_AVAILABLE:
raise ModuleNotFoundError( # pragma: no-cover
'You want to use ImageNet dataset loaded from `torchvision` which is not installed yet.'
)

Expand Down
8 changes: 4 additions & 4 deletions pl_bolts/datamodules/stl10_datamodule.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
if _TORCHVISION_AVAILABLE:
from torchvision import transforms as transform_lib
from torchvision.datasets import STL10
else: # pragma: no cover
warn_missing_pkg('torchvision')
else:
warn_missing_pkg('torchvision') # pragma: no-cover


class STL10DataModule(LightningDataModule): # pragma: no cover
Expand Down Expand Up @@ -73,8 +73,8 @@ def __init__(
"""
super().__init__(*args, **kwargs)

if not _TORCHVISION_AVAILABLE: # pragma: no cover
raise ModuleNotFoundError(
if not _TORCHVISION_AVAILABLE:
raise ModuleNotFoundError( # pragma: no-cover
'You want to use STL10 dataset loaded from `torchvision` which is not installed yet.'
)

Expand Down
8 changes: 4 additions & 4 deletions pl_bolts/datamodules/vocdetection_datamodule.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
if _TORCHVISION_AVAILABLE:
import torchvision.transforms as T
from torchvision.datasets import VOCDetection
else: # pragma: no cover
warn_missing_pkg('torchvision')
else:
warn_missing_pkg('torchvision') # pragma: no-cover


class Compose(object):
Expand Down Expand Up @@ -114,8 +114,8 @@ def __init__(
*args,
**kwargs,
):
if not _TORCHVISION_AVAILABLE: # pragma: no cover
raise ModuleNotFoundError(
if not _TORCHVISION_AVAILABLE:
raise ModuleNotFoundError( # pragma: no-cover
'You want to use VOC dataset loaded from `torchvision` which is not installed yet.'
)

Expand Down
4 changes: 2 additions & 2 deletions pl_bolts/datasets/cifar10_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@

if _PIL_AVAILABLE:
from PIL import Image
else: # pragma: no cover
warn_missing_pkg('PIL', pypi_name='Pillow')
else:
warn_missing_pkg('PIL', pypi_name='Pillow') # pragma: no-cover


class CIFAR10(LightDataset):
Expand Down
9 changes: 4 additions & 5 deletions pl_bolts/datasets/mnist_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,15 @@
from pl_bolts.utils.warnings import warn_missing_pkg

if _TORCHVISION_AVAILABLE:
from torchvision import transforms as transform_lib
from torchvision.datasets import MNIST
else: # pragma: no cover
warn_missing_pkg('torchvision')
else:
warn_missing_pkg('torchvision') # pragma: no-cover
MNIST = object

if _PIL_AVAILABLE:
from PIL import Image
else: # pragma: no cover
warn_missing_pkg('PIL', pypi_name='Pillow')
else:
warn_missing_pkg('PIL', pypi_name='Pillow') # pragma: no-cover


class BinaryMNIST(MNIST):
Expand Down
8 changes: 3 additions & 5 deletions pl_bolts/models/rl/common/gym_wrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,13 @@
import numpy as np
import torch

from pl_bolts.utils import _OPENCV_AVAILABLE
from pl_bolts.utils.warnings import warn_missing_pkg

try:
if _OPENCV_AVAILABLE:
import cv2
except ModuleNotFoundError:
warn_missing_pkg('cv2', pypi_name='opencv-python') # pragma: no-cover
_OPENCV_AVAILABLE = False
else:
_OPENCV_AVAILABLE = True
warn_missing_pkg('cv2', pypi_name='opencv-python') # pragma: no-cover


class ToTensor(gym.Wrapper):
Expand Down
8 changes: 3 additions & 5 deletions pl_bolts/models/rl/dqn_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,13 @@
from pl_bolts.models.rl.common.agents import ValueAgent
from pl_bolts.models.rl.common.memory import MultiStepBuffer
from pl_bolts.models.rl.common.networks import CNN
from pl_bolts.utils import _GYM_AVAILABLE
from pl_bolts.utils.warnings import warn_missing_pkg

try:
if _GYM_AVAILABLE:
from pl_bolts.models.rl.common.gym_wrappers import gym, make_environment
except ModuleNotFoundError:
warn_missing_pkg('gym') # pragma: no-cover
_GYM_AVAILABLE = False
else:
_GYM_AVAILABLE = True
warn_missing_pkg('gym') # pragma: no-cover


class DQN(pl.LightningModule):
Expand Down
8 changes: 3 additions & 5 deletions pl_bolts/models/rl/reinforce_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,13 @@
from pl_bolts.datamodules.experience_source import Experience
from pl_bolts.models.rl.common.agents import PolicyAgent
from pl_bolts.models.rl.common.networks import MLP
from pl_bolts.utils import _GYM_AVAILABLE
from pl_bolts.utils.warnings import warn_missing_pkg

try:
if _GYM_AVAILABLE:
import gym
except ModuleNotFoundError:
warn_missing_pkg('gym') # pragma: no-cover
_GYM_AVAILABLE = False
else:
_GYM_AVAILABLE = True
warn_missing_pkg('gym') # pragma: no-cover


class Reinforce(pl.LightningModule):
Expand Down
8 changes: 3 additions & 5 deletions pl_bolts/models/rl/vanilla_policy_gradient_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,13 @@
from pl_bolts.datamodules import ExperienceSourceDataset
from pl_bolts.models.rl.common.agents import PolicyAgent
from pl_bolts.models.rl.common.networks import MLP
from pl_bolts.utils import _GYM_AVAILABLE
from pl_bolts.utils.warnings import warn_missing_pkg

try:
if _GYM_AVAILABLE:
import gym
except ModuleNotFoundError:
warn_missing_pkg('gym') # pragma: no-cover
_GYM_AVAILABLE = False
else:
_GYM_AVAILABLE = True
warn_missing_pkg('gym') # pragma: no-cover


class VanillaPolicyGradient(pl.LightningModule):
Expand Down
8 changes: 3 additions & 5 deletions pl_bolts/models/self_supervised/amdim/transforms.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
from pl_bolts.transforms.self_supervised import RandomTranslateWithReflect
from pl_bolts.utils import _TORCHVISION_AVAILABLE
from pl_bolts.utils.warnings import warn_missing_pkg

try:
if _TORCHVISION_AVAILABLE:
from torchvision import transforms
except ModuleNotFoundError:
warn_missing_pkg('torchvision') # pragma: no-cover
_TORCHVISION_AVAILABLE = False
else:
_TORCHVISION_AVAILABLE = True
warn_missing_pkg('torchvision') # pragma: no-cover


class AMDIMTrainTransformsCIFAR10:
Expand Down
8 changes: 3 additions & 5 deletions pl_bolts/models/self_supervised/cpc/transforms.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
from pl_bolts.transforms.self_supervised import Patchify, RandomTranslateWithReflect
from pl_bolts.utils import _TORCHVISION_AVAILABLE
from pl_bolts.utils.warnings import warn_missing_pkg

try:
if _TORCHVISION_AVAILABLE:
from torchvision import transforms
except ModuleNotFoundError:
warn_missing_pkg('torchvision') # pragma: no-cover
_TORCHVISION_AVAILABLE = False
else:
_TORCHVISION_AVAILABLE = True
warn_missing_pkg('torchvision') # pragma: no-cover


class CPCTrainTransformsCIFAR10:
Expand Down
Loading