Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
5a804830
P
Paddle
项目概览
PaddlePaddle
/
Paddle
大约 2 年 前同步成功
通知
2325
Star
20933
Fork
5424
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1423
列表
看板
标记
里程碑
合并请求
543
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1,423
Issue
1,423
列表
看板
标记
里程碑
合并请求
543
合并请求
543
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
5a804830
编写于
6月 27, 2023
作者:
L
LoneRanger
提交者:
GitHub
6月 27, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
replace the CosineDecay in fluid with 2.0 version (#54829)
* remove the CosineDecay in fluid * Update test_basic_api_transformation.py
上级
de60c1d1
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
5 addition
and
69 deletion
+5
-69
python/paddle/fluid/dygraph/learning_rate_scheduler.py
python/paddle/fluid/dygraph/learning_rate_scheduler.py
+0
-64
python/paddle/fluid/layers/learning_rate_scheduler.py
python/paddle/fluid/layers/learning_rate_scheduler.py
+2
-2
test/dygraph_to_static/test_basic_api_transformation.py
test/dygraph_to_static/test_basic_api_transformation.py
+3
-3
未找到文件。
python/paddle/fluid/dygraph/learning_rate_scheduler.py
浏览文件 @
5a804830
...
...
@@ -25,7 +25,6 @@ __all__ = [
'NoamDecay'
,
'PiecewiseDecay'
,
'PolynomialDecay'
,
'CosineDecay'
,
'LinearLrWarmup'
,
'ReduceLROnPlateau'
,
'StepDecay'
,
...
...
@@ -294,69 +293,6 @@ class PolynomialDecay(LearningRateDecay):
return
decayed_lr
class
CosineDecay
(
LearningRateDecay
):
r
"""
:api_attr: imperative
Applies cosine decay to the learning rate.
The algorithm can be described as following.
.. math::
decayed\_learning\_rate = learning\_rate * 0.5 * (math.cos(global\_step * \\frac{math.pi}{step\_each\_epoch} ) + 1)
Parameters:
learning_rate(Variable|float): The initial learning rate. If the type
is Variable, it's a tensor with shape [1], the data type can be
float32 or float64. It also can be set to python int number.
step_each_epoch(int): The number of steps in an epoch.
epochs(int): The number of epochs.
begin(int, optional): The begin step. The initial value of global_step described above. The default value is 0.
step(int, optional): The step size used to calculate the new global_step in the description above.
The default value is 1.
dtype(str, optional): The data type used to create the learning rate variable. The data type can be set as
'float32', 'float64'. The default value is 'float32'.
Returns:
None.
Examples:
.. code-block:: python
base_lr = 0.1
with fluid.dygraph.guard():
optimizer = fluid.optimizer.SGD(
learning_rate = fluid.dygraph.CosineDecay(
base_lr, 10000, 120) )
"""
def
__init__
(
self
,
learning_rate
,
step_each_epoch
,
epochs
,
begin
=
0
,
step
=
1
,
dtype
=
'float32'
,
):
super
().
__init__
(
begin
,
step
,
dtype
)
self
.
learning_rate
=
learning_rate
self
.
step_each_epoch
=
step_each_epoch
self
.
epochs
=
epochs
def
step
(
self
):
cur_epoch
=
paddle
.
floor
(
self
.
create_lr_var
(
self
.
step_num
/
self
.
step_each_epoch
)
)
decayed_lr
=
(
self
.
learning_rate
*
0.5
*
(
paddle
.
cos
(
cur_epoch
*
math
.
pi
/
self
.
epochs
)
+
1
)
)
return
decayed_lr
class
NoamDecay
(
LearningRateDecay
):
r
"""
:api_attr: imperative
...
...
python/paddle/fluid/layers/learning_rate_scheduler.py
浏览文件 @
5a804830
...
...
@@ -495,8 +495,8 @@ def cosine_decay(learning_rate, step_each_epoch, epochs):
with
default_main_program
().
_lr_schedule_guard
():
if
in_dygraph_mode
():
decay
=
imperate_lr
.
Cosine
Decay
(
learning_rate
,
step_each_epoch
,
epochs
decay
=
paddle
.
optimizer
.
lr
.
CosineAnnealing
Decay
(
learning_rate
,
epochs
)
return
decay
else
:
...
...
test/dygraph_to_static/test_basic_api_transformation.py
浏览文件 @
5a804830
...
...
@@ -333,11 +333,11 @@ class TestDygraphBasicApi_Prelu(TestDygraphBasicApi):
# 2. test Apis that inherit from LearningRateDecay
def
dyfunc_CosineDecay
():
base_lr
=
0.1
CosineDecay
=
fluid
.
dygraph
.
Cosine
Decay
(
learning_rate
=
base_lr
,
step_each_epoch
=
10000
,
epochs
=
120
CosineDecay
=
paddle
.
optimizer
.
lr
.
CosineAnnealing
Decay
(
learning_rate
=
base_lr
,
T_max
=
120
)
lr
=
CosineDecay
()
return
lr
return
paddle
.
to_tensor
(
lr
)
def
dyfunc_ExponentialDecay
():
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录