Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Crayon鑫
Paddle
提交
bf6e7cba
P
Paddle
项目概览
Crayon鑫
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
bf6e7cba
编写于
11月 13, 2020
作者:
Z
Zhou Wei
提交者:
GitHub
11月 13, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
updata 2.0 API english doc (#28525)
* make Numpy version is below 1.19.3 * fix 2.0 doc
上级
7b1619e6
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
77 addition
and
72 deletion
+77
-72
paddle/fluid/operators/unique_op.cu
paddle/fluid/operators/unique_op.cu
+1
-1
paddle/fluid/pybind/imperative.cc
paddle/fluid/pybind/imperative.cc
+7
-15
python/paddle/framework/__init__.py
python/paddle/framework/__init__.py
+1
-5
python/paddle/framework/io.py
python/paddle/framework/io.py
+0
-4
python/paddle/optimizer/lr.py
python/paddle/optimizer/lr.py
+68
-47
未找到文件。
paddle/fluid/operators/unique_op.cu
浏览文件 @
bf6e7cba
...
...
@@ -177,7 +177,7 @@ static void UniqueFlattendCUDATensor(const framework::ExecutionContext& context,
thrust
::
sort_by_key
(
thrust
::
device
,
in_data_hat
,
in_data_hat
+
num_input
,
sorted_indices_data
);
// 1. Calculate op result: 'out'
:
// 1. Calculate op result: 'out'
Tensor
range
;
range
.
Resize
(
framework
::
make_ddim
({
num_input
+
1
}));
auto
range_data_ptr
=
range
.
mutable_data
<
IndexT
>
(
context
.
GetPlace
());
...
...
paddle/fluid/pybind/imperative.cc
浏览文件 @
bf6e7cba
...
...
@@ -685,8 +685,6 @@ void BindImperative(py::module *m_ptr) {
.. code-block:: python
import paddle
paddle.disable_static()
linear = Linear(32, 64)
data = paddle.uniform(shape=[30, 10, 32], -1, 1)
x = linear(data)
...
...
@@ -704,19 +702,13 @@ void BindImperative(py::module *m_ptr) {
.. code-block:: python
import paddle
paddle.disable_static()
inputs = []
for _ in range(10):
tmp = paddle.ones([2, 2])
tmp.stop_gradient=False
inputs.append(tmp)
ret = paddle.sums(inputs2)
loss = paddle.sum(ret)
loss.backward()
print("Before clear_gradient {}".format(loss.grad))
loss.clear_gradient()
print("After clear_gradient {}".format(loss.grad))
input = paddle.uniform([10, 2])
linear = paddle.nn.Linear(2, 3)
out = linear(input)
out.backward()
print("Before clear_gradient, linear.weight.grad: {}".format(linear.weight.grad))
linear.weight.clear_gradient()
print("After clear_gradient, linear.weight.grad: {}".format(linear.weight.grad))
)DOC"
)
.
def
(
"clone"
,
[](
std
::
shared_ptr
<
imperative
::
VarBase
>
&
self
)
{
...
...
python/paddle/framework/__init__.py
浏览文件 @
bf6e7cba
...
...
@@ -18,10 +18,7 @@ __all__ = [
'get_default_dtype'
,
'set_default_dtype'
]
__all__
+=
[
'grad'
,
'LayerList'
,
'load'
,
'save'
,
'to_variable'
,
'no_grad'
,
'DataParallel'
]
__all__
+=
[
'grad'
,
'LayerList'
,
'load'
,
'save'
,
'no_grad'
,
'DataParallel'
]
from
.
import
random
from
.random
import
seed
...
...
@@ -39,7 +36,6 @@ from ..fluid.core import VarBase #DEFINE_ALIAS
from
paddle.fluid
import
core
#DEFINE_ALIAS
from
..fluid.dygraph.base
import
no_grad_
as
no_grad
#DEFINE_ALIAS
from
..fluid.dygraph.base
import
to_variable
#DEFINE_ALIAS
from
..fluid.dygraph.base
import
grad
#DEFINE_ALIAS
from
.io
import
save
from
.io
import
load
...
...
python/paddle/framework/io.py
浏览文件 @
bf6e7cba
...
...
@@ -225,8 +225,6 @@ def save(obj, path):
import paddle
paddle.disable_static()
emb = paddle.nn.Embedding(10, 10)
layer_state_dict = emb.state_dict()
paddle.save(layer_state_dict, "emb.pdparams")
...
...
@@ -318,8 +316,6 @@ def load(path, **configs):
.. code-block:: python
import paddle
paddle.disable_static()
emb = paddle.nn.Embedding(10, 10)
layer_state_dict = emb.state_dict()
...
...
python/paddle/optimizer/lr.py
浏览文件 @
bf6e7cba
...
...
@@ -226,14 +226,15 @@ class NoamDecay(LRScheduler):
scheduler = paddle.optimizer.lr.NoamDecay(d_model=0.01, warmup_steps=100, verbose=True)
sgd = paddle.optimizer.SGD(learning_rate=scheduler, parameters=linear.parameters())
for epoch in range(20):
for batch_id in range(
2
):
for batch_id in range(
5
):
x = paddle.uniform([10, 10])
out = linear(x)
loss = paddle.mean(out)
loss.backward()
sgd.step()
sgd.clear_gradients()
scheduler.step()
scheduler.step() # If you update learning rate each step
# scheduler.step() # If you update learning rate each epoch
# train on static graph mode
paddle.enable_static()
...
...
@@ -251,7 +252,7 @@ class NoamDecay(LRScheduler):
exe = paddle.static.Executor()
exe.run(start_prog)
for epoch in range(20):
for batch_id in range(
2
):
for batch_id in range(
5
):
out = exe.run(
main_prog,
feed={
...
...
@@ -259,7 +260,8 @@ class NoamDecay(LRScheduler):
'y': np.random.randn(3, 4, 5).astype('float32')
},
fetch_list=loss.name)
scheduler.step()
scheduler.step() # If you update learning rate each step
# scheduler.step() # If you update learning rate each epoch
"""
...
...
@@ -322,14 +324,15 @@ class PiecewiseDecay(LRScheduler):
scheduler = paddle.optimizer.lr.PiecewiseDecay(boundaries=[3, 6, 9], values=[0.1, 0.2, 0.3, 0.4], verbose=True)
sgd = paddle.optimizer.SGD(learning_rate=scheduler, parameters=linear.parameters())
for epoch in range(20):
for batch_id in range(
2
):
for batch_id in range(
5
):
x = paddle.uniform([10, 10])
out = linear(x)
loss = paddle.mean(out)
loss.backward()
sgd.step()
sgd.clear_gradients()
scheduler.step()
scheduler.step() # If you update learning rate each step
# scheduler.step() # If you update learning rate each epoch
# train on static graph mode
paddle.enable_static()
...
...
@@ -347,7 +350,7 @@ class PiecewiseDecay(LRScheduler):
exe = paddle.static.Executor()
exe.run(start_prog)
for epoch in range(20):
for batch_id in range(
2
):
for batch_id in range(
5
):
out = exe.run(
main_prog,
feed={
...
...
@@ -355,7 +358,8 @@ class PiecewiseDecay(LRScheduler):
'y': np.random.randn(3, 4, 5).astype('float32')
},
fetch_list=loss.name)
scheduler.step()
scheduler.step() # If you update learning rate each step
# scheduler.step() # If you update learning rate each epoch
"""
def
__init__
(
self
,
boundaries
,
values
,
last_epoch
=-
1
,
verbose
=
False
):
...
...
@@ -403,14 +407,15 @@ class NaturalExpDecay(LRScheduler):
scheduler = paddle.optimizer.lr.NaturalExpDecay(learning_rate=0.5, gamma=0.1, verbose=True)
sgd = paddle.optimizer.SGD(learning_rate=scheduler, parameters=linear.parameters())
for epoch in range(20):
for batch_id in range(
2
):
for batch_id in range(
5
):
x = paddle.uniform([10, 10])
out = linear(x)
loss = paddle.mean(out)
loss.backward()
sgd.step()
sgd.clear_gradients()
scheduler.step()
scheduler.step() # If you update learning rate each step
# scheduler.step() # If you update learning rate each epoch
# train on static graph mode
paddle.enable_static()
...
...
@@ -428,7 +433,7 @@ class NaturalExpDecay(LRScheduler):
exe = paddle.static.Executor()
exe.run(start_prog)
for epoch in range(20):
for batch_id in range(
2
):
for batch_id in range(
5
):
out = exe.run(
main_prog,
feed={
...
...
@@ -436,7 +441,8 @@ class NaturalExpDecay(LRScheduler):
'y': np.random.randn(3, 4, 5).astype('float32')
},
fetch_list=loss.name)
scheduler.step()
scheduler.step() # If you update learning rate each step
# scheduler.step() # If you update learning rate each epoch
"""
def
__init__
(
self
,
learning_rate
,
gamma
,
last_epoch
=-
1
,
verbose
=
False
):
...
...
@@ -481,14 +487,15 @@ class InverseTimeDecay(LRScheduler):
scheduler = paddle.optimizer.lr.InverseTimeDecay(learning_rate=0.5, gamma=0.1, verbose=True)
sgd = paddle.optimizer.SGD(learning_rate=scheduler, parameters=linear.parameters())
for epoch in range(20):
for batch_id in range(
2
):
for batch_id in range(
5
):
x = paddle.uniform([10, 10])
out = linear(x)
loss = paddle.mean(out)
loss.backward()
sgd.step()
sgd.clear_gradients()
scheduler.step()
scheduler.step() # If you update learning rate each step
# scheduler.step() # If you update learning rate each epoch
# train on static graph mode
paddle.enable_static()
...
...
@@ -506,7 +513,7 @@ class InverseTimeDecay(LRScheduler):
exe = paddle.static.Executor()
exe.run(start_prog)
for epoch in range(20):
for batch_id in range(
2
):
for batch_id in range(
5
):
out = exe.run(
main_prog,
feed={
...
...
@@ -514,7 +521,8 @@ class InverseTimeDecay(LRScheduler):
'y': np.random.randn(3, 4, 5).astype('float32')
},
fetch_list=loss.name)
scheduler.step()
scheduler.step() # If you update learning rate each step
# scheduler.step() # If you update learning rate each epoch
"""
...
...
@@ -576,14 +584,15 @@ class PolynomialDecay(LRScheduler):
scheduler = paddle.optimizer.lr.PolynomialDecay(learning_rate=0.5, decay_steps=20, verbose=True)
sgd = paddle.optimizer.SGD(learning_rate=scheduler, parameters=linear.parameters())
for epoch in range(20):
for batch_id in range(
2
):
for batch_id in range(
5
):
x = paddle.uniform([10, 10])
out = linear(x)
loss = paddle.mean(out)
loss.backward()
sgd.step()
sgd.clear_gradients()
scheduler.step()
scheduler.step() # If you update learning rate each step
# scheduler.step() # If you update learning rate each epoch
# train on static graph mode
paddle.enable_static()
...
...
@@ -601,7 +610,7 @@ class PolynomialDecay(LRScheduler):
exe = paddle.static.Executor()
exe.run(start_prog)
for epoch in range(20):
for batch_id in range(
2
):
for batch_id in range(
5
):
out = exe.run(
main_prog,
feed={
...
...
@@ -609,7 +618,8 @@ class PolynomialDecay(LRScheduler):
'y': np.random.randn(3, 4, 5).astype('float32')
},
fetch_list=loss.name)
scheduler.step()
scheduler.step() # If you update learning rate each step
# scheduler.step() # If you update learning rate each epoch
"""
def
__init__
(
self
,
...
...
@@ -691,14 +701,15 @@ class LinearWarmup(LRScheduler):
learning_rate=0.5, warmup_steps=20, start_lr=0, end_lr=0.5, verbose=True)
sgd = paddle.optimizer.SGD(learning_rate=scheduler, parameters=linear.parameters())
for epoch in range(20):
for batch_id in range(
2
):
for batch_id in range(
5
):
x = paddle.uniform([10, 10])
out = linear(x)
loss = paddle.mean(out)
loss.backward()
sgd.step()
sgd.clear_gradients()
scheduler.step()
scheduler.step() # If you update learning rate each step
# scheduler.step() # If you update learning rate each epoch
# train on static graph mode
paddle.enable_static()
...
...
@@ -717,7 +728,7 @@ class LinearWarmup(LRScheduler):
exe = paddle.static.Executor()
exe.run(start_prog)
for epoch in range(20):
for batch_id in range(
2
):
for batch_id in range(
5
):
out = exe.run(
main_prog,
feed={
...
...
@@ -725,7 +736,8 @@ class LinearWarmup(LRScheduler):
'y': np.random.randn(3, 4, 5).astype('float32')
},
fetch_list=loss.name)
scheduler.step()
scheduler.step() # If you update learning rate each step
# scheduler.step() # If you update learning rate each epoch
"""
def
__init__
(
self
,
...
...
@@ -814,14 +826,15 @@ class ExponentialDecay(LRScheduler):
scheduler = paddle.optimizer.lr.ExponentialDecay(learning_rate=0.5, gamma=0.9, verbose=True)
sgd = paddle.optimizer.SGD(learning_rate=scheduler, parameters=linear.parameters())
for epoch in range(20):
for batch_id in range(
2
):
for batch_id in range(
5
):
x = paddle.uniform([10, 10])
out = linear(x)
loss = paddle.mean(out)
loss.backward()
sgd.step()
sgd.clear_gradients()
scheduler.step()
scheduler.step() # If you update learning rate each step
# scheduler.step() # If you update learning rate each epoch
# train on static graph mode
paddle.enable_static()
...
...
@@ -839,7 +852,7 @@ class ExponentialDecay(LRScheduler):
exe = paddle.static.Executor()
exe.run(start_prog)
for epoch in range(20):
for batch_id in range(
2
):
for batch_id in range(
5
):
out = exe.run(
main_prog,
feed={
...
...
@@ -847,7 +860,8 @@ class ExponentialDecay(LRScheduler):
'y': np.random.randn(3, 4, 5).astype('float32')
},
fetch_list=loss.name)
scheduler.step()
scheduler.step() # If you update learning rate each step
# scheduler.step() # If you update learning rate each epoch
"""
def
__init__
(
self
,
learning_rate
,
gamma
,
last_epoch
=-
1
,
verbose
=
False
):
...
...
@@ -901,14 +915,15 @@ class MultiStepDecay(LRScheduler):
scheduler = paddle.optimizer.lr.MultiStepDecay(learning_rate=0.5, milestones=[2, 4, 6], gamma=0.8, verbose=True)
sgd = paddle.optimizer.SGD(learning_rate=scheduler, parameters=linear.parameters())
for epoch in range(20):
for batch_id in range(
2
):
for batch_id in range(
5
):
x = paddle.uniform([10, 10])
out = linear(x)
loss = paddle.mean(out)
loss.backward()
sgd.step()
sgd.clear_gradients()
scheduler.step()
scheduler.step() # If you update learning rate each step
# scheduler.step() # If you update learning rate each epoch
# train on static graph mode
paddle.enable_static()
...
...
@@ -926,7 +941,7 @@ class MultiStepDecay(LRScheduler):
exe = paddle.static.Executor()
exe.run(start_prog)
for epoch in range(20):
for batch_id in range(
2
):
for batch_id in range(
5
):
out = exe.run(
main_prog,
feed={
...
...
@@ -934,7 +949,8 @@ class MultiStepDecay(LRScheduler):
'y': np.random.randn(3, 4, 5).astype('float32')
},
fetch_list=loss.name)
scheduler.step()
scheduler.step() # If you update learning rate each step
# scheduler.step() # If you update learning rate each epoch
"""
def
__init__
(
self
,
...
...
@@ -1008,14 +1024,15 @@ class StepDecay(LRScheduler):
scheduler = paddle.optimizer.lr.StepDecay(learning_rate=0.5, step_size=5, gamma=0.8, verbose=True)
sgd = paddle.optimizer.SGD(learning_rate=scheduler, parameters=linear.parameters())
for epoch in range(20):
for batch_id in range(
2
):
for batch_id in range(
5
):
x = paddle.uniform([10, 10])
out = linear(x)
loss = paddle.mean(out)
loss.backward()
sgd.step()
sgd.clear_gradients()
scheduler.step()
scheduler.step() # If you update learning rate each step
# scheduler.step() # If you update learning rate each epoch
# train on static graph mode
paddle.enable_static()
...
...
@@ -1033,7 +1050,7 @@ class StepDecay(LRScheduler):
exe = paddle.static.Executor()
exe.run(start_prog)
for epoch in range(20):
for batch_id in range(
2
):
for batch_id in range(
5
):
out = exe.run(
main_prog,
feed={
...
...
@@ -1041,7 +1058,8 @@ class StepDecay(LRScheduler):
'y': np.random.randn(3, 4, 5).astype('float32')
},
fetch_list=loss.name)
scheduler.step()
scheduler.step() # If you update learning rate each step
# scheduler.step() # If you update learning rate each epoch
"""
def
__init__
(
self
,
...
...
@@ -1102,14 +1120,15 @@ class LambdaDecay(LRScheduler):
scheduler = paddle.optimizer.lr.LambdaDecay(learning_rate=0.5, lr_lambda=lambda x:0.95**x, verbose=True)
sgd = paddle.optimizer.SGD(learning_rate=scheduler, parameters=linear.parameters())
for epoch in range(20):
for batch_id in range(
2
):
for batch_id in range(
5
):
x = paddle.uniform([10, 10])
out = linear(x)
loss = paddle.mean(out)
loss.backward()
sgd.step()
sgd.clear_gradients()
scheduler.step()
scheduler.step() # If you update learning rate each step
# scheduler.step() # If you update learning rate each epoch
# train on static graph mode
paddle.enable_static()
...
...
@@ -1127,7 +1146,7 @@ class LambdaDecay(LRScheduler):
exe = paddle.static.Executor()
exe.run(start_prog)
for epoch in range(20):
for batch_id in range(
2
):
for batch_id in range(
5
):
out = exe.run(
main_prog,
feed={
...
...
@@ -1135,7 +1154,8 @@ class LambdaDecay(LRScheduler):
'y': np.random.randn(3, 4, 5).astype('float32')
},
fetch_list=loss.name)
scheduler.step()
scheduler.step() # If you update learning rate each step
# scheduler.step() # If you update learning rate each epoch
"""
...
...
@@ -1200,14 +1220,15 @@ class ReduceOnPlateau(LRScheduler):
scheduler = paddle.optimizer.lr.ReduceOnPlateau(learning_rate=1.0, factor=0.5, patience=5, verbose=True)
sgd = paddle.optimizer.SGD(learning_rate=scheduler, parameters=linear.parameters())
for epoch in range(20):
for batch_id in range(
2
):
for batch_id in range(
5
):
x = paddle.uniform([10, 10])
out = linear(x)
loss = paddle.mean(out)
loss.backward()
sgd.step()
sgd.clear_gradients()
scheduler.step(loss)
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
paddle.enable_static()
...
...
@@ -1225,7 +1246,7 @@ class ReduceOnPlateau(LRScheduler):
exe = paddle.static.Executor()
exe.run(start_prog)
for epoch in range(20):
for batch_id in range(
2
):
for batch_id in range(
5
):
out = exe.run(
main_prog,
feed={
...
...
@@ -1233,7 +1254,8 @@ class ReduceOnPlateau(LRScheduler):
'y': np.random.randn(3, 4, 5).astype('float32')
},
fetch_list=loss.name)
scheduler.step(out[0])
scheduler.step(out[0]) # If you update learning rate each step
# scheduler.step(out[0]) # If you update learning rate each epoch
"""
...
...
@@ -1268,7 +1290,6 @@ class ReduceOnPlateau(LRScheduler):
"The type of 'learning_rate' in 'ReduceOnPlateau' must be 'float', but received %s."
%
type
(
learning_rate
))
self
.
verbose
=
verbose
self
.
patience
=
patience
self
.
threshold
=
threshold
self
.
threshold_mode
=
threshold_mode
...
...
@@ -1406,7 +1427,7 @@ class CosineAnnealingDecay(LRScheduler):
scheduler = paddle.optimizer.lr.CosineAnnealingDecay(learning_rate=0.5, T_max=10, verbose=True)
sgd = paddle.optimizer.SGD(learning_rate=scheduler, parameters=linear.parameters())
for epoch in range(20):
for batch_id in range(
2
):
for batch_id in range(
5
):
x = paddle.uniform([10, 10])
out = linear(x)
loss = paddle.mean(out)
...
...
@@ -1431,7 +1452,7 @@ class CosineAnnealingDecay(LRScheduler):
exe = paddle.static.Executor()
exe.run(start_prog)
for epoch in range(20):
for batch_id in range(
2
):
for batch_id in range(
5
):
out = exe.run(
main_prog,
feed={
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录