Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
5e0f199a
P
Paddle
项目概览
PaddlePaddle
/
Paddle
1 年多 前同步成功
通知
2305
Star
20932
Fork
5423
代码
文件
提交
分支
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看板
未验证
提交
5e0f199a
编写于
3年前
作者:
李
李季
提交者:
GitHub
3年前
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix raw optim (#36176)
* fix raw optim * pre-commit test file Co-authored-by:
N
sneaxiy
<
sneaxiy@126.com
>
上级
8af939f1
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
161 addition
and
0 deletion
+161
-0
python/paddle/distributed/fleet/meta_optimizers/raw_program_optimizer.py
...istributed/fleet/meta_optimizers/raw_program_optimizer.py
+2
-0
python/paddle/fluid/tests/unittests/CMakeLists.txt
python/paddle/fluid/tests/unittests/CMakeLists.txt
+2
-0
python/paddle/fluid/tests/unittests/test_rnn_dp.py
python/paddle/fluid/tests/unittests/test_rnn_dp.py
+157
-0
未找到文件。
python/paddle/distributed/fleet/meta_optimizers/raw_program_optimizer.py
浏览文件 @
5e0f199a
...
...
@@ -460,6 +460,8 @@ class RawProgramOptimizer(MetaOptimizerBase):
if
is_optimizer_op
(
op
):
break
for
name
in
op
.
output_arg_names
:
if
name
==
core
.
kEmptyVarName
():
continue
var
=
block
.
var
(
name
)
if
not
outputs_name_to_idx
.
get
(
var
):
# if the grad only be generated by one op
...
...
This diff is collapsed.
Click to expand it.
python/paddle/fluid/tests/unittests/CMakeLists.txt
浏览文件 @
5e0f199a
...
...
@@ -21,6 +21,7 @@ list(APPEND DIST_TEST_OPS test_parallel_dygraph_transformer)
list
(
APPEND DIST_TEST_OPS test_fleet_pipeline_meta_optimizer
)
list
(
APPEND DIST_TEST_OPS test_fleet_pipeline_meta_optimizer_with_recompute
)
list
(
APPEND DIST_TEST_OPS test_fleet_raw_program_meta_optimizer
)
list
(
APPEND DIST_TEST_OPS test_rnn_dp
)
list
(
APPEND DIST_TEST_OPS test_fleet_graph_execution_meta_optimizer
)
list
(
APPEND DIST_TEST_OPS test_gen_nccl_id_op
)
list
(
APPEND DIST_TEST_OPS test_parallel_dygraph_unused_variables
)
...
...
@@ -66,6 +67,7 @@ list(APPEND MIXED_DIST_TEST_OPS test_fleet_recompute_meta_optimizer)
list
(
APPEND MIXED_DIST_TEST_OPS test_fleet_pipeline_meta_optimizer
)
list
(
APPEND MIXED_DIST_TEST_OPS test_fleet_pipeline_meta_optimizer_with_recompute
)
list
(
APPEND MIXED_DIST_TEST_OPS test_fleet_raw_program_meta_optimizer
)
list
(
APPEND MIXED_DIST_TEST_OPS test_rnn_dp
)
list
(
APPEND MIXED_DIST_TEST_OPS test_fleet_amp_meta_optimizer
)
list
(
APPEND MIXED_DIST_TEST_OPS test_fleet_amp_init
)
list
(
APPEND MIXED_DIST_TEST_OPS test_fleet_gradient_merge_meta_optimizer
)
...
...
This diff is collapsed.
Click to expand it.
python/paddle/fluid/tests/unittests/test_rnn_dp.py
0 → 100644
浏览文件 @
5e0f199a
# Copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import
unittest
import
paddle
import
os
import
numpy
as
np
import
paddle
import
paddle.static
as
static
import
paddle.distributed.fleet
as
fleet
import
paddle.nn
as
nn
import
paddle.nn.functional
as
F
paddle
.
enable_static
()
class
RNNEncoder
(
nn
.
Layer
):
def
__init__
(
self
,
input_size
,
hidden_size
,
num_layers
=
1
,
direction
=
"forward"
,
dropout
=
0.0
,
pooling_type
=
None
,
**
kwargs
):
super
().
__init__
()
self
.
_input_size
=
input_size
self
.
_hidden_size
=
hidden_size
self
.
_direction
=
direction
self
.
_pooling_type
=
pooling_type
self
.
rnn_layer
=
nn
.
SimpleRNN
(
input_size
=
input_size
,
hidden_size
=
hidden_size
,
num_layers
=
num_layers
,
direction
=
direction
,
dropout
=
dropout
,
**
kwargs
)
def
get_input_dim
(
self
):
return
self
.
_input_size
def
get_output_dim
(
self
):
if
self
.
_direction
==
"bidirect"
:
return
self
.
_hidden_size
*
2
else
:
return
self
.
_hidden_size
def
forward
(
self
,
inputs
,
sequence_length
):
encoded_text
,
last_hidden
=
self
.
rnn_layer
(
inputs
,
sequence_length
=
sequence_length
)
output
=
paddle
.
max
(
encoded_text
,
axis
=
1
)
return
output
class
RNNModel
(
nn
.
Layer
):
def
__init__
(
self
,
vocab_size
,
num_classes
,
emb_dim
=
128
,
padding_idx
=
0
,
rnn_hidden_size
=
198
,
direction
=
'forward'
,
rnn_layers
=
1
,
dropout_rate
=
0.0
,
pooling_type
=
None
,
fc_hidden_size
=
96
):
super
().
__init__
()
self
.
embedder
=
nn
.
Embedding
(
num_embeddings
=
vocab_size
,
embedding_dim
=
emb_dim
,
padding_idx
=
padding_idx
)
self
.
rnn_encoder
=
RNNEncoder
(
emb_dim
,
rnn_hidden_size
,
num_layers
=
rnn_layers
,
direction
=
direction
,
dropout
=
dropout_rate
,
pooling_type
=
pooling_type
)
self
.
fc
=
nn
.
Linear
(
self
.
rnn_encoder
.
get_output_dim
(),
fc_hidden_size
)
self
.
output_layer
=
nn
.
Linear
(
fc_hidden_size
,
num_classes
)
def
forward
(
self
,
text
,
seq_len
):
embedded_text
=
self
.
embedder
(
text
)
text_repr
=
self
.
rnn_encoder
(
embedded_text
,
sequence_length
=
seq_len
)
fc_out
=
paddle
.
tanh
(
self
.
fc
(
text_repr
))
logits
=
self
.
output_layer
(
fc_out
)
return
logits
def
rnn_pretrain_forward
(
train_program
,
start_program
,
topo
=
None
):
with
static
.
program_guard
(
train_program
,
start_program
),
paddle
.
utils
.
unique_name
.
guard
():
batch_size
=
1
tokens
=
static
.
data
(
name
=
"tokens"
,
shape
=
[
batch_size
,
-
1
],
dtype
=
"int64"
)
seq_len
=
static
.
data
(
name
=
"ids"
,
shape
=
[
batch_size
],
dtype
=
"int64"
)
labels
=
static
.
data
(
name
=
"labels"
,
shape
=
[
batch_size
],
dtype
=
"int64"
)
data_holders
=
[
tokens
,
seq_len
,
labels
]
vocab_size
=
10
num_classes
=
2
pad_token_id
=
0
model
=
RNNModel
(
vocab_size
,
num_classes
,
direction
=
'forward'
,
padding_idx
=
pad_token_id
,
pooling_type
=
'max'
)
optimizer
=
paddle
.
optimizer
.
Adam
(
parameters
=
model
.
parameters
(),
learning_rate
=
0.001
)
criterion
=
paddle
.
nn
.
CrossEntropyLoss
()
preds
=
model
(
tokens
,
seq_len
)
loss
=
criterion
(
preds
,
labels
)
return
train_program
,
start_program
,
loss
,
optimizer
,
data_holders
class
TestFleetMetaOptimizer
(
unittest
.
TestCase
):
def
setUp
(
self
):
os
.
environ
[
"PADDLE_TRAINER_ID"
]
=
"1"
os
.
environ
[
"PADDLE_TRAINER_ENDPOINTS"
]
=
"127.0.0.1:36001,127.0.0.1:36002"
def
test_rnn_raw_optimizer
(
self
):
import
paddle.distributed.fleet
as
fleet
import
paddle.distributed.fleet.base.role_maker
as
role_maker
role
=
role_maker
.
PaddleCloudRoleMaker
(
is_collective
=
True
)
fleet
.
init
(
role
)
train_program
=
static
.
Program
()
start_program
=
static
.
Program
()
train_program
,
start_program
,
loss
,
optimizer
,
data_holders
=
\
rnn_pretrain_forward
(
train_program
,
start_program
)
with
paddle
.
static
.
program_guard
(
train_program
,
start_program
),
paddle
.
utils
.
unique_name
.
guard
():
strategy
=
fleet
.
DistributedStrategy
()
strategy
.
without_graph_optimization
=
True
strategy
.
fuse_all_reduce_ops
=
True
fleet
.
init
(
is_collective
=
True
,
strategy
=
strategy
)
optimizer
=
fleet
.
distributed_optimizer
(
optimizer
)
optimizer
.
minimize
(
loss
)
if
__name__
==
"__main__"
:
unittest
.
main
()
This diff is collapsed.
Click to expand it.
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录
新手
引导
客服
返回
顶部