Skip to content

Commit

Permalink
Fix docs typo (#4930)
Browse files Browse the repository at this point in the history
* Fix docs

* typo

* import

* Apply suggestions from code review

Co-authored-by: Jirka Borovec <Borda@users.noreply.github.com>
Co-authored-by: chaton <thomas@grid.ai>
Co-authored-by: Jirka Borovec <jirka.borovec@seznam.cz>
Co-authored-by: edenlightning <66261195+edenlightning@users.noreply.github.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
6 people committed Feb 1, 2021
1 parent 4218c59 commit d71659b
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 d71659b

Please sign in to comment.