Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
Paddle
提交
4ae7ea0a
P
Paddle
项目概览
BaiXuePrincess
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
4ae7ea0a
编写于
6月 28, 2019
作者:
L
lujun
提交者:
GitHub
6月 28, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
cherry pick, fix dygraph api doc, test=release/1.5
BackwardStrategy dygraph.nn dygraph.checkpoint
上级
3cd78f6e
变更
4
展开全部
隐藏空白更改
内联
并排
Showing
4 changed file
with
146 addition
and
146 deletion
+146
-146
paddle/fluid/API.spec
paddle/fluid/API.spec
+2
-2
paddle/fluid/pybind/imperative.cc
paddle/fluid/pybind/imperative.cc
+17
-16
python/paddle/fluid/dygraph/checkpoint.py
python/paddle/fluid/dygraph/checkpoint.py
+30
-25
python/paddle/fluid/dygraph/nn.py
python/paddle/fluid/dygraph/nn.py
+97
-103
未找到文件。
paddle/fluid/API.spec
浏览文件 @
4ae7ea0a
...
@@ -731,8 +731,8 @@ paddle.fluid.dygraph.Tracer.train_mode (ArgSpec(args=['self'], varargs=None, key
...
@@ -731,8 +731,8 @@ paddle.fluid.dygraph.Tracer.train_mode (ArgSpec(args=['self'], varargs=None, key
paddle.fluid.dygraph.start_gperf_profiler (ArgSpec(args=[], varargs=None, keywords=None, defaults=None), ('document', '6adf97f83acf6453d4a6a4b1070f3754'))
paddle.fluid.dygraph.start_gperf_profiler (ArgSpec(args=[], varargs=None, keywords=None, defaults=None), ('document', '6adf97f83acf6453d4a6a4b1070f3754'))
paddle.fluid.dygraph.stop_gperf_profiler (ArgSpec(args=[], varargs=None, keywords=None, defaults=None), ('document', '6adf97f83acf6453d4a6a4b1070f3754'))
paddle.fluid.dygraph.stop_gperf_profiler (ArgSpec(args=[], varargs=None, keywords=None, defaults=None), ('document', '6adf97f83acf6453d4a6a4b1070f3754'))
paddle.fluid.dygraph.prepare_context (ArgSpec(args=['strategy'], varargs=None, keywords=None, defaults=(None,)), ('document', '6adf97f83acf6453d4a6a4b1070f3754'))
paddle.fluid.dygraph.prepare_context (ArgSpec(args=['strategy'], varargs=None, keywords=None, defaults=(None,)), ('document', '6adf97f83acf6453d4a6a4b1070f3754'))
paddle.fluid.dygraph.save_persistables (ArgSpec(args=['model_dict', 'dirname', 'optimizers'], varargs=None, keywords=None, defaults=('save_dir', None)), ('document', '
bdeefe733228f5f2d4a8f8c61a5956cf
'))
paddle.fluid.dygraph.save_persistables (ArgSpec(args=['model_dict', 'dirname', 'optimizers'], varargs=None, keywords=None, defaults=('save_dir', None)), ('document', '
7f526f879139a14cda8e0b5a9171f264
'))
paddle.fluid.dygraph.load_persistables (ArgSpec(args=['dirname'], varargs=None, keywords=None, defaults=('save_dir',)), ('document', '
fb79b050b5eb52fa9c5fdccefe521aa1
'))
paddle.fluid.dygraph.load_persistables (ArgSpec(args=['dirname'], varargs=None, keywords=None, defaults=('save_dir',)), ('document', '
2574d50a7a9f89fb0d74ddf73d8128f0
'))
paddle.fluid.dygraph.NoamDecay.__init__ (ArgSpec(args=['self', 'd_model', 'warmup_steps', 'begin', 'step', 'dtype'], varargs=None, keywords=None, defaults=(1, 1, 'float32')), ('document', '6adf97f83acf6453d4a6a4b1070f3754'))
paddle.fluid.dygraph.NoamDecay.__init__ (ArgSpec(args=['self', 'd_model', 'warmup_steps', 'begin', 'step', 'dtype'], varargs=None, keywords=None, defaults=(1, 1, 'float32')), ('document', '6adf97f83acf6453d4a6a4b1070f3754'))
paddle.fluid.dygraph.NoamDecay.create_lr_var (ArgSpec(args=['self', 'lr'], varargs=None, keywords=None, defaults=None), ('document', '013bc233558149d0757b3df57845b866'))
paddle.fluid.dygraph.NoamDecay.create_lr_var (ArgSpec(args=['self', 'lr'], varargs=None, keywords=None, defaults=None), ('document', '013bc233558149d0757b3df57845b866'))
paddle.fluid.dygraph.NoamDecay.step (ArgSpec(args=['self'], varargs=None, keywords=None, defaults=None), ('document', '6adf97f83acf6453d4a6a4b1070f3754'))
paddle.fluid.dygraph.NoamDecay.step (ArgSpec(args=['self'], varargs=None, keywords=None, defaults=None), ('document', '6adf97f83acf6453d4a6a4b1070f3754'))
...
...
paddle/fluid/pybind/imperative.cc
浏览文件 @
4ae7ea0a
...
@@ -162,22 +162,23 @@ void BindImperative(pybind11::module *m_ptr) {
...
@@ -162,22 +162,23 @@ void BindImperative(pybind11::module *m_ptr) {
1. :code:`sort_sum_gradient`, which will sum the gradient by the reverse order of trace.
1. :code:`sort_sum_gradient`, which will sum the gradient by the reverse order of trace.
Examples:
Examples:
.. code-block:: python
.. code-block:: python
import numpy as np
import paddle.fluid as fluid
import numpy as np
from paddle.fluid import FC
import paddle.fluid as fluid
from paddle.fluid import FC
x = np.ones([2, 2], np.float32)
with fluid.dygraph.guard():
x = np.ones([2, 2], np.float32)
inputs2 = []
with fluid.dygraph.guard():
for _ in range(10):
inputs2 = []
inputs2.append(fluid.dygraph.base.to_variable(x))
for _ in range(10):
ret2 = fluid.layers.sums(inputs2)
inputs2.append(fluid.dygraph.base.to_variable(x))
loss2 = fluid.layers.reduce_sum(ret2)
ret2 = fluid.layers.sums(inputs2)
backward_strategy = fluid.dygraph.BackwardStrategy()
loss2 = fluid.layers.reduce_sum(ret2)
backward_strategy.sort_sum_gradient = True
backward_strategy = fluid.dygraph.BackwardStrategy()
loss2.backward(backward_strategy)
backward_strategy.sort_sum_gradient = True
loss2.backward(backward_strategy)
)DOC"
);
)DOC"
);
backward_strategy
.
def
(
py
::
init
())
backward_strategy
.
def
(
py
::
init
())
.
def_property
(
"sort_sum_gradient"
,
.
def_property
(
"sort_sum_gradient"
,
...
...
python/paddle/fluid/dygraph/checkpoint.py
浏览文件 @
4ae7ea0a
...
@@ -43,35 +43,38 @@ def save_persistables(model_dict, dirname='save_dir', optimizers=None):
...
@@ -43,35 +43,38 @@ def save_persistables(model_dict, dirname='save_dir', optimizers=None):
optimizers(fluid.Optimizer|list(fluid.Optimizer)|None): The optimizers to be saved
optimizers(fluid.Optimizer|list(fluid.Optimizer)|None): The optimizers to be saved
Returns:
Returns:
None
Examples:
Examples:
.. code-block:: python
.. code-block:: python
ptb_model = PtbModel(
ptb_model = PtbModel(
hidden_size=hidden_size,
hidden_size=hidden_size,
vocab_size=vocab_size,
vocab_size=vocab_size,
num_layers=num_layers,
num_layers=num_layers,
num_steps=num_steps,
num_steps=num_steps,
init_scale=init_scale)
init_scale=init_scale)
sgd = fluid.optimizer.SGD(learning_rate=0.01)
sgd = fluid.optimizer.SGD(learning_rate=0.01)
x_data = np.arange(12).reshape(4, 3).astype('int64')
x_data = np.arange(12).reshape(4, 3).astype('int64')
y_data = np.arange(1, 13).reshape(4, 3).astype('int64')
y_data = np.arange(1, 13).reshape(4, 3).astype('int64')
x_data = x_data.reshape((-1, num_steps, 1))
x_data = x_data.reshape((-1, num_steps, 1))
y_data = y_data.reshape((-1, 1))
y_data = y_data.reshape((-1, 1))
init_hidden_data = np.zeros(
init_hidden_data = np.zeros(
(num_layers, batch_size, hidden_size), dtype='float32')
(num_layers, batch_size, hidden_size), dtype='float32')
init_cell_data = np.zeros(
init_cell_data = np.zeros(
(num_layers, batch_size, hidden_size), dtype='float32')
(num_layers, batch_size, hidden_size), dtype='float32')
x = to_variable(x_data)
x = to_variable(x_data)
y = to_variable(y_data)
y = to_variable(y_data)
init_hidden = to_variable(init_hidden_data)
init_hidden = to_variable(init_hidden_data)
init_cell = to_variable(init_cell_data)
init_cell = to_variable(init_cell_data)
dy_loss, last_hidden, last_cell = ptb_model(x, y, init_hidden,
dy_loss, last_hidden, last_cell = ptb_model(x, y, init_hidden,
init_cell)
init_cell)
dy_loss.backward()
dy_loss.backward()
sgd.minimize(dy_loss)
sgd.minimize(dy_loss)
ptb_model.clear_gradient()
ptb_model.clear_gradient()
param_path = "./my_paddle_model"
param_path = "./my_paddle_model"
fluid.dygraph.save_persistables(ptb_model.state_dict(), dirname=param_path, sgd)
fluid.dygraph.save_persistables(ptb_model.state_dict(), dirname=param_path, sgd)
"""
"""
if
isinstance
(
model_dict
,
collections
.
OrderedDict
):
if
isinstance
(
model_dict
,
collections
.
OrderedDict
):
_save_var_to_file
(
model_dict
,
optimizers
,
dirname
,
None
)
_save_var_to_file
(
model_dict
,
optimizers
,
dirname
,
None
)
...
@@ -95,13 +98,15 @@ def load_persistables(dirname='save_dir'):
...
@@ -95,13 +98,15 @@ def load_persistables(dirname='save_dir'):
optimizer dict: The optimizer
optimizer dict: The optimizer
Examples:
Examples:
.. code-block:: python
my_layer = layer(fluid.Layer)
.. code-block:: python
param_path = "./my_paddle_model"
sgd = SGDOptimizer(learning_rate=1e-3)
my_layer = layer(fluid.Layer)
param_dict, optimizer_dict = fluid.dygraph.load_persistables(my_layer.parameters(), param_path)
param_path = "./my_paddle_model"
param_1 = param_dict['PtbModel_0.w_1']
sgd = SGDOptimizer(learning_rate=1e-3)
sgd.load(optimizer_dict)
param_dict, optimizer_dict = fluid.dygraph.load_persistables(my_layer.parameters(), param_path)
param_1 = param_dict['PtbModel_0.w_1']
sgd.load(optimizer_dict)
"""
"""
return
_load_var_from_file
(
dirname
)
return
_load_var_from_file
(
dirname
)
...
...
python/paddle/fluid/dygraph/nn.py
浏览文件 @
4ae7ea0a
此差异已折叠。
点击以展开。
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录