"deploy/vscode:/vscode.git/clone" did not exist on "7c09c97d70486d8749c71a67daac28b67a7a7e12"
callback.rst 4.09 KB
Newer Older
Sylvain Gugger's avatar
Sylvain Gugger committed
1
2
3
4
5
6
7
8
9
10
11
12
.. 
    Copyright 2020 The HuggingFace Team. All rights reserved.

    Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
    the License. You may obtain a copy of the License at

        http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
    an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
    specific language governing permissions and limitations under the License.

Sylvain Gugger's avatar
Sylvain Gugger committed
13
14
15
16
17
18
19
20
21
22
23
24
25
26
Callbacks
-----------------------------------------------------------------------------------------------------------------------

Callbacks are objects that can customize the behavior of the training loop in the PyTorch
:class:`~transformers.Trainer` (this feature is not yet implemented in TensorFlow) that can inspect the training loop
state (for progress reporting, logging on TensorBoard or other ML platforms...) and take decisions (like early
stopping).

Callbacks are "read only" pieces of code, apart from the :class:`~transformers.TrainerControl` object they return, they
cannot change anything in the training loop. For customizations that require changes in the training loop, you should
subclass :class:`~transformers.Trainer` and override the methods you need (see :doc:`trainer` for examples).

By default a :class:`~transformers.Trainer` will use the following callbacks:

Tiger's avatar
Tiger committed
27
- :class:`~transformers.DefaultFlowCallback` which handles the default behavior for logging, saving and evaluation.
28
- :class:`~transformers.PrinterCallback` or :class:`~transformers.ProgressCallback` to display progress and print the
Sylvain Gugger's avatar
Sylvain Gugger committed
29
30
31
32
33
34
  logs (the first one is used if you deactivate tqdm through the :class:`~transformers.TrainingArguments`, otherwise
  it's the second one).
- :class:`~transformers.integrations.TensorBoardCallback` if tensorboard is accessible (either through PyTorch >= 1.4
  or tensorboardX).
- :class:`~transformers.integrations.WandbCallback` if `wandb <https://www.wandb.com/>`__ is installed.
- :class:`~transformers.integrations.CometCallback` if `comet_ml <https://www.comet.ml/site/>`__ is installed.
35
- :class:`~transformers.integrations.MLflowCallback` if `mlflow <https://www.mlflow.org/>`__ is installed.
36
37
- :class:`~transformers.integrations.AzureMLCallback` if `azureml-sdk <https://pypi.org/project/azureml-sdk/>`__ is
  installed.
Sylvain Gugger's avatar
Sylvain Gugger committed
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58

The main class that implements callbacks is :class:`~transformers.TrainerCallback`. It gets the
:class:`~transformers.TrainingArguments` used to instantiate the :class:`~transformers.Trainer`, can access that
Trainer's internal state via :class:`~transformers.TrainerState`, and can take some actions on the training loop via
:class:`~transformers.TrainerControl`.


Available Callbacks
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Here is the list of the available :class:`~transformers.TrainerCallback` in the library:

.. autoclass:: transformers.integrations.CometCallback
    :members: setup

.. autoclass:: transformers.DefaultFlowCallback

.. autoclass:: transformers.PrinterCallback

.. autoclass:: transformers.ProgressCallback

59
60
.. autoclass:: transformers.EarlyStoppingCallback

Sylvain Gugger's avatar
Sylvain Gugger committed
61
62
63
64
65
.. autoclass:: transformers.integrations.TensorBoardCallback

.. autoclass:: transformers.integrations.WandbCallback
    :members: setup

66
67
68
.. autoclass:: transformers.integrations.MLflowCallback
    :members: setup

69
.. autoclass:: transformers.integrations.AzureMLCallback
Sylvain Gugger's avatar
Sylvain Gugger committed
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89

TrainerCallback
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

.. autoclass:: transformers.TrainerCallback
    :members:


TrainerState
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

.. autoclass:: transformers.TrainerState
    :members:


TrainerControl
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

.. autoclass:: transformers.TrainerControl
    :members: