From 8e35384557ba096b9487835d414ec71e2c8e0c90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mochol=C3=AD?= Date: Mon, 13 Mar 2023 18:33:14 +0100 Subject: [PATCH] Remove outdated LightningModule animation (#17057) --- .../common/lightning_module.rst | 65 ++++++++----------- 1 file changed, 27 insertions(+), 38 deletions(-) diff --git a/docs/source-pytorch/common/lightning_module.rst b/docs/source-pytorch/common/lightning_module.rst index ce502859a7..8114c986c0 100644 --- a/docs/source-pytorch/common/lightning_module.rst +++ b/docs/source-pytorch/common/lightning_module.rst @@ -7,39 +7,28 @@ LightningModule ############### -A :class:`~LightningModule` organizes your PyTorch code into 6 sections: +A :class:`~lightning.pytorch.core.module.LightningModule` organizes your PyTorch code into 6 sections: -- Computations (init). -- Train Loop (training_step) -- Validation Loop (validation_step) -- Test Loop (test_step) -- Prediction Loop (predict_step) -- Optimizers and LR Schedulers (configure_optimizers) +- Initialization (``__init__`` and :meth:`~lightning.pytorch.core.hooks.ModelHooks.setup`). +- Train Loop (:meth:`~lightning.pytorch.core.module.LightningModule.training_step`) +- Validation Loop (:meth:`~lightning.pytorch.core.module.LightningModule.validation_step`) +- Test Loop (:meth:`~lightning.pytorch.core.module.LightningModule.test_step`) +- Prediction Loop (:meth:`~lightning.pytorch.core.module.LightningModule.predict_step`) +- Optimizers and LR Schedulers (:meth:`~lightning.pytorch.core.module.LightningModule.configure_optimizers`) -| - -.. raw:: html - - - -| - -Notice a few things. - -1. It is the SAME code. -2. The PyTorch code IS NOT abstracted - just organized. -3. All the other code that's not in the :class:`~LightningModule` - has been automated for you by the Trainer. +When you convert to use Lightning, the code IS NOT abstracted - just organized. +All the other code that's not in the :class:`~lightning.pytorch.core.module.LightningModule` +has been automated for you by the :class:`~lightning.pytorch.trainer.trainer.Trainer`. | .. code-block:: python - net = Net() + net = MyLightningModuleNet() trainer = Trainer() trainer.fit(net) -4. There are no ``.cuda()`` or ``.to(device)`` calls required. Lightning does these for you. +There are no ``.cuda()`` or ``.to(device)`` calls required. Lightning does these for you. | @@ -57,7 +46,7 @@ Notice a few things. new_x = torch.Tensor(2, 3) new_x = new_x.to(x) -5. When running under a distributed strategy, Lightning handles the distributed sampler for you by default. +When running under a distributed strategy, Lightning handles the distributed sampler for you by default. | @@ -72,7 +61,7 @@ Notice a few things. data = MNIST(...) DataLoader(data) -6. A :class:`~LightningModule` is a :class:`torch.nn.Module` but with added functionality. Use it as such! +A :class:`~lightning.pytorch.core.module.LightningModule` is a :class:`torch.nn.Module` but with added functionality. Use it as such! | @@ -135,19 +124,19 @@ The LightningModule has many convenience methods, but the core ones you need to * - Name - Description - * - init - - Define computations here - * - forward - - Use for inference only (separate from training_step) - * - training_step - - the complete training loop - * - validation_step - - the complete validation loop - * - test_step - - the complete test loop - * - predict_step - - the complete prediction loop - * - configure_optimizers + * - ``__init__`` and :meth:`~lightning.pytorch.core.hooks.ModelHooks.setup` + - Define initialization here + * - :meth:`~lightning.pytorch.core.module.LightningModule.forward` + - To run data through your model only (separate from ``training_step``) + * - :meth:`~lightning.pytorch.core.module.LightningModule.training_step` + - the complete training step + * - :meth:`~lightning.pytorch.core.module.LightningModule.validation_step` + - the complete validation step + * - :meth:`~lightning.pytorch.core.module.LightningModule.test_step` + - the complete test step + * - :meth:`~lightning.pytorch.core.module.LightningModule.predict_step` + - the complete prediction step + * - :meth:`~lightning.pytorch.core.module.LightningModule.configure_optimizers` - define optimizers and LR schedulers ----------