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

Fix docs examples & typos #4930

Merged
merged 28 commits into from
Feb 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
f26ca74
Fix docs
siahuat0727 Dec 1, 2020
51ecf0b
typo
Borda Dec 1, 2020
55d356e
Merge branch 'master' into fix-docs
tchaton Dec 3, 2020
cec1393
import
Borda Dec 3, 2020
4858b80
Merge branch 'master' into fix-docs
edenlightning Dec 16, 2020
a7b2151
Apply suggestions from code review
Borda Jan 26, 2021
1eccebb
Merge branch 'master' into fix-docs
mergify[bot] Jan 26, 2021
9ed8ca3
Merge branch 'master' into fix-docs
mergify[bot] Jan 27, 2021
d8e7da9
Merge branch 'master' into fix-docs
mergify[bot] Jan 27, 2021
552e483
Merge branch 'master' into fix-docs
mergify[bot] Jan 27, 2021
b5c3599
Merge branch 'master' into fix-docs
mergify[bot] Jan 27, 2021
d9f6be1
Merge branch 'master' into fix-docs
mergify[bot] Jan 27, 2021
b35e10b
Merge branch 'master' into fix-docs
mergify[bot] Jan 27, 2021
7e310bf
Merge branch 'master' into fix-docs
mergify[bot] Jan 28, 2021
793be6e
Apply suggestions from code review
Borda Jan 28, 2021
1ace420
Merge branch 'master' into fix-docs
mergify[bot] Jan 28, 2021
e8bc81d
Apply suggestions from code review
Borda Jan 29, 2021
058b5a0
typo
Borda Jan 29, 2021
0c917d8
pl
Borda Jan 29, 2021
bd391da
mock
Borda Jan 29, 2021
c726ba0
Merge branch 'master' into fix-docs
mergify[bot] Jan 29, 2021
7156260
Merge branch 'master' into fix-docs
mergify[bot] Jan 29, 2021
25358b9
Merge branch 'master' into fix-docs
mergify[bot] Jan 29, 2021
4bec4c4
Merge branch 'master' into fix-docs
mergify[bot] Jan 30, 2021
1a71ff1
Merge branch 'master' into fix-docs
mergify[bot] Jan 31, 2021
bbd4d8f
Merge branch 'master' into fix-docs
mergify[bot] Jan 31, 2021
0b44200
Merge branch 'master' into fix-docs
mergify[bot] Feb 1, 2021
1d9516c
nn
Borda Feb 1, 2021
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: 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):
Borda marked this conversation as resolved.
Show resolved Hide resolved
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