optimizer_schedules.rst 1.69 KB
Newer Older
thomwolf's avatar
thomwolf committed
1
2
3
Optimizer
----------------------------------------------------

4
5
6
7
The ``.optimization`` module provides:

- an optimizer with weight decay fixed that can be used to fine-tuned models, and
- several schedules in the form of schedule objects that inherit from ``_LRSchedule``:
8
- a gradient accumulation class to accumulate the gradients of multiple batches
9

thomwolf's avatar
thomwolf committed
10
11
12
``AdamW``
~~~~~~~~~~~~~~~~

13
.. autoclass:: transformers.AdamW
thomwolf's avatar
thomwolf committed
14
15
    :members:

16
17
18
19
20
21
22
``AdamWeightDecay``
~~~~~~~~~~~~~~~~~~~

.. autoclass:: transformers.AdamWeightDecay

.. autofunction:: transformers.create_optimizer

thomwolf's avatar
thomwolf committed
23
24
25
Schedules
----------------------------------------------------

26
Learning Rate Schedules
27
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
28
.. autofunction:: transformers.get_constant_schedule
thomwolf's avatar
thomwolf committed
29

30

31
.. autofunction:: transformers.get_constant_schedule_with_warmup
thomwolf's avatar
thomwolf committed
32

33
34
35
36
37
.. image:: /imgs/warmup_constant_schedule.png
    :target: /imgs/warmup_constant_schedule.png
    :alt:


38
.. autofunction:: transformers.get_cosine_schedule_with_warmup
thomwolf's avatar
thomwolf committed
39

40
41
42
43
44
.. image:: /imgs/warmup_cosine_schedule.png
    :target: /imgs/warmup_cosine_schedule.png
    :alt:


45
.. autofunction:: transformers.get_cosine_with_hard_restarts_schedule_with_warmup
thomwolf's avatar
thomwolf committed
46

47
48
49
50
51
52
.. image:: /imgs/warmup_cosine_hard_restarts_schedule.png
    :target: /imgs/warmup_cosine_hard_restarts_schedule.png
    :alt:



53
.. autofunction:: transformers.get_linear_schedule_with_warmup
54
55
56
57

.. image:: /imgs/warmup_linear_schedule.png
    :target: /imgs/warmup_linear_schedule.png
    :alt:
58
59
60
61

``Warmup``
~~~~~~~~~~~~~~~~

62
.. autoclass:: transformers.WarmUp
63
64
65
66
67
68
69
70
71
    :members:

Gradient Strategies
----------------------------------------------------

``GradientAccumulator``
~~~~~~~~~~~~~~~~~~~~~~~

.. autoclass:: transformers.GradientAccumulator