Document feedback

Question document fragment

When a question document fragment contains a formula, it is displayed as a space.

Submission type
issue

It's a little complicated...

I'd like to ask someone.

PR

Just a small problem.

I can fix it online!

Please select the submission type

Problem type
Specifications and Common Mistakes

- Specifications and Common Mistakes:

- Misspellings or punctuation mistakes,incorrect formulas, abnormal display.

- Incorrect links, empty cells, or wrong formats.

- Chinese characters in English context.

- Minor inconsistencies between the UI and descriptions.

- Low writing fluency that does not affect understanding.

- Incorrect version numbers, including software package names and version numbers on the UI.

Usability

- Usability:

- Incorrect or missing key steps.

- Missing main function descriptions, keyword explanation, necessary prerequisites, or precautions.

- Ambiguous descriptions, unclear reference, or contradictory context.

- Unclear logic, such as missing classifications, items, and steps.

Correctness

- Correctness:

- Technical principles, function descriptions, supported platforms, parameter types, or exceptions inconsistent with that of software implementation.

- Incorrect schematic or architecture diagrams.

- Incorrect commands or command parameters.

- Incorrect code.

- Commands inconsistent with the functions.

- Wrong screenshots.

- Sample code running error, or running results inconsistent with the expectation.

Risk Warnings

- Risk Warnings:

- Lack of risk warnings for operations that may damage the system or important data.

Content Compliance

- Content Compliance:

- Contents that may violate applicable laws and regulations or geo-cultural context-sensitive words and expressions.

- Copyright infringement.

Please select the type of question

Problem description

Describe the bug so that we can quickly locate the problem.

mindformers.core.PolynomialWithWarmUpLR

View Source On Gitee
class mindformers.core.PolynomialWithWarmUpLR(learning_rate: float, total_steps: int, warmup_steps: int = None, lr_end: float = 1e-7, power: float = 1.0, warmup_lr_init: float = 0., warmup_ratio: float = None, decay_steps: int = None, **kwargs)[source]

Polynomial with Warm Up Learning Rate.

At the beginning of training, the learning rate gradually increases from a lower initial value, ηwarmup , to the starting learning rate, ηstart . The change in learning rate during the warm-up phase, depending on the step t , is described by the following formula:

ηt=ηwarmup+t×ηstartηwarmupwarmup_steps

where warmup\_steps represents the total number of steps in the warm-up phase.

After the warm-up phase concludes, the learning rate gradually decays according to a polynomial function, reaching the final learning rate, ηend . The change in learning rate over the total number of steps total\_steps is given by the formula:

ηt=ηend+(ηstartηend)×(1twarmup_stepsdecay_steps)power

where power is the exponent of the polynomial, controlling the decay rate.

This learning rate strategy is well-suited for scenarios where a stable learning rate is needed during the early stages of training, with a gradual decrease in the later stages. By preventing gradient explosion initially and reducing the learning rate during the latter part of training, it helps the model achieve better generalization as it converges.

Parameters
  • learning_rate (float) – Initial value of learning rate.

  • total_steps (int) – The number of total steps.

  • warmup_steps (int) – The number of warm up steps.

  • lr_end (float, optional) – Final value of learning rate. Default: 1e-7.

  • power (float, optional) – The power of the polynomial. Default: 1.0.

  • warmup_lr_init (float, optional) – Initial learning rate in warm up steps. Default: 0..

  • warmup_ratio (float, optional) – Ratio of total training steps used for warmup. Default: None.

  • decay_steps (int, optional) – The number of decay steps, which must be smaller than total_steps - warmup_steps. If the value is None, decay steps will be total_steps - warmup_steps. Default: None.

Inputs:
  • global_step (int) - The global step.

Outputs:

Learning rate.

Examples

>>> import mindspore as ms
>>> from mindformers.core import PolynomialWithWarmUpLR
>>>
>>> ms.set_context(mode=ms.GRAPH_MODE)
>>> total_steps = 20
>>> warmup_steps = 10
>>> learning_rate = 0.005
>>> lr_end = 0.0000001
>>>
>>> polynomial_warmup = PolynomialWithWarmUpLR(learning_rate=learning_rate,
...                                            warmup_steps=warmup_steps,
...                                            total_steps=total_steps,
...                                            lr_end=lr_end)
>>> print(polynomial_warmup(1))
0.0005
>>> print(polynomial_warmup(15))
0.0025000498