From d71659b42a13946b854d49f5bb1bf6e2bcd5b9b2 Mon Sep 17 00:00:00 2001 From: siahuat0727 Date: Mon, 1 Feb 2021 21:09:01 +0800 Subject: [PATCH] Fix docs typo (#4930) * Fix docs * typo * import * Apply suggestions from code review Co-authored-by: Jirka Borovec Co-authored-by: chaton Co-authored-by: Jirka Borovec Co-authored-by: edenlightning <66261195+edenlightning@users.noreply.github.com> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> --- docs/source/conf.py | 11 +++++++---- docs/source/style_guide.rst | 23 ++++++++++++----------- pytorch_lightning/core/lightning.py | 2 +- 3 files changed, 20 insertions(+), 16 deletions(-) diff --git a/docs/source/conf.py b/docs/source/conf.py index 2b861623599a6..42b02828348ad 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -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 @@ -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 diff --git a/docs/source/style_guide.rst b/docs/source/style_guide.rst index c6e06395f851a..1645f3b76cfbb 100644 --- a/docs/source/style_guide.rst +++ b/docs/source/style_guide.rst @@ -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 @@ -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 @@ -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. diff --git a/pytorch_lightning/core/lightning.py b/pytorch_lightning/core/lightning.py index 4880f8336d067..1784a3f809e27 100644 --- a/pytorch_lightning/core/lightning.py +++ b/pytorch_lightning/core/lightning.py @@ -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):