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.

mindearth.core.get_warmup_cosine_annealing_lr

View Source On Gitee
mindearth.core.get_warmup_cosine_annealing_lr(lr_init, steps_per_epoch, last_epoch, warmup_epochs=0, warmup_lr_init=0.0, eta_min=1e-06)[source]

Calculates learning rate base on cosine decay function. If warmup epoch is specified, the warmup epoch will be warmed up by linear annealing.

For the i-th step, the formula of computing cosine decayed_learning_rate[i] is:

decayed_learning_rate[i]=eta_min+0.5(lr_initeta_min)(1+cos(current_epochlast_epochπ))

Where current_epoch=floor(isteps_per_epoch).

If warmup epoch is specified, for the i-th step in waramup epoch, the formula of computing

warmup_learning_rate[i] is:

warmup_learning_rate[i]=(lr_initwarmup_lr_init)i/warmup_steps+warmup_lr_init
Parameters
  • lr_init (float) – init learning rate, positive float value.

  • steps_per_epoch (int) – number of steps to each epoch, positive int value.

  • last_epoch (int) – total epoch of training, positive int value.

  • warmup_epochs (int) – total epoch of warming up, default:0.

  • warmup_lr_init (float) – warmup init learning rate, default:0.0.

  • eta_min (float) – minimum learning rate, default: 1e-6.

Returns

Numpy.array, learning rate array.

Raises
  • TypeError – If lr_init or warmup_lr_init or eta_min is not a float.

  • TypeError – If steps_per_epoch or warmup_epochs or last_epoch is not an int.

Supported Platforms:

Ascend GPU CPU

Examples

>>> from mindearth import get_warmup_cosine_annealing_lr
>>> lr_init = 0.001
>>> steps_per_epoch = 3
>>> last_epoch = 5
>>> warmup_epochs = 1
>>> lr = get_warmup_cosine_annealing_lr(lr_init, steps_per_epoch, last_epoch, warmup_epochs=warmup_epochs)
>>> print(lr)
[3.3333333e-04 6.6666666e-04 1.0000000e-03 9.0460398e-04 9.0460398e-04
 9.0460398e-04 6.5485400e-04 6.5485400e-04 6.5485400e-04 3.4614600e-04
 3.4614600e-04 3.4614600e-04 9.6396012e-05 9.6396012e-05 9.6396012e-05]