Skip to content

Commit f162335

Browse files
awaelchlitchatonrohitgr7
authored
Add example table to loop docs (#10058)
Co-authored-by: tchaton <[email protected]> Co-authored-by: Rohit Gupta <[email protected]>
1 parent 47e7a28 commit f162335

File tree

2 files changed

+33
-9
lines changed

2 files changed

+33
-9
lines changed

docs/source/extensions/loops.rst

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -411,18 +411,33 @@ To run the following demo, install Flash and `BaaL <https://github.com/ElementAI
411411
Here is the `Active Learning Loop example <https://github.com/PyTorchLightning/lightning-flash/blob/master/flash_examples/integrations/baal/image_classification_active_learning.py>`_ and the `code for the active learning loop <https://github.com/PyTorchLightning/lightning-flash/blob/master/flash/image/classification/integrations/baal/loop.py#L31>`_.
412412

413413

414-
`KFold / Cross Validation <https://en.wikipedia.org/wiki/Cross-validation_(statistics)>`__ is a machine learning practice in which the training dataset is being partitioned into `num_folds` complementary subsets.
415-
One cross validation round will perform fitting where one fold is left out for validation and the other folds are used for training.
416-
To reduce variability, once all rounds are performed using the different folds, the trained models are ensembled and their predictions are
417-
averaged when estimating the model's predictive performance on the test dataset.
418-
KFold can elegantly be implemented with `Lightning Loop Customization` as follows:
414+
----------
415+
416+
Advanced Examples
417+
-----------------
418+
419+
420+
.. list-table:: Ready-to-run loop examples and tutorials
421+
:widths: 25 75
422+
:header-rows: 1
419423

420-
Here is the `KFold Loop example <https://github.com/PyTorchLightning/pytorch-lightning/blob/master/pl_examples/loops/kfold.py>`_.
424+
* - Link to Example
425+
- Description
426+
* - `K-fold Cross Validation <https://github.com/PyTorchLightning/pytorch-lightning/blob/master/pl_examples/loop_examples/kfold.py>`_
427+
- `KFold / Cross Validation <https://en.wikipedia.org/wiki/Cross-validation_(statistics)>`__ is a machine learning practice in which the training dataset is being partitioned into ``num_folds`` complementary subsets.
428+
One cross validation round will perform fitting where one fold is left out for validation and the other folds are used for training.
429+
To reduce variability, once all rounds are performed using the different folds, the trained models are ensembled and their predictions are
430+
averaged when estimating the model's predictive performance on the test dataset.
431+
* - `Yielding Training Step <https://github.com/PyTorchLightning/pytorch-lightning/blob/master/pl_examples/loop_examples/yielding_training_step.py>`_
432+
- This loop enables you to write the :meth:`~pytorch_lightning.core.lightning.LightningModule.training_step` hook
433+
as a Python Generator for automatic optimization with multiple optimizers, i.e., you can :code:`yield` loss
434+
values from it instead of returning them. This can enable more elegant and expressive implementations, as shown
435+
shown with a GAN in this example.
421436

422437

423438
----------
424439

425-
Advanced Topics and Examples
426-
----------------------------
440+
Advanced Features
441+
-----------------
427442

428-
Next: :doc:`Advanced loop features and examples <../extensions/loops_advanced>`
443+
Next: :doc:`Advanced loop features <../extensions/loops_advanced>`

pl_examples/README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,12 @@ ______________________________________________________________________
2020
This folder contains older examples. You should instead use the examples
2121
in [lightning-bolts](https://pytorch-lightning.readthedocs.io/en/latest/ecosystem/bolts.html)
2222
for advanced use cases.
23+
24+
______________________________________________________________________
25+
26+
## Loop examples
27+
28+
Contains implementations leveraging [loop customization](https://pytorch-lightning.readthedocs.io/en/latest/extensions/loops.html) to enhance the Trainer with new optimization routines.
29+
30+
- [K-fold Cross Validation Loop](./loop_examples/kfold.py): Implemenation of cross validation in a loop and special datamodule.
31+
- [Yield Loop](./loop_examples/yielding_training_step.py): Enables yielding from the training_step like in a Python generator. Useful for automatic optimization with multiple optimizers.

0 commit comments

Comments
 (0)