optimizer_schedules.rst 1.74 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
23
24
``AdamWeightDecay``
~~~~~~~~~~~~~~~~~~~

.. autoclass:: transformers.AdamWeightDecay
    :members:

.. autofunction:: transformers.create_optimizer
    :members:

thomwolf's avatar
thomwolf committed
25
26
27
Schedules
----------------------------------------------------

28
29
30
Learning Rate Schedules
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

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

33

34
.. autofunction:: transformers.get_constant_schedule_with_warmup
thomwolf's avatar
thomwolf committed
35

36
37
38
39
40
.. image:: /imgs/warmup_constant_schedule.png
    :target: /imgs/warmup_constant_schedule.png
    :alt:


41
.. autofunction:: transformers.get_cosine_schedule_with_warmup
thomwolf's avatar
thomwolf committed
42
43
    :members:

44
45
46
47
48
.. image:: /imgs/warmup_cosine_schedule.png
    :target: /imgs/warmup_cosine_schedule.png
    :alt:


49
.. autofunction:: transformers.get_cosine_with_hard_restarts_schedule_with_warmup
thomwolf's avatar
thomwolf committed
50

51
52
53
54
55
56
.. image:: /imgs/warmup_cosine_hard_restarts_schedule.png
    :target: /imgs/warmup_cosine_hard_restarts_schedule.png
    :alt:



57
.. autofunction:: transformers.get_linear_schedule_with_warmup
58
59
60
61

.. image:: /imgs/warmup_linear_schedule.png
    :target: /imgs/warmup_linear_schedule.png
    :alt:
62
63
64
65
66
67
68
69
70
71
72
73
74
75

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

.. autoclass:: transformers.Warmup
    :members:

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

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

.. autoclass:: transformers.GradientAccumulator