-
Notifications
You must be signed in to change notification settings - Fork 3.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
loop customization docs #9557
loop customization docs #9557
Conversation
+---------------------------------------------------------------+-----------------------------------------------------------------------+-------------------------------------------------------------------------------+ | ||
| Entry point | Trainer attribute | Loop class | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is supposed to be a table, sorry this may look messed up in your browser when viewing the diff
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Neat ! Good idea to show entry points !
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this may look messed up in your browser
For better text readability, we could use .. list-table::
as we do in Bolts maybe?
source: https://github.com/PyTorchLightning/lightning-bolts/blame/master/docs/source/deprecated/models/self_supervised.rst#L148
built page: https://lightning-bolts.readthedocs.io/en/latest/deprecated/models/self_supervised.html#cifar-10-and-stl-10-baselines
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks better on the source code. let's do it
Build Error! No Linked Issue found. Please link an issue or mention it in the body using #<issue_id> |
hey @tchaton can we disable the bot for documentation updates? |
Codecov Report
@@ Coverage Diff @@
## master #9557 +/- ##
======================================
- Coverage 93% 93% -0%
======================================
Files 180 180
Lines 15090 15116 +26
======================================
+ Hits 14019 14043 +24
- Misses 1071 1073 +2 |
Can we also add this to the Also in general: This is part of the public facing lightning API. I find it strange, that the API section only covers trainer and LightningModule. |
Yes, I need to implement this. I will try this weekend. Best, |
Co-authored-by: Carlos Mocholí <carlossmocholi@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome work !
docs/source/advanced/loops.rst
Outdated
- how you can create a custom loop for a new training step flavor, | ||
- and how you can connect the custom loop and run it. | ||
|
||
Most importantly, we will also provide guidelines when to use loop customization and when NOT to use it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Most importantly, we will also provide guidelines when to use loop customization and when NOT to use it. | |
Most importantly, we will provide guidelines when to use loop customization and when NOT to use it. |
+---------------------------------------------------------------+-----------------------------------------------------------------------+-------------------------------------------------------------------------------+ | ||
| Entry point | Trainer attribute | Loop class | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Neat ! Good idea to show entry points !
docs/source/advanced/loops.rst
Outdated
| :meth:`~pytorch_lightning.trainer.trainer.Trainer.predict` | :attr:`~pytorch_lightning.trainer.trainer.Trainer.predict_loop` | :class:`~pytorch_lightning.loops.dataloader.prediction_loop.PredictionLoop` | | ||
+---------------------------------------------------------------+-----------------------------------------------------------------------+-------------------------------------------------------------------------------+ | ||
|
||
When the user calls :code:`Trainer.method`, it redirects to the corresponding :code:`Trainer.loop.run()` which implements the main logic of that particular Lightning loop. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When the user calls :code:`Trainer.method`, it redirects to the corresponding :code:`Trainer.loop.run()` which implements the main logic of that particular Lightning loop. | |
When the user calls :code:`Trainer.method`, it redirects to the corresponding :code:`Trainer.loop.run()` which implements the associated logic of this particular Lightning Loop. |
Set the environment variable `PL_FAULT_TOLERANT_TRAINING = 1` to enable saving the progress of loops. | ||
Read more about :doc:`fault-tolerant training training <../advanced/fault_tolerant_training>`. | ||
|
||
An interesting property of the abstract loop interface is that it can maintain a state. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An interesting property of the abstract loop interface is that it can maintain a state. | |
The PyTorch Lightning Loop state management design is highly inspired from the PyTorch nn.Module and relies on the same underlying logic. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
actually all I want to express here is that the benefit of having loops as objects is that they can have state.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know, but I built the state management exactly as pytorch ones. Advanced users are already familiar with it, and it means they will understand faster how it works. Just a personal suggestion.
Read more about :doc:`fault-tolerant training training <../advanced/fault_tolerant_training>`. | ||
|
||
An interesting property of the abstract loop interface is that it can maintain a state. | ||
It can save its state to a checkpoint through corresponding hooks and if implemented accordingly, resume it's state of exectuion at the appropriate place. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It can save its state to a checkpoint through corresponding hooks and if implemented accordingly, resume it's state of exectuion at the appropriate place. | |
As a result, the loops can save their state and their children within the model checkpoint through corresponding hooks and if implemented accordingly, resume their state of execution at the appropriate place. |
|
||
An interesting property of the abstract loop interface is that it can maintain a state. | ||
It can save its state to a checkpoint through corresponding hooks and if implemented accordingly, resume it's state of exectuion at the appropriate place. | ||
This design is particularly interesting for fault-tolerant training which is an experimental feature released in Lightning v1.5. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This design is particularly interesting for fault-tolerant training which is an experimental feature released in Lightning v1.5. | |
As a matter of facts, all the Lightning loops implements an advanced state management which is the underlying mechanism of a long waited feature: Fault Tolerant Training which is an experimental feature released in Lightning v1.5. |
|
||
**How do I make sure a given LightningModule is compatible with my custom loop?** | ||
|
||
To restrict the compatibility of a LightningModule to a particular loop type, we recommend to define a specific class mixin for this purpose. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dope ! Really neat :)
@justusschock sounds good, can move it to "Optional Extensions" section under plugins if others agree @carmocca @tchaton .
We have two sections, one is just called "Lightning API" and the other "API Reference" which is supposed to contain all public facing api. The difference is that the former is more a user guide and the latter is just the api reference nothing more. we could probably do a better naming there. |
Co-authored-by: thomas chaton <thomas@grid.ai>
for more information, see https://pre-commit.ci
from pytorch_lightning.loops.utilities import _build_training_step_kwargs | ||
|
||
|
||
class YieldLoop(OptimizerLoop): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@awaelchli, would mind making sure the code isn't too long. Maybe 80 lines. It doesn't render very well in the doc.
will rewrite the docs and send new pr. |
What does this PR do?
Adds a user guide for loops in Lightning. Contains:
Also adds the loop base class to the API reference section.
You can check the docs build by clicking here:
Then go to Artifacts and navigate to loops.html.
Or if you have access to circle-ci: https://129946-178626720-gh.circle-artifacts.com/0/html/advanced/loops.html
Part of #7938
Before submitting
PR review
Anyone in the community is free to review the PR once the tests have passed.
Before you start reviewing make sure you have read Review guidelines. In short, see the following bullet-list:
Did you have fun?
I made sure I had fun coding 🙃