Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
413efdc9
P
Paddle
项目概览
PaddlePaddle
/
Paddle
大约 1 年 前同步成功
通知
2298
Star
20931
Fork
5422
代码
文件
提交
分支
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看板
未验证
提交
413efdc9
编写于
7月 19, 2023
作者:
J
jjyaoao
提交者:
GitHub
7月 19, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
修改COPY-FROM No.4 optimizer (#55238)
Signed-off-by:
N
jjyaoao
<
jjyaoao@126.com
>
上级
7849d58d
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
126 addition
and
16 deletion
+126
-16
python/paddle/optimizer/adam.py
python/paddle/optimizer/adam.py
+2
-0
python/paddle/optimizer/lr.py
python/paddle/optimizer/lr.py
+124
-16
未找到文件。
python/paddle/optimizer/adam.py
浏览文件 @
413efdc9
...
...
@@ -96,6 +96,7 @@ class Adam(Optimizer):
Examples:
.. code-block:: python
:name: code-example1
import paddle
...
...
@@ -110,6 +111,7 @@ class Adam(Optimizer):
adam.clear_grad()
.. code-block:: python
:name: code-example2
# Adam with beta1/beta2 as Tensor and weight_decay as float
import paddle
...
...
python/paddle/optimizer/lr.py
浏览文件 @
413efdc9
...
...
@@ -126,6 +126,18 @@ class LRScheduler:
Returns:
None
Examples:
.. code-block:: python
import paddle
value = paddle.arange(26, dtype='float32')
a = paddle.reshape(value, [2, 13])
linear = paddle.nn.Linear(13, 5)
adadelta = paddle.optimizer.Adadelta(learning_rate=0.0003, epsilon=1e-06, rho=0.95,
parameters = linear.parameters())
out = linear(a)
out.backward()
adadelta.step()
adadelta.clear_grad()
"""
if
epoch
is
None
:
self
.
last_epoch
+=
1
...
...
@@ -240,7 +252,9 @@ class NoamDecay(LRScheduler):
Examples:
.. code-block:: python
:name: code-example1
# Example1: train on default dynamic graph mode
import paddle
import numpy as np
...
...
@@ -259,7 +273,12 @@ class NoamDecay(LRScheduler):
scheduler.step() # If you update learning rate each step
# scheduler.step() # If you update learning rate each epoch
# train on static graph mode
.. code-block:: python
:name: code-example2
# Example2: train on static graph mode
import paddle
import numpy as np
paddle.enable_static()
main_prog = paddle.static.Program()
start_prog = paddle.static.Program()
...
...
@@ -343,7 +362,9 @@ class PiecewiseDecay(LRScheduler):
Examples:
.. code-block:: python
:name: code-example1
# Example1: train on default dynamic graph mode
import paddle
import numpy as np
...
...
@@ -362,7 +383,12 @@ class PiecewiseDecay(LRScheduler):
scheduler.step() # If you update learning rate each step
# scheduler.step() # If you update learning rate each epoch
# train on static graph mode
.. code-block:: python
:name: code-example2
# Example2: train on static graph mode
import paddle
import numpy as np
paddle.enable_static()
main_prog = paddle.static.Program()
start_prog = paddle.static.Program()
...
...
@@ -433,11 +459,11 @@ class NaturalExpDecay(LRScheduler):
Examples:
.. code-block:: python
:name: code-example1
# Example1: train on default dynamic graph mode
import paddle
import numpy as np
# train on default dynamic graph mode
linear = paddle.nn.Linear(10, 10)
scheduler = paddle.optimizer.lr.NaturalExpDecay(learning_rate=0.5, gamma=0.1, verbose=True)
sgd = paddle.optimizer.SGD(learning_rate=scheduler, parameters=linear.parameters())
...
...
@@ -452,7 +478,12 @@ class NaturalExpDecay(LRScheduler):
scheduler.step() # If you update learning rate each step
# scheduler.step() # If you update learning rate each epoch
# train on static graph mode
.. code-block:: python
:name: code-example2
# Example2: train on static graph mode
import paddle
import numpy as np
paddle.enable_static()
main_prog = paddle.static.Program()
start_prog = paddle.static.Program()
...
...
@@ -515,7 +546,9 @@ class InverseTimeDecay(LRScheduler):
Examples:
.. code-block:: python
:name: code-example1
# Example1: train on default dynamic graph mode
import paddle
import numpy as np
...
...
@@ -534,7 +567,12 @@ class InverseTimeDecay(LRScheduler):
scheduler.step() # If you update learning rate each step
# scheduler.step() # If you update learning rate each epoch
# train on static graph mode
.. code-block:: python
:name: code-example2
# Example2: train on static graph mode
import paddle
import numpy as np
paddle.enable_static()
main_prog = paddle.static.Program()
start_prog = paddle.static.Program()
...
...
@@ -611,7 +649,9 @@ class PolynomialDecay(LRScheduler):
Examples:
.. code-block:: python
:name: code-example1
# Example1: train on default dynamic graph mode
import paddle
import numpy as np
...
...
@@ -630,7 +670,12 @@ class PolynomialDecay(LRScheduler):
scheduler.step() # If you update learning rate each step
# scheduler.step() # If you update learning rate each epoch
# train on static graph mode
.. code-block:: python
:name: code-example2
# Example2: train on static graph mode
import paddle
import numpy as np
paddle.enable_static()
main_prog = paddle.static.Program()
start_prog = paddle.static.Program()
...
...
@@ -735,7 +780,9 @@ class LinearWarmup(LRScheduler):
Examples:
.. code-block:: python
:name: code-example1
# Example1: train on default dynamic graph mode
import paddle
import numpy as np
...
...
@@ -755,7 +802,12 @@ class LinearWarmup(LRScheduler):
scheduler.step() # If you update learning rate each step
# scheduler.step() # If you update learning rate each epoch
# train on static graph mode
.. code-block:: python
:name: code-example2
# Example2: train on static graph mode
import paddle
import numpy as np
paddle.enable_static()
main_prog = paddle.static.Program()
start_prog = paddle.static.Program()
...
...
@@ -868,7 +920,9 @@ class ExponentialDecay(LRScheduler):
Examples:
.. code-block:: python
:name: code-example1
# Example1: train on default dynamic graph mode
import paddle
import numpy as np
...
...
@@ -887,7 +941,12 @@ class ExponentialDecay(LRScheduler):
scheduler.step() # If you update learning rate each step
# scheduler.step() # If you update learning rate each epoch
# train on static graph mode
.. code-block:: python
:name: code-example2
# Example2: train on static graph mode
import paddle
import numpy as np
paddle.enable_static()
main_prog = paddle.static.Program()
start_prog = paddle.static.Program()
...
...
@@ -959,7 +1018,9 @@ class MultiStepDecay(LRScheduler):
Examples:
.. code-block:: python
:name: code-example1
# Example1: train on default dynamic graph mode
import paddle
import numpy as np
...
...
@@ -978,7 +1039,12 @@ class MultiStepDecay(LRScheduler):
scheduler.step() # If you update learning rate each step
# scheduler.step() # If you update learning rate each epoch
# train on static graph mode
.. code-block:: python
:name: code-example2
# Example2: train on static graph mode
import paddle
import numpy as np
paddle.enable_static()
main_prog = paddle.static.Program()
start_prog = paddle.static.Program()
...
...
@@ -1066,7 +1132,9 @@ class StepDecay(LRScheduler):
Examples:
.. code-block:: python
:name: code-example1
# Example1: train on default dynamic graph mode
import paddle
import numpy as np
...
...
@@ -1085,7 +1153,12 @@ class StepDecay(LRScheduler):
scheduler.step() # If you update learning rate each step
# scheduler.step() # If you update learning rate each epoch
# train on static graph mode
.. code-block:: python
:name: code-example2
# Example2: train on static graph mode
import paddle
import numpy as np
paddle.enable_static()
main_prog = paddle.static.Program()
start_prog = paddle.static.Program()
...
...
@@ -1163,7 +1236,9 @@ class LambdaDecay(LRScheduler):
Examples:
.. code-block:: python
:name: code-example1
# Example1: train on default dynamic graph mode
import paddle
import numpy as np
...
...
@@ -1182,7 +1257,12 @@ class LambdaDecay(LRScheduler):
scheduler.step() # If you update learning rate each step
# scheduler.step() # If you update learning rate each epoch
# train on static graph mode
.. code-block:: python
:name: code-example2
# Example2: train on static graph mode
import paddle
import numpy as np
paddle.enable_static()
main_prog = paddle.static.Program()
start_prog = paddle.static.Program()
...
...
@@ -1264,7 +1344,9 @@ class ReduceOnPlateau(LRScheduler):
Examples:
.. code-block:: python
:name: code-example1
# Example1: train on default dynamic graph mode
import paddle
import numpy as np
...
...
@@ -1283,7 +1365,12 @@ class ReduceOnPlateau(LRScheduler):
scheduler.step(loss) # If you update learning rate each step
# scheduler.step(loss) # If you update learning rate each epoch
# train on static graph mode
.. code-block:: python
:name: code-example2
# Example2: train on static graph mode
import paddle
import numpy as np
paddle.enable_static()
main_prog = paddle.static.Program()
start_prog = paddle.static.Program()
...
...
@@ -1488,7 +1575,9 @@ class CosineAnnealingDecay(LRScheduler):
Examples:
.. code-block:: python
:name: code-example1
# Example1: train on default dynamic graph mode
import paddle
import numpy as np
...
...
@@ -1507,7 +1596,12 @@ class CosineAnnealingDecay(LRScheduler):
scheduler.step() # If you update learning rate each step
# scheduler.step() # If you update learning rate each epoch
# train on static graph mode
.. code-block:: python
:name: code-example2
# Example2: train on static graph mode
import paddle
import numpy as np
paddle.enable_static()
main_prog = paddle.static.Program()
start_prog = paddle.static.Program()
...
...
@@ -1686,7 +1780,9 @@ class OneCycleLR(LRScheduler):
Examples:
.. code-block:: python
:name: code-example1
# Example1: train on default dynamic graph mode
import paddle
import numpy as np
...
...
@@ -1704,7 +1800,12 @@ class OneCycleLR(LRScheduler):
sgd.clear_gradients()
scheduler.step() # You should update learning rate each step
# train on static graph mode
.. code-block:: python
:name: code-example2
# Example2: train on static graph mode
import paddle
import numpy as np
paddle.enable_static()
main_prog = paddle.static.Program()
start_prog = paddle.static.Program()
...
...
@@ -1929,7 +2030,9 @@ class CyclicLR(LRScheduler):
Examples:
.. code-block:: python
:name: code-example1
# Example1: train on default dynamic graph mode
import paddle
import numpy as np
...
...
@@ -1947,7 +2050,12 @@ class CyclicLR(LRScheduler):
sgd.clear_gradients()
scheduler.step() # You should update learning rate each step
# train on static graph mode
.. code-block:: python
:name: code-example2
# Example2: train on static graph mode
import paddle
import numpy as np
paddle.enable_static()
main_prog = paddle.static.Program()
start_prog = paddle.static.Program()
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录