optimizer_schedules.rst 1.7 KB
Newer Older
1
Optimization
thomwolf's avatar
thomwolf committed
2
3
----------------------------------------------------

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

10
11
``AdamW`` (PyTorch)
~~~~~~~~~~~~~~~~~~~
thomwolf's avatar
thomwolf committed
12

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

16
17
``AdamWeightDecay`` (TensorFlow)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
18
19
20
21
22

.. autoclass:: transformers.AdamWeightDecay

.. autofunction:: transformers.create_optimizer

thomwolf's avatar
thomwolf committed
23
Schedules
24
25
26
27
~~~~~~~~~~~~~~~~~~~

Learning Rate Schedules (Pytorch)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
thomwolf's avatar
thomwolf committed
28

29
.. autofunction:: transformers.get_constant_schedule
thomwolf's avatar
thomwolf committed
30

31

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

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


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

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


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

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



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

.. image:: /imgs/warmup_linear_schedule.png
    :target: /imgs/warmup_linear_schedule.png
    :alt:
59

60
61
``Warmup`` (TensorFlow)
^^^^^^^^^^^^^^^^^^^^^^^
62

63
.. autoclass:: transformers.WarmUp
64
65
66
    :members:

Gradient Strategies
67
~~~~~~~~~~~~~~~~~~~~
68

69
70
``GradientAccumulator`` (TensorFlow)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
71
72

.. autoclass:: transformers.GradientAccumulator