Skip to content

Commit d5f77c9

Browse files
Release2 (#2262)
* fix missing arg * fix missing arg * fix missing arg * fix missing arg * fix missing arg * fix missing arg * fix missing arg
1 parent 9739b3e commit d5f77c9

20 files changed

+305
-118
lines changed

docs/source/apex.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
=================
88
Lightning offers 16-bit training for CPUs, GPUs and TPUs.
99

10+
----------
11+
1012
GPU 16-bit
1113
----------
1214
16 bit precision can cut your memory footprint by half.
@@ -67,6 +69,8 @@ Enable 16-bit
6769
If you need to configure the apex init for your particular use case or want to use a different way of doing
6870
16-bit training, override :meth:`pytorch_lightning.core.LightningModule.configure_apex`.
6971

72+
----------
73+
7074
TPU 16-bit
7175
----------
7276
16-bit on TPus is much simpler. To use 16-bit with TPUs set precision to 16 when using the tpu flag

docs/source/early_stopping.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,16 @@ You can stop an epoch early by overriding :meth:`~pytorch_lightning.core.lightni
1313

1414
If you do this repeatedly, for every epoch you had originally requested, then this will stop your entire run.
1515

16+
----------
17+
1618
Default Epoch End Callback Behavior
1719
-----------------------------------
1820
By default early stopping will be enabled if `'val_loss'`
1921
is found in :meth:`~pytorch_lightning.core.lightning.LightningModule.validation_epoch_end`'s
2022
return dict. Otherwise training will proceed with early stopping disabled.
2123

24+
----------
25+
2226
Enable Early Stopping using the EarlyStopping Callback
2327
------------------------------------------------------
2428
The
@@ -81,6 +85,8 @@ and change where it is called:
8185
- :class:`~pytorch_lightning.trainer.trainer.Trainer`
8286
- :class:`~pytorch_lightning.callbacks.early_stopping.EarlyStopping`
8387

88+
----------
89+
8490
Disable Early Stopping with callbacks on epoch end
8591
--------------------------------------------------
8692
To disable early stopping pass ``False`` to the

docs/source/experiment_reporting.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Lightning supports many different experiment loggers. These loggers allow you to
1010
as training progresses. They usually provide a GUI to visualize and can sometimes even snapshot hyperparameters
1111
used in each experiment.
1212

13+
----------
1314

1415
Control logging frequency
1516
^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -21,6 +22,8 @@ It may slow training down to log every single batch. Trainer has an option to lo
2122
k = 10
2223
trainer = Trainer(row_log_interval=k)
2324

25+
----------
26+
2427
Control log writing frequency
2528
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2629

@@ -35,6 +38,8 @@ want to log using this trainer flag.
3538
k = 100
3639
trainer = Trainer(log_save_interval=k)
3740

41+
----------
42+
3843
Log metrics
3944
^^^^^^^^^^^
4045

@@ -84,6 +89,8 @@ For instance, here we log images using tensorboard.
8489
...
8590
return results
8691

92+
----------
93+
8794
Modify progress bar
8895
^^^^^^^^^^^^^^^^^^^
8996

@@ -102,6 +109,8 @@ Here we show the validation loss in the progress bar
102109
results = {'progress_bar': logs}
103110
return results
104111

112+
----------
113+
105114
Snapshot hyperparameters
106115
^^^^^^^^^^^^^^^^^^^^^^^^
107116

@@ -117,6 +126,8 @@ Some loggers also allow logging the hyperparams used in the experiment. For inst
117126
when using the TestTubeLogger or the TensorBoardLogger, all hyperparams will show
118127
in the `hparams tab <https://pytorch.org/docs/stable/tensorboard.html#torch.utils.tensorboard.writer.SummaryWriter.add_hparams>`_.
119128

129+
----------
130+
120131
Snapshot code
121132
^^^^^^^^^^^^^
122133

docs/source/hooks.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ Training set-up
3030
- :meth:`~pytorch_lightning.core.lightning.LightningModule.summarize`
3131
- :meth:`~pytorch_lightning.trainer.training_io.TrainerIOMixin.restore_weights`
3232

33+
----------
34+
3335
Training loop
3436
^^^^^^^^^^^^^
3537

@@ -46,6 +48,8 @@ Training loop
4648
- :meth:`~pytorch_lightning.core.lightning.LightningModule.training_epoch_end`
4749
- :meth:`~pytorch_lightning.core.hooks.ModelHooks.on_epoch_end`
4850

51+
----------
52+
4953
Validation loop
5054
^^^^^^^^^^^^^^^
5155

@@ -59,6 +63,8 @@ Validation loop
5963
- ``torch.set_grad_enabled(True)``
6064
- :meth:`~pytorch_lightning.core.hooks.ModelHooks.on_post_performance_check`
6165

66+
----------
67+
6268
Test loop
6369
^^^^^^^^^
6470

docs/source/hyperparameters.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ Hyperparameters
1313
Lightning has utilities to interact seamlessly with the command line ArgumentParser
1414
and plays well with the hyperparameter optimization framework of your choice.
1515

16+
----------
17+
1618
ArgumentParser
1719
^^^^^^^^^^^^^^
1820
Lightning is designed to augment a lot of the functionality of the built-in Python ArgumentParser
@@ -30,6 +32,7 @@ This allows you to call your program like so:
3032
3133
python trainer.py --layer_1_dim 64
3234
35+
----------
3336

3437
Argparser Best Practices
3538
^^^^^^^^^^^^^^^^^^^^^^^^
@@ -100,6 +103,8 @@ Finally, make sure to start the training like so:
100103
dict_args = vars(args)
101104
model = LitModel(**dict_args)
102105
106+
----------
107+
103108
LightningModule hyperparameters
104109
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
105110
Often times we train many versions of a model. You might share that model or come back to it a few months later
@@ -188,6 +193,7 @@ In that case, choose only a few
188193
# this works
189194
model.hparams.anything
190195
196+
----------
191197

192198
Trainer args
193199
^^^^^^^^^^^^
@@ -204,6 +210,7 @@ To recap, add ALL possible trainer flags to the argparser and init the Trainer t
204210
# or if you need to pass in callbacks
205211
trainer = Trainer.from_argparse_args(hparams, checkpoint_callback=..., callbacks=[...])
206212
213+
----------
207214

208215
Multiple Lightning Modules
209216
^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -284,6 +291,8 @@ and now we can train MNIST or the GAN using the command line interface!
284291
$ python main.py --model_name gan --encoder_layers 24
285292
$ python main.py --model_name mnist --layer_1_dim 128
286293
294+
----------
295+
287296
Hyperparameter Optimization
288297
^^^^^^^^^^^^^^^^^^^^^^^^^^^
289298
Lightning is fully compatible with the hyperparameter optimization libraries!

docs/source/introduction_guide.rst

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,14 +256,14 @@ under the `train_dataloader` method. This is great because if you run into a pro
256256
to figure out how they prepare their training data you can just look in the `train_dataloader` method.
257257

258258
Usually though, we want to separate the things that write to disk in data-processing from
259-
things like transforms which happen in memory.
259+
things like transforms which happen in memory. This is only relevant in multi-GPU or TPU training.
260260

261261
.. testcode::
262262

263263
class LitMNIST(LightningModule):
264264

265265
def prepare_data(self):
266-
# download only
266+
# download only (not called on every GPU, just the root GPU per node)
267267
MNIST(os.getcwd(), train=True, download=True)
268268

269269
def train_dataloader(self):
@@ -302,6 +302,31 @@ In general fill these methods with the following:
302302
# return a DataLoader
303303
...
304304

305+
Models defined by data
306+
^^^^^^^^^^^^^^^^^^^^^^
307+
Sometimes a model needs to know about the data to be built (ie: number of classes or vocab size).
308+
In this case we recommend the following:
309+
310+
1. use `prepare_data` to download and process the dataset.
311+
2. use `setup` to do splits, and build your model internals
312+
313+
Example::
314+
315+
class LitMNIST(LightningModule):
316+
317+
def __init__(self):
318+
self.l1 = None
319+
320+
def prepare_data(self):
321+
download_data()
322+
tokenize()
323+
324+
def setup(self, step):
325+
# step is either 'fit' or 'test' 90% of the time not relevant
326+
data = load_data()
327+
num_classes = data.classes
328+
self.l1 = nn.Linear(..., num_classes)
329+
305330
Optimizer
306331
^^^^^^^^^
307332

docs/source/loggers.rst

Lines changed: 136 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,139 @@
33

44
Loggers
55
===========
6-
.. automodule:: pytorch_lightning.loggers
7-
:noindex:
8-
:exclude-members:
9-
_abc_impl,
10-
_save_model,
11-
on_epoch_end,
12-
on_train_end,
13-
on_epoch_start,
6+
Lightning supports the most popular logging frameworks (TensorBoard, Comet, Weights and Biases, etc...).
7+
To use a logger, simply pass it into the :class:`~pytorch_lightning.trainer.trainer.Trainer`.
8+
Lightning uses TensorBoard by default.
9+
10+
.. code-block:: python
11+
12+
from pytorch_lightning import Trainer
13+
from pytorch_lightning import loggers
14+
tb_logger = loggers.TensorBoardLogger('logs/')
15+
trainer = Trainer(logger=tb_logger)
16+
17+
Choose from any of the others such as MLflow, Comet, Neptune, WandB, ...
18+
19+
.. code-block:: python
20+
21+
comet_logger = loggers.CometLogger(save_dir='logs/')
22+
trainer = Trainer(logger=comet_logger)
23+
24+
To use multiple loggers, simply pass in a ``list`` or ``tuple`` of loggers ...
25+
26+
.. code-block:: python
27+
28+
tb_logger = loggers.TensorBoardLogger('logs/')
29+
comet_logger = loggers.CometLogger(save_dir='logs/')
30+
trainer = Trainer(logger=[tb_logger, comet_logger])
31+
32+
Note:
33+
All loggers log by default to ``os.getcwd()``. To change the path without creating a logger set
34+
``Trainer(default_root_dir='/your/path/to/save/checkpoints')``
35+
36+
----------
37+
38+
Custom Logger
39+
-------------
40+
41+
You can implement your own logger by writing a class that inherits from
42+
:class:`LightningLoggerBase`. Use the :func:`~pytorch_lightning.loggers.base.rank_zero_only`
43+
decorator to make sure that only the first process in DDP training logs data.
44+
45+
.. code-block:: python
46+
47+
from pytorch_lightning.utilities import rank_zero_only
48+
from pytorch_lightning.loggers import LightningLoggerBase
49+
class MyLogger(LightningLoggerBase):
50+
51+
@rank_zero_only
52+
def log_hyperparams(self, params):
53+
# params is an argparse.Namespace
54+
# your code to record hyperparameters goes here
55+
pass
56+
57+
@rank_zero_only
58+
def log_metrics(self, metrics, step):
59+
# metrics is a dictionary of metric names and values
60+
# your code to record metrics goes here
61+
pass
62+
63+
def save(self):
64+
# Optional. Any code necessary to save logger data goes here
65+
pass
66+
67+
@rank_zero_only
68+
def finalize(self, status):
69+
# Optional. Any code that needs to be run after training
70+
# finishes goes here
71+
pass
72+
73+
If you write a logger that may be useful to others, please send
74+
a pull request to add it to Lighting!
75+
76+
----------
77+
78+
Using loggers
79+
-------------
80+
81+
Call the logger anywhere except ``__init__`` in your
82+
:class:`~pytorch_lightning.core.lightning.LightningModule` by doing:
83+
84+
.. code-block:: python
85+
86+
from pytorch_lightning import LightningModule
87+
class LitModel(LightningModule):
88+
def training_step(self, batch, batch_idx):
89+
# example
90+
self.logger.experiment.whatever_method_summary_writer_supports(...)
91+
92+
# example if logger is a tensorboard logger
93+
self.logger.experiment.add_image('images', grid, 0)
94+
self.logger.experiment.add_graph(model, images)
95+
96+
def any_lightning_module_function_or_hook(self):
97+
self.logger.experiment.add_histogram(...)
98+
99+
Read more in the `Experiment Logging use case <./experiment_logging.html>`_.
100+
101+
------
102+
103+
Supported Loggers
104+
-----------------
105+
The following are loggers we support
106+
107+
Comet
108+
^^^^^
109+
110+
.. autoclass:: pytorch_lightning.loggers.comet.CometLogger
111+
:noindex:
112+
113+
MLFlow
114+
^^^^^^
115+
116+
.. autoclass:: pytorch_lightning.loggers.mlflow.MLFlowLogger
117+
:noindex:
118+
119+
Neptune
120+
^^^^^^^
121+
122+
.. autoclass:: pytorch_lightning.loggers.neptune.NeptuneLogger
123+
:noindex:
124+
125+
Tensorboard
126+
^^^^^^^^^^^^
127+
128+
.. autoclass:: pytorch_lightning.loggers.tensorboard.TensorBoardLogger
129+
:noindex:
130+
131+
Test-tube
132+
^^^^^^^^^
133+
134+
.. autoclass:: pytorch_lightning.loggers.test_tube.TestTubeLogger
135+
:noindex:
136+
137+
Trains
138+
^^^^^^
139+
140+
.. autoclass:: pytorch_lightning.loggers.trains.TrainsLogger
141+
:noindex:

docs/source/lr_finder.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ initial lr.
2222
For the moment, this feature only works with models having a single optimizer.
2323
LR support for DDP is not implemented yet, it is comming soon.
2424

25+
----------
26+
2527
Using Lightning's built-in LR finder
2628
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2729

0 commit comments

Comments
 (0)