mirror of
https://github.com/wassname/pytorch-lightning.git
synced 2026-09-11 12:31:23 +08:00
Deployed 62201de with MkDocs version: 1.0.4
This commit is contained in:
+239
-3
@@ -79,6 +79,10 @@
|
||||
<input class="md-toggle" data-md-toggle="search" type="checkbox" id="__search" autocomplete="off">
|
||||
<label class="md-overlay" data-md-component="overlay" for="__drawer"></label>
|
||||
|
||||
<a href="#hooks" tabindex="1" class="md-skip">
|
||||
Skip to content
|
||||
</a>
|
||||
|
||||
|
||||
<header class="md-header" data-md-component="header">
|
||||
<nav class="md-header-nav md-grid">
|
||||
@@ -406,11 +410,91 @@
|
||||
|
||||
<input class="md-toggle md-nav__toggle" data-md-toggle="toc" type="checkbox" id="__toc">
|
||||
|
||||
|
||||
|
||||
|
||||
<label class="md-nav__link md-nav__link--active" for="__toc">
|
||||
Hooks
|
||||
</label>
|
||||
|
||||
<a href="./" title="Hooks" class="md-nav__link md-nav__link--active">
|
||||
Hooks
|
||||
</a>
|
||||
|
||||
|
||||
<nav class="md-nav md-nav--secondary">
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<label class="md-nav__title" for="__toc">Table of contents</label>
|
||||
<ul class="md-nav__list" data-md-scrollfix>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#on_epoch_start" title="on_epoch_start" class="md-nav__link">
|
||||
on_epoch_start
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#on_batch_end" title="on_batch_end" class="md-nav__link">
|
||||
on_batch_end
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#on_batch_start" title="on_batch_start" class="md-nav__link">
|
||||
on_batch_start
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#on_pre_performance_check" title="on_pre_performance_check" class="md-nav__link">
|
||||
on_pre_performance_check
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#on_post_performance_check" title="on_post_performance_check" class="md-nav__link">
|
||||
on_post_performance_check
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#on_tng_metrics" title="on_tng_metrics" class="md-nav__link">
|
||||
on_tng_metrics
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#on_before_zero_grad" title="on_before_zero_grad" class="md-nav__link">
|
||||
on_before_zero_grad
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#on_after_backward" title="on_after_backward" class="md-nav__link">
|
||||
on_after_backward
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</ul>
|
||||
|
||||
</nav>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
@@ -462,6 +546,86 @@
|
||||
</div>
|
||||
|
||||
|
||||
<div class="md-sidebar md-sidebar--secondary" data-md-component="toc">
|
||||
<div class="md-sidebar__scrollwrap">
|
||||
<div class="md-sidebar__inner">
|
||||
|
||||
<nav class="md-nav md-nav--secondary">
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<label class="md-nav__title" for="__toc">Table of contents</label>
|
||||
<ul class="md-nav__list" data-md-scrollfix>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#on_epoch_start" title="on_epoch_start" class="md-nav__link">
|
||||
on_epoch_start
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#on_batch_end" title="on_batch_end" class="md-nav__link">
|
||||
on_batch_end
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#on_batch_start" title="on_batch_start" class="md-nav__link">
|
||||
on_batch_start
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#on_pre_performance_check" title="on_pre_performance_check" class="md-nav__link">
|
||||
on_pre_performance_check
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#on_post_performance_check" title="on_post_performance_check" class="md-nav__link">
|
||||
on_post_performance_check
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#on_tng_metrics" title="on_tng_metrics" class="md-nav__link">
|
||||
on_tng_metrics
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#on_before_zero_grad" title="on_before_zero_grad" class="md-nav__link">
|
||||
on_before_zero_grad
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#on_after_backward" title="on_after_backward" class="md-nav__link">
|
||||
on_after_backward
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</ul>
|
||||
|
||||
</nav>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="md-content">
|
||||
<article class="md-content__inner md-typeset">
|
||||
@@ -470,9 +634,81 @@
|
||||
<a href="https://github.com/williamFalcon/pytorch-lightning/edit/master/docs/Trainer/hooks.md" title="Edit this page" class="md-icon md-content__icon"></a>
|
||||
|
||||
|
||||
<h1>Hooks</h1>
|
||||
|
||||
|
||||
<h1 id="hooks">Hooks</h1>
|
||||
<p>[<a href="https://github.com/williamFalcon/pytorch-lightning/blob/master/pytorch_lightning/root_module/hooks.py">Github Code</a>] </p>
|
||||
<p>There are cases when you might want to do something different at different parts of the training/validation loop.
|
||||
To enable a hook, simply override the method in your LightningModule and the trainer will call it at the correct time.</p>
|
||||
<p><strong>Contributing</strong> If there's a hook you'd like to add, simply:
|
||||
1. Fork PytorchLightning.
|
||||
2. Add the hook <a href="https://github.com/williamFalcon/pytorch-lightning/blob/master/pytorch_lightning/root_module/hooks.py">here</a>. <br />
|
||||
3. Add the correct place in the <a href="https://github.com/williamFalcon/pytorch-lightning/blob/master/pytorch_lightning/models/trainer.py">Trainer</a>
|
||||
where it should be called.</p>
|
||||
<hr />
|
||||
<h4 id="on_epoch_start">on_epoch_start</h4>
|
||||
<p>Called in the training loop at the very beginning of the epoch. </p>
|
||||
<pre><code class="python">def on_epoch_start(self):
|
||||
# do something when the epoch starts
|
||||
</code></pre>
|
||||
|
||||
<hr />
|
||||
<h4 id="on_batch_end">on_batch_end</h4>
|
||||
<p>Called in the training loop at the very end of the epoch. </p>
|
||||
<pre><code class="python">def on_epoch_end(self):
|
||||
# do something when the epoch ends
|
||||
</code></pre>
|
||||
|
||||
<hr />
|
||||
<h4 id="on_batch_start">on_batch_start</h4>
|
||||
<p>Called in the training loop before anything happens for that batch. </p>
|
||||
<pre><code class="python">def on_batch_start(self):
|
||||
# do something when the batch starts
|
||||
</code></pre>
|
||||
|
||||
<hr />
|
||||
<h4 id="on_pre_performance_check">on_pre_performance_check</h4>
|
||||
<p>Called at the very beginning of the validation loop. </p>
|
||||
<pre><code class="python">def on_pre_performance_check(self):
|
||||
# do something before validation starts
|
||||
</code></pre>
|
||||
|
||||
<hr />
|
||||
<h4 id="on_post_performance_check">on_post_performance_check</h4>
|
||||
<p>Called at the very end of the validation loop. </p>
|
||||
<pre><code class="python">def on_post_performance_check(self):
|
||||
# do something before validation end
|
||||
</code></pre>
|
||||
|
||||
<hr />
|
||||
<h4 id="on_tng_metrics">on_tng_metrics</h4>
|
||||
<p>Called in the training loop, right before metrics are logged.
|
||||
Although you can log at any time by using self.experiment, you can use
|
||||
this callback to modify what will be logged.</p>
|
||||
<pre><code class="python">def on_tng_metrics(self, metrics):
|
||||
# do something before validation end
|
||||
</code></pre>
|
||||
|
||||
<hr />
|
||||
<h4 id="on_before_zero_grad">on_before_zero_grad</h4>
|
||||
<p>Called in the training loop after taking an optimizer step and before zeroing grads.
|
||||
Good place to inspect weight information with weights updated.</p>
|
||||
<p>Called once per optimizer</p>
|
||||
<pre><code class="python">def on_before_zero_grad(self, optimizer):
|
||||
# do something with the optimizer or inspect it.
|
||||
</code></pre>
|
||||
|
||||
<hr />
|
||||
<h4 id="on_after_backward">on_after_backward</h4>
|
||||
<p>Called in the training loop after model.backward()
|
||||
This is the ideal place to inspect or log gradient information </p>
|
||||
<pre><code class="python">def on_after_backward(self):
|
||||
# example to inspect gradient information in tensorboard
|
||||
if self.trainer.global_step % 25 == 0: # don't make the tf file huge
|
||||
params = self.state_dict()
|
||||
for k, v in params.items():
|
||||
grads = v
|
||||
name = k
|
||||
self.experiment.add_histogram(tag=name, values=grads, global_step=self.trainer.global_step)
|
||||
</code></pre>
|
||||
|
||||
|
||||
|
||||
|
||||
File diff suppressed because one or more lines are too long
+14
-14
@@ -2,72 +2,72 @@
|
||||
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
|
||||
<url>
|
||||
<loc>None</loc>
|
||||
<lastmod>2019-07-27</lastmod>
|
||||
<lastmod>2019-07-28</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>None</loc>
|
||||
<lastmod>2019-07-27</lastmod>
|
||||
<lastmod>2019-07-28</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>None</loc>
|
||||
<lastmod>2019-07-27</lastmod>
|
||||
<lastmod>2019-07-28</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>None</loc>
|
||||
<lastmod>2019-07-27</lastmod>
|
||||
<lastmod>2019-07-28</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>None</loc>
|
||||
<lastmod>2019-07-27</lastmod>
|
||||
<lastmod>2019-07-28</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>None</loc>
|
||||
<lastmod>2019-07-27</lastmod>
|
||||
<lastmod>2019-07-28</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>None</loc>
|
||||
<lastmod>2019-07-27</lastmod>
|
||||
<lastmod>2019-07-28</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>None</loc>
|
||||
<lastmod>2019-07-27</lastmod>
|
||||
<lastmod>2019-07-28</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>None</loc>
|
||||
<lastmod>2019-07-27</lastmod>
|
||||
<lastmod>2019-07-28</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>None</loc>
|
||||
<lastmod>2019-07-27</lastmod>
|
||||
<lastmod>2019-07-28</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>None</loc>
|
||||
<lastmod>2019-07-27</lastmod>
|
||||
<lastmod>2019-07-28</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>None</loc>
|
||||
<lastmod>2019-07-27</lastmod>
|
||||
<lastmod>2019-07-28</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>None</loc>
|
||||
<lastmod>2019-07-27</lastmod>
|
||||
<lastmod>2019-07-28</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>None</loc>
|
||||
<lastmod>2019-07-27</lastmod>
|
||||
<lastmod>2019-07-28</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
</urlset>
|
||||
Binary file not shown.
Reference in New Issue
Block a user