Skip to content

Commit

Permalink
Merge branch 'master' into bugfix/5487_auto_lr_ordering
Browse files Browse the repository at this point in the history
  • Loading branch information
mergify[bot] authored Feb 1, 2021
2 parents 71b36d2 + d71659b commit 042bfda
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 16 deletions.
11 changes: 7 additions & 4 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@
PATH_ROOT = os.path.join(PATH_HERE, '..', '..')
sys.path.insert(0, os.path.abspath(PATH_ROOT))

builtins.__LIGHTNING_SETUP__ = True

SPHINX_MOCK_REQUIREMENTS = int(os.environ.get('SPHINX_MOCK_REQUIREMENTS', True))
if SPHINX_MOCK_REQUIREMENTS:
builtins.__LIGHTNING_SETUP__ = True

import pytorch_lightning # noqa: E402

Expand Down Expand Up @@ -361,15 +361,18 @@ def package_list_from_file(file):
import importlib
import os
import torch
from torch import nn
import pytorch_lightning as pl
from pytorch_lightning import LightningModule, Trainer
from pytorch_lightning.utilities import (
NATIVE_AMP_AVAILABLE,
APEX_AVAILABLE,
XLA_AVAILABLE,
TPU_AVAILABLE,
_module_available,
)
TORCHVISION_AVAILABLE = importlib.util.find_spec("torchvision") is not None
TORCHVISION_AVAILABLE = _module_available("torchvision")
"""
coverage_skip_undoc_in_source = True
23 changes: 12 additions & 11 deletions docs/source/style_guide.rst
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,16 @@ A LightningModule can define both a system and a model.

Here's a LightningModule that defines a model:

.. code-block:: python
.. testcode::

class LitModel(pl.LightningModule):
def __init__(self, num_layers: int = 3)
class LitModel(LightningModule):
def __init__(self, num_layers: int = 3):
super().__init__()
self.layer_1 = nn.Linear(...)
self.layer_2 = nn.Linear(...)
self.layer_3 = nn.Linear(...)
self.layer_1 = nn.Linear()
self.layer_2 = nn.Linear()
self.layer_3 = nn.Linear()

Here's a lightningModule that defines a system:
Here's a LightningModule that defines a system:

.. code-block:: python
Expand Down Expand Up @@ -74,9 +74,9 @@ sensible defaults in the init so that the user doesn't have to guess.

Here's an example where a user will have to go hunt through files to figure out how to init this LightningModule.

.. code-block:: python
.. testcode::

class LitModel(pl.LightningModule):
class LitModel(LightningModule):
def __init__(self, params):
self.lr = params.lr
self.coef_x = params.coef_x
Expand All @@ -85,10 +85,11 @@ Models defined as such leave you with many questions; what is coef_x? is it a st

Instead, be explicit in your init

.. code-block:: python
.. testcode::

class LitModel(pl.LightningModule):
def __init__(self, encoder: nn.Module, coeff_x: float = 0.2, lr: float = 1e-3)
def __init__(self, encoder: nn.Module, coef_x: float = 0.2, lr: float = 1e-3):
pass

Now the user doesn't have to guess. Instead they know the value type and the model has a sensible default where the
user can see the value immediately.
Expand Down
2 changes: 1 addition & 1 deletion pytorch_lightning/core/lightning.py
Original file line number Diff line number Diff line change
Expand Up @@ -1501,7 +1501,7 @@ def save_hyperparameters(self, *args, frame=None) -> None:
Args:
args: single object of `dict`, `NameSpace` or `OmegaConf`
or string names or argumenst from class `__init__`
or string names or arguments from class `__init__`
>>> from collections import OrderedDict
>>> class ManuallyArgsModel(LightningModule):
Expand Down

0 comments on commit 042bfda

Please sign in to comment.