Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
Paddle
提交
c83ea1cd
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看板
提交
c83ea1cd
编写于
10月 08, 2017
作者:
Y
Yang Yang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
remove hardcode add_XX_op
上级
a67e8ea3
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
21 addition
and
126 deletion
+21
-126
paddle/framework/executor_test.cc
paddle/framework/executor_test.cc
+21
-126
未找到文件。
paddle/framework/executor_test.cc
浏览文件 @
c83ea1cd
...
...
@@ -99,121 +99,6 @@ void AddOp(const std::string& type, const VariableNameMap& inputs,
}
}
void
add_gaussian_random_op
(
string
var_name
,
std
::
vector
<
int
>
dim
,
proto_block
*
block
)
{
// insert variable
auto
a
=
block
->
add_vars
();
a
->
set_name
(
var_name
);
auto
a_lt
=
a
->
mutable_lod_tensor
();
a_lt
->
set_data_type
(
paddle
::
framework
::
DataType
::
FP32
);
for
(
int
i
:
dim
)
{
a_lt
->
add_dims
(
i
);
}
// insert operation
auto
op
=
block
->
add_ops
();
op
->
set_type
(
"gaussian_random"
);
auto
dims
=
op
->
add_attrs
();
dims
->
set_name
(
"dims"
);
dims
->
set_type
(
paddle
::
framework
::
AttrType
::
INTS
);
for
(
int
i
:
dim
)
{
dims
->
add_ints
(
i
);
}
auto
Out
=
op
->
add_outputs
();
Out
->
set_parameter
(
"Out"
);
Out
->
add_arguments
(
var_name
);
}
void
add_feed_op
(
string
var_name
,
std
::
vector
<
int
>&
dim
,
int
index
,
proto_block
*
block
)
{
// insert variable
auto
a
=
block
->
add_vars
();
a
->
set_name
(
var_name
);
auto
a_lt
=
a
->
mutable_lod_tensor
();
a_lt
->
set_data_type
(
paddle
::
framework
::
DataType
::
FP32
);
for
(
int
i
:
dim
)
{
a_lt
->
add_dims
(
i
);
}
// insert operation
auto
op
=
block
->
add_ops
();
op
->
set_type
(
"feed"
);
// set dims attr
auto
dims
=
op
->
add_attrs
();
dims
->
set_name
(
"dims"
);
dims
->
set_type
(
paddle
::
framework
::
AttrType
::
INTS
);
for
(
int
i
:
dim
)
{
dims
->
add_ints
(
i
);
}
// set col attr
auto
col
=
op
->
add_attrs
();
col
->
set_name
(
"col"
);
col
->
set_type
(
paddle
::
framework
::
AttrType
::
INT
);
col
->
set_i
(
index
);
auto
Out
=
op
->
add_outputs
();
Out
->
set_parameter
(
"Out"
);
Out
->
add_arguments
(
var_name
);
}
void
add_fetch_op
(
string
var_name
,
std
::
vector
<
int
>
dim
,
int
index
,
proto_block
*
block
)
{
// insert variable
auto
a
=
block
->
add_vars
();
a
->
set_name
(
var_name
);
auto
a_lt
=
a
->
mutable_lod_tensor
();
a_lt
->
set_data_type
(
paddle
::
framework
::
DataType
::
FP32
);
for
(
int
i
:
dim
)
{
a_lt
->
add_dims
(
i
);
}
// insert operation
auto
op
=
block
->
add_ops
();
op
->
set_type
(
"fetch"
);
// set dims attr
auto
dims
=
op
->
add_attrs
();
dims
->
set_name
(
"dims"
);
dims
->
set_type
(
paddle
::
framework
::
AttrType
::
INTS
);
for
(
int
i
:
dim
)
{
dims
->
add_ints
(
i
);
}
// set col attr
auto
col
=
op
->
add_attrs
();
col
->
set_name
(
"col"
);
col
->
set_type
(
paddle
::
framework
::
AttrType
::
INT
);
col
->
set_i
(
index
);
auto
Out
=
op
->
add_inputs
();
Out
->
set_parameter
(
"Input"
);
Out
->
add_arguments
(
var_name
);
}
void
add_mul_op
(
string
X_str
,
string
Y_str
,
string
Out_str
,
proto_block
*
block
)
{
// insert variable
auto
a
=
block
->
add_vars
();
a
->
set_name
(
Out_str
);
auto
a_lt
=
a
->
mutable_lod_tensor
();
a_lt
->
set_data_type
(
paddle
::
framework
::
DataType
::
FP32
);
// insert op
auto
op
=
block
->
add_ops
();
op
->
set_type
(
"mul"
);
auto
X
=
op
->
add_inputs
();
X
->
set_parameter
(
"X"
);
X
->
add_arguments
(
X_str
);
auto
Y
=
op
->
add_inputs
();
Y
->
set_parameter
(
"Y"
);
Y
->
add_arguments
(
Y_str
);
auto
Out
=
op
->
add_outputs
();
Out
->
set_parameter
(
"Out"
);
Out
->
add_arguments
(
Out_str
);
}
std
::
once_flag
set_variable_flag
;
// Tensors in feed value variable will only be in CPUPlace
...
...
@@ -268,21 +153,27 @@ class ExecutorTesterRandom : public ::testing::Test {
AddOp
(
"gaussian_random"
,
{},
{{
"Out"
,
{
"w2"
}}},
{{
"dims"
,
std
::
vector
<
int
>
{
embed_dim
,
input_dim
}}},
init_root_block
);
AddOp
(
"fetch"
,
{{
"Input"
,
{
"w1"
}}},
{},
{{
"dims"
,
std
::
vector
<
int
>
{
input_dim
,
embed_dim
}}},
init_root_block
);
{{
"dims"
,
std
::
vector
<
int
>
{
input_dim
,
embed_dim
}},
{
"col"
,
0
}},
init_root_block
);
AddOp
(
"fetch"
,
{{
"Input"
,
{
"w2"
}}},
{},
{{
"dims"
,
std
::
vector
<
int
>
{
embed_dim
,
input_dim
}}},
init_root_block
);
{{
"dims"
,
std
::
vector
<
int
>
{
embed_dim
,
input_dim
}},
{
"col"
,
1
}},
init_root_block
);
// run pdesc
auto
root_block
=
pdesc_
.
add_blocks
();
root_block
->
set_idx
(
0
);
root_block
->
set_parent_idx
(
-
1
);
add_gaussian_random_op
(
"a"
,
{
batch_size
,
input_dim
},
root_block
);
add_mul_op
(
"a"
,
"w1"
,
"b"
,
root_block
);
add_mul_op
(
"b"
,
"w2"
,
"a_out"
,
root_block
);
AddOp
(
"gaussian_random"
,
{},
{{
"Out"
,
{
"a"
}}},
{{
"dims"
,
std
::
vector
<
int
>
{
batch_size
,
input_dim
}}},
root_block
);
AddOp
(
"mul"
,
{{
"X"
,
{
"a"
}},
{
"Y"
,
{
"w1"
}}},
{{
"Out"
,
{
"b"
}}},
{},
root_block
);
AddOp
(
"mul"
,
{{
"X"
,
{
"b"
}},
{
"Y"
,
{
"w2"
}}},
{{
"Out"
,
{
"a_out"
}}},
{},
root_block
);
add_fetch_op
(
"a_out"
,
{
input_dim
,
batch_size
},
0
,
root_block
);
AddOp
(
"fetch"
,
{{
"Input"
,
{
"a_out"
}}},
{},
{{
"dims"
,
std
::
vector
<
int
>
{
input_dim
,
batch_size
}},
{
"col"
,
1
}},
root_block
);
}
protected:
...
...
@@ -299,10 +190,14 @@ class ExecutorTesterFeedAndFetch : public ::testing::Test {
std
::
vector
<
int
>
dim
{
6
};
add_feed_op
(
"a"
,
dim
,
0
,
root_block
);
add_feed_op
(
"b"
,
dim
,
1
,
root_block
);
add_fetch_op
(
"a"
,
dim
,
0
,
root_block
);
add_fetch_op
(
"b"
,
dim
,
1
,
root_block
);
AddOp
(
"feed"
,
{},
{{
"Out"
,
{
"a"
}}},
{{
"dims"
,
dim
},
{
"col"
,
0
}},
root_block
);
AddOp
(
"feed"
,
{},
{{
"Out"
,
{
"b"
}}},
{{
"dims"
,
dim
},
{
"col"
,
1
}},
root_block
);
AddOp
(
"fetch"
,
{{
"Input"
,
{
"a"
}}},
{},
{{
"dims"
,
dim
},
{
"col"
,
0
}},
root_block
);
AddOp
(
"fetch"
,
{{
"Input"
,
{
"b"
}}},
{},
{{
"dims"
,
dim
},
{
"col"
,
1
}},
root_block
);
std
::
vector
<
float
>
vec1
=
{
1.0
,
2.0
,
3.0
,
4.0
,
5.0
,
6.0
};
std
::
vector
<
float
>
vec2
=
{
4.0
,
5.0
,
6.0
,
7.0
,
8.0
,
9.0
};
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录