{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "## Classes for callback implementors" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "hide_input": true }, "outputs": [], "source": [ "from fastai.gen_doc.nbdoc import *\n", "from fastai.callback import * \n", "from fastai.basics import *" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "fastai provides a powerful *callback* system, which is documented on the [`callbacks`](/callbacks.html#callbacks) page; look on that page if you're just looking for how to use existing callbacks. If you want to create your own, you'll need to use the classes discussed below.\n", "\n", "A key motivation for the callback system is that additional functionality can be entirely implemented in a single callback, so that it's easily read. By using this trick, we will have different methods categorized in different callbacks where we will find clearly stated all the interventions the method makes in training. For instance in the [`LRFinder`](/callbacks.lr_finder.html#LRFinder) callback, on top of running the fit function with exponentially growing LRs, it needs to handle some preparation and clean-up, and all this code can be in the same callback so we know exactly what it is doing and where to look if we need to change something.\n", "\n", "In addition, it allows our [`fit`](/basic_train.html#fit) function to be very clean and simple, yet still easily extended. So far in implementing a number of recent papers, we haven't yet come across any situation where we had to modify our training loop source code - we've been able to use callbacks every time." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "hide_input": true }, "outputs": [ { "data": { "text/markdown": [ "
class Callback[source][test]Callback()\n",
"\n",
"on_train_begin[source][test]on_train_begin(**\\*\\*`kwargs`**:`Any`)\n",
"\n",
"No tests found for on_train_begin. To contribute a test please refer to this guide and this discussion.
on_epoch_begin[source][test]on_epoch_begin(**\\*\\*`kwargs`**:`Any`)\n",
"\n",
"No tests found for on_epoch_begin. To contribute a test please refer to this guide and this discussion.
on_batch_begin[source][test]on_batch_begin(**\\*\\*`kwargs`**:`Any`)\n",
"\n",
"No tests found for on_batch_begin. To contribute a test please refer to this guide and this discussion.
on_loss_begin[source][test]on_loss_begin(**\\*\\*`kwargs`**:`Any`)\n",
"\n",
"No tests found for on_loss_begin. To contribute a test please refer to this guide and this discussion.
on_backward_begin[source][test]on_backward_begin(**\\*\\*`kwargs`**:`Any`)\n",
"\n",
"No tests found for on_backward_begin. To contribute a test please refer to this guide and this discussion.
on_backward_end[source][test]on_backward_end(**\\*\\*`kwargs`**:`Any`)\n",
"\n",
"No tests found for on_backward_end. To contribute a test please refer to this guide and this discussion.
on_step_end[source][test]on_step_end(**\\*\\*`kwargs`**:`Any`)\n",
"\n",
"No tests found for on_step_end. To contribute a test please refer to this guide and this discussion.
on_batch_end[source][test]on_batch_end(**\\*\\*`kwargs`**:`Any`)\n",
"\n",
"No tests found for on_batch_end. To contribute a test please refer to this guide and this discussion.
on_epoch_end[source][test]on_epoch_end(**\\*\\*`kwargs`**:`Any`)\n",
"\n",
"No tests found for on_epoch_end. To contribute a test please refer to this guide and this discussion.
on_train_end[source][test]on_train_end(**\\*\\*`kwargs`**:`Any`)\n",
"\n",
"No tests found for on_train_end. To contribute a test please refer to this guide and this discussion.
get_state[source][test]get_state(**`minimal`**:`bool`=***`True`***)\n",
"\n",
"No tests found for get_state. To contribute a test please refer to this guide and this discussion.
annealing_cos[source][test]annealing_cos(**`start`**:`Number`, **`end`**:`Number`, **`pct`**:`float`) → `Number`\n",
"\n",
"No tests found for annealing_cos. To contribute a test please refer to this guide and this discussion.
annealing_exp[source][test]annealing_exp(**`start`**:`Number`, **`end`**:`Number`, **`pct`**:`float`) → `Number`\n",
"\n",
"No tests found for annealing_exp. To contribute a test please refer to this guide and this discussion.
annealing_linear[source][test]annealing_linear(**`start`**:`Number`, **`end`**:`Number`, **`pct`**:`float`) → `Number`\n",
"\n",
"No tests found for annealing_linear. To contribute a test please refer to this guide and this discussion.
annealing_no[source][test]annealing_no(**`start`**:`Number`, **`end`**:`Number`, **`pct`**:`float`) → `Number`\n",
"\n",
"No tests found for annealing_no. To contribute a test please refer to this guide and this discussion.
annealing_poly[source][test]annealing_poly(**`degree`**:`Number`) → `Number`\n",
"\n",
"No tests found for annealing_poly. To contribute a test please refer to this guide and this discussion.
class CallbackHandler[source][test]CallbackHandler(**`callbacks`**:`Collection`\\[[`Callback`](/callback.html#Callback)\\]=***`None`***, **`metrics`**:`Collection`\\[[`Callback`](/callback.html#Callback)\\]=***`None`***, **`beta`**:`float`=***`0.98`***)\n",
"\n",
"No tests found for CallbackHandler. To contribute a test please refer to this guide and this discussion.
on_backward_begin[source][test]on_backward_begin(**`loss`**:`Tensor`)\n",
"\n",
"No tests found for on_backward_begin. To contribute a test please refer to this guide and this discussion.
on_backward_end[source][test]on_backward_end()\n",
"\n",
"No tests found for on_backward_end. To contribute a test please refer to this guide and this discussion.
on_batch_begin[source][test]on_batch_begin(**`xb`**:`Tensor`, **`yb`**:`Tensor`, **`train`**:`bool`=***`True`***)\n",
"\n",
"No tests found for on_batch_begin. To contribute a test please refer to this guide and this discussion.
on_batch_end[source][test]on_batch_end(**`loss`**:`Tensor`)\n",
"\n",
"No tests found for on_batch_end. To contribute a test please refer to this guide and this discussion.
on_epoch_begin[source][test]on_epoch_begin()\n",
"\n",
"No tests found for on_epoch_begin. To contribute a test please refer to this guide and this discussion.
on_epoch_end[source][test]on_epoch_end(**`val_loss`**:`Tensor`) → `bool`\n",
"\n",
"No tests found for on_epoch_end. To contribute a test please refer to this guide and this discussion.
on_loss_begin[source][test]on_loss_begin(**`out`**:`Tensor`)\n",
"\n",
"No tests found for on_loss_begin. To contribute a test please refer to this guide and this discussion.
on_step_end[source][test]on_step_end()\n",
"\n",
"No tests found for on_step_end. To contribute a test please refer to this guide and this discussion.
on_train_begin[source][test]on_train_begin(**`epochs`**:`int`, **`pbar`**:`PBar`, **`metrics`**:`MetricFuncList`)\n",
"\n",
"No tests found for on_train_begin. To contribute a test please refer to this guide and this discussion.
on_train_end[source][test]on_train_end(**`exception`**:`Union`\\[`bool`, `Exception`\\])\n",
"\n",
"No tests found for on_train_end. To contribute a test please refer to this guide and this discussion.
set_dl[source][test]set_dl(**`dl`**:[`DataLoader`](https://pytorch.org/docs/stable/data.html#torch.utils.data.DataLoader))\n",
"\n",
"No tests found for set_dl. To contribute a test please refer to this guide and this discussion.
class OptimWrapper[source][test]OptimWrapper(**`opt`**:[`Optimizer`](https://pytorch.org/docs/stable/optim.html#torch.optim.Optimizer), **`wd`**:`Floats`=***`0.0`***, **`true_wd`**:`bool`=***`False`***, **`bn_wd`**:`bool`=***`True`***)\n",
"\n",
"No tests found for OptimWrapper. To contribute a test please refer to this guide and this discussion.
clear[source][test]clear()\n",
"\n",
"No tests found for clear. To contribute a test please refer to this guide and this discussion.
create[source][test]create(**`opt_func`**:`Union`\\[`type`, `Callable`\\], **`lr`**:`Union`\\[`float`, `Tuple`, `List`\\[`T`\\]\\], **`layer_groups`**:`ModuleList`, **`wd`**:`Floats`=***`0.0`***, **`true_wd`**:`bool`=***`False`***, **`bn_wd`**:`bool`=***`True`***) → [`Optimizer`](https://pytorch.org/docs/stable/optim.html#torch.optim.Optimizer)\n",
"\n",
"No tests found for create. To contribute a test please refer to this guide and this discussion.
new[source][test]new(**`layer_groups`**:`ModuleList`, **`split_no_wd`**:`bool`=***`True`***)\n",
"\n",
"No tests found for new. To contribute a test please refer to this guide and this discussion.
read_defaults[source][test]read_defaults()\n",
"\n",
"No tests found for read_defaults. To contribute a test please refer to this guide and this discussion.
read_val[source][test]read_val(**`key`**:`str`) → `Union`\\[`List`\\[`float`\\], `Tuple`\\[`List`\\[`float`\\], `List`\\[`float`\\]\\]\\]\n",
"\n",
"No tests found for read_val. To contribute a test please refer to this guide and this discussion.
set_val[source][test]set_val(**`key`**:`str`, **`val`**:`Any`, **`bn_groups`**:`bool`=***`True`***) → `Any`\n",
"\n",
"No tests found for set_val. To contribute a test please refer to this guide and this discussion.
step[source][test]step()\n",
"\n",
"No tests found for step. To contribute a test please refer to this guide and this discussion.
zero_grad[source][test]zero_grad()\n",
"\n",
"No tests found for zero_grad. To contribute a test please refer to this guide and this discussion.
class SmoothenValue[source][test]SmoothenValue(**`beta`**:`float`)\n",
"\n",
"No tests found for SmoothenValue. To contribute a test please refer to this guide and this discussion.
add_value[source][test]add_value(**`val`**:`float`)\n",
"\n",
"No tests found for add_value. To contribute a test please refer to this guide and this discussion.
class Scheduler[source][test]Scheduler(**`vals`**:`StartOptEnd`, **`n_iter`**:`int`, **`func`**:`Optional`\\[`AnnealFunc`\\]=***`None`***)\n",
"\n",
"No tests found for Scheduler. To contribute a test please refer to this guide and this discussion.
step[source][test]step() → `Number`\n",
"\n",
"No tests found for step. To contribute a test please refer to this guide and this discussion.
class AverageMetric[source][test]AverageMetric(**`func`**) :: [`Callback`](/callback.html#Callback)\n",
"\n",
"No tests found for AverageMetric. To contribute a test please refer to this guide and this discussion.
on_epoch_begin[source][test]on_epoch_begin(**\\*\\*`kwargs`**)\n",
"\n",
"No tests found for on_epoch_begin. To contribute a test please refer to this guide and this discussion.
on_batch_end[source][test]on_batch_end(**`last_output`**, **`last_target`**, **\\*\\*`kwargs`**)\n",
"\n",
"No tests found for on_batch_end. To contribute a test please refer to this guide and this discussion.
on_epoch_end[source][test]on_epoch_end(**`last_metrics`**, **\\*\\*`kwargs`**)\n",
"\n",
"No tests found for on_epoch_end. To contribute a test please refer to this guide and this discussion.