Api_attr

imperative

Sets the learning rate of `optimizer` to the initial lr times a multiplicative factor, and this multiplicative factor is computed by function `lr_lambda` . `lr_lambda` is funciton which receives `epoch` .

The algorithm can be described as the code below.

```learning_rate = 0.5        # init learning_rate
lr_lambda = lambda epoch: 0.95 ** epoch

learning_rate = 0.5        # epoch 0
learning_rate = 0.475      # epoch 1
learning_rate = 0.45125    # epoch 2
```
Parameters
• learning_rate (float|int) – The initial learning rate. It can be set to python float or int number.

• lr_lambda (function) – A function which computes a multiplicative factor given an integer parameter `epoch` , and then multiply the initial learning rate by this multiplicative factor.

Returns

None.

Examples

```import paddle.fluid as fluid
import numpy as np
with fluid.dygraph.guard():
x = np.random.uniform(-1, 1, [10, 10]).astype("float32")
linear = fluid.dygraph.Linear(10, 10)
input = fluid.dygraph.to_variable(x)
scheduler = fluid.dygraph.LambdaDecay(0.5, lr_lambda=lambda x: 0.95**x)

for epoch in range(6):
for batch_id in range(5):
out = linear(input)
loss = fluid.layers.reduce_mean(out)
scheduler.epoch()

print("epoch:%d, current lr is %f" .format(epoch, adam.current_step_lr()))
# epoch:0, current lr is 0.5
# epoch:1, current lr is 0.475
# epoch:2, current lr is 0.45125
```
create_lr_var ( lr )

convert lr from float to variable

Parameters

lr – learning rate

Returns

learning rate variable

epoch ( epoch=None )

compueted learning_rate and update it when invoked.

set_dict ( state_dict )

Returns the state of the scheduler as a `dict`.
{"ft_lang_label":"__label__en","ft_lang_prob":0.5812417,"math_prob":0.96710163,"size":2054,"snap":"2021-43-2021-49","text_gpt3_token_len":550,"char_repetition_ratio":0.15317073,"word_repetition_ratio":0.01369863,"special_character_ratio":0.28042844,"punctuation_ratio":0.1966759,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9995285,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2021-10-28T06:05:28Z\",\"WARC-Record-ID\":\"<urn:uuid:43f370e6-90a5-4269-b892-6e2a9b544295>\",\"Content-Length\":\"222112\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:07be9688-4fd5-449f-b165-4d6d0714a0da>\",\"WARC-Concurrent-To\":\"<urn:uuid:34af09a1-064d-4798-9167-aea3e259ac9f>\",\"WARC-IP-Address\":\"106.12.155.111\",\"WARC-Target-URI\":\"https://www.paddlepaddle.org.cn/documentation/docs/en/api/paddle/fluid/dygraph/learning_rate_scheduler/LambdaDecay_en.html\",\"WARC-Payload-Digest\":\"sha1:2WEV2ZQCNQHWG4AP3A3NVXVUSMQEHLPJ\",\"WARC-Block-Digest\":\"sha1:ZYAYVX5DIG344TPGGU637RMCZW424RWH\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2021/CC-MAIN-2021-43/CC-MAIN-2021-43_segments_1634323588257.34_warc_CC-MAIN-20211028034828-20211028064828-00597.warc.gz\"}"}