doctest for .rst files (#1511)

* add doctest to circleci

* Revert "add doctest to circleci"

This reverts commit c45b34ea911a81f87989f6c3a832b1e8d8c471c6.

* Revert "Revert "add doctest to circleci""

This reverts commit 41fca97fdcfe1cf4f6bdb3bbba75d25fa3b11f70.

* doctest docs rst files

* Revert "doctest docs rst files"

This reverts commit b4a2e83e3da5ed1909de500ec14b6b614527c07f.

* doctest only rst

* doctest debugging.rst

* doctest apex

* doctest callbacks

* doctest early stopping

* doctest for child modules

* doctest experiment reporting

* indentation

* doctest fast training

* doctest for hyperparams

* doctests for lr_finder

* doctests multi-gpu

* more doctest

* make doctest drone

* fix label build error

* update fast training

* update invalid imports

* fix problem with int device count

* rebase stuff

* wip

* wip

* wip

* intro guide

* add missing code block

* circleci

* logger import for doctest

* test if doctest runs on drone

* fix mnist download

* also run install deps for building docs

* install cmake

* try sudo

* hide output

* try pip stuff

* try to mock horovod

* Tranfer -> Transfer

* add torchvision to extras

* revert pip stuff

* mlflow file location

* do not mock torch

* torchvision

* drone extra req.

* try higher sphinx version

* Revert "try higher sphinx version"

This reverts commit 490ac28e46d6fd52352640dfdf0d765befa56988.

* try coverage command

* try coverage command

* try undoc flag

* newline

* undo drone

* report coverage

* review

Co-authored-by: Jirka Borovec <Borda@users.noreply.github.com>

* remove torchvision from extras

* skip tests only if torchvision not available

* fix testoutput torchvision

Co-authored-by: Jirka Borovec <Borda@users.noreply.github.com>
This commit is contained in:
Adrian Wälchli
2020-05-04 22:16:54 -04:00
committed by GitHub
co-authored by Jirka Borovec
parent 48e808c20e
commit a6de1b8d75
25 changed files with 798 additions and 637 deletions
+21 -15
View File
@@ -1,3 +1,10 @@
.. testsetup:: *
import os
from pytorch_lightning.trainer.trainer import Trainer
from pytorch_lightning.core.lightning import LightningModule
Saving and loading weights
==========================
@@ -22,13 +29,13 @@ Automatic saving
Checkpointing is enabled by default to the current working directory.
To change the checkpoint path pass in:
.. code-block:: python
.. testcode::
Trainer(default_save_path='/your/path/to/save/checkpoints')
trainer = Trainer(default_save_path='/your/path/to/save/checkpoints')
To modify the behavior of checkpointing pass in your own callback.
.. code-block:: python
.. testcode::
from pytorch_lightning.callbacks import ModelCheckpoint
@@ -47,17 +54,16 @@ To modify the behavior of checkpointing pass in your own callback.
Or disable it by passing
.. code-block:: python
.. testcode::
trainer = Trainer(checkpoint_callback=False)
trainer = Trainer(checkpoint_callback=False)
The Lightning checkpoint also saves the hparams (hyperparams) passed into the LightningModule init.
.. note:: hparams is a `Namespace <https://docs.python.org/2/library/argparse.html#argparse.Namespace>`_.
.. code-block:: python
:emphasize-lines: 8
.. testcode::
from argparse import Namespace
@@ -67,9 +73,9 @@ The Lightning checkpoint also saves the hparams (hyperparams) passed into the Li
# define you module to have hparams as the first arg
# this means your checkpoint will have everything that went into making
# this model (in this case, learning rate)
class MyLightningModule(pl.LightningModule):
class MyLightningModule(LightningModule):
def __init__(self, hparams, ...):
def __init__(self, hparams, *args, **kwargs):
self.hparams = hparams
Manual saving
@@ -78,7 +84,7 @@ You can manually save checkpoints and restore your model from the checkpointed s
.. code-block:: python
model = MyModel(hparams)
model = MyLightningModule(hparams)
trainer.fit(model)
trainer.save_checkpoint("example.ckpt")
new_model = MyModel.load_from_checkpoint(checkpoint_path="example.ckpt")
@@ -96,9 +102,9 @@ To load a model along with its weights, biases and hyperparameters use following
The above only works if you used `hparams` in your model definition
.. code-block:: python
.. testcode::
class MyModel(pl.LightningModule):
class LitModel(LightningModule):
def __init__(self, hparams):
self.hparams = hparams
@@ -106,9 +112,9 @@ The above only works if you used `hparams` in your model definition
But if you don't and instead pass individual parameters
.. code-block:: python
.. testcode::
class MyModel(pl.LightningModule):
class LitModel(LightningModule):
def __init__(self, in_dim, out_dim):
self.l1 = nn.Linear(in_dim, out_dim)
@@ -117,7 +123,7 @@ you can restore the model like this
.. code-block:: python
model = MyModel.load_from_checkpoint(PATH, in_dim=128, out_dim=10)
model = LitModel.load_from_checkpoint(PATH, in_dim=128, out_dim=10)
Restoring Training State