Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleDetection
提交
340d21d4
P
PaddleDetection
项目概览
PaddlePaddle
/
PaddleDetection
大约 1 年 前同步成功
通知
695
Star
11112
Fork
2696
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
184
列表
看板
标记
里程碑
合并请求
40
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleDetection
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
184
Issue
184
列表
看板
标记
里程碑
合并请求
40
合并请求
40
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
340d21d4
编写于
10月 10, 2017
作者:
Y
Yang Yang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Init at block[0]; Run at block[1]
上级
e5155713
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
36 addition
and
47 deletion
+36
-47
paddle/framework/executor.cc
paddle/framework/executor.cc
+8
-8
paddle/framework/executor.h
paddle/framework/executor.h
+2
-2
paddle/framework/executor_test.cc
paddle/framework/executor_test.cc
+26
-37
未找到文件。
paddle/framework/executor.cc
浏览文件 @
340d21d4
...
...
@@ -56,13 +56,12 @@ Executor::~Executor() {
}
}
void
Executor
::
Run
(
const
ProgramDesc
&
pdesc
,
Scope
*
scope
)
{
void
Executor
::
Run
(
const
ProgramDesc
&
pdesc
,
Scope
*
scope
,
int
block_id
)
{
// TODO(tonyyang-svail):
// - only runs the first block (i.e. no RNN support)
// - only runs on the first device (i.e. no interdevice communication)
// - will change to use multiple blocks for RNN op and Cond Op
PADDLE_ENFORCE_GT
(
pdesc
.
blocks_size
(),
0
);
auto
&
block
=
pdesc
.
blocks
(
0
);
PADDLE_ENFORCE_GT
(
pdesc
.
blocks_size
(),
block_id
);
auto
&
block
=
pdesc
.
blocks
(
block_id
);
auto
&
device
=
device_contexts_
[
0
];
// Instantiate all the vars in the global scope
...
...
@@ -72,7 +71,7 @@ void Executor::Run(const ProgramDesc& pdesc, Scope* scope) {
Scope
&
local_scope
=
scope
->
NewScope
();
std
::
vector
<
bool
>
should_run
=
Prune
(
pdesc
);
std
::
vector
<
bool
>
should_run
=
Prune
(
pdesc
,
block_id
);
PADDLE_ENFORCE_EQ
(
should_run
.
size
(),
block
.
ops_size
());
for
(
size_t
i
=
0
;
i
<
should_run
.
size
();
++
i
)
{
if
(
should_run
[
i
])
{
...
...
@@ -92,12 +91,11 @@ void Executor::Run(const ProgramDesc& pdesc, Scope* scope) {
// - Destroy local_scope
}
std
::
vector
<
bool
>
Executor
::
Prune
(
const
ProgramDesc
&
pdesc
)
{
std
::
vector
<
bool
>
Executor
::
Prune
(
const
ProgramDesc
&
pdesc
,
int
block_id
)
{
// TODO(tonyyang-svail):
// - only runs the first block
// - will change to use multiple blocks for RNN op and Cond Op
auto
&
block
=
pdesc
.
blocks
(
0
);
auto
&
block
=
pdesc
.
blocks
(
block_id
);
auto
&
ops
=
block
.
ops
();
bool
expect_feed
=
true
;
...
...
@@ -144,8 +142,10 @@ std::vector<bool> Executor::Prune(const ProgramDesc& pdesc) {
}
}
LOG
(
INFO
)
<<
"1 "
<<
op_desc
.
type
();
should_run
.
push_back
(
true
);
}
else
{
LOG
(
INFO
)
<<
"0 "
<<
op_desc
.
type
();
should_run
.
push_back
(
false
);
}
}
...
...
paddle/framework/executor.h
浏览文件 @
340d21d4
...
...
@@ -34,7 +34,7 @@ class Executor {
* ProgramDesc
* Scope
*/
void
Run
(
const
ProgramDesc
&
,
Scope
*
);
void
Run
(
const
ProgramDesc
&
,
Scope
*
,
int
);
protected:
/* @Brief
...
...
@@ -46,7 +46,7 @@ class Executor {
* @return
* vector<bool> Same size as ops. Indicates whether an op should be run.
*/
std
::
vector
<
bool
>
Prune
(
const
ProgramDesc
&
pdesc
);
std
::
vector
<
bool
>
Prune
(
const
ProgramDesc
&
pdesc
,
int
block_id
);
private:
std
::
vector
<
platform
::
DeviceContext
*>
device_contexts_
;
...
...
paddle/framework/executor_test.cc
浏览文件 @
340d21d4
...
...
@@ -104,50 +104,40 @@ class ExecutorTesterRandom : public ::testing::Test {
virtual
void
SetUp
()
override
{
int
input_dim
=
5
,
batch_size
=
2
,
embed_dim
=
5
;
// init pdesc
auto
temp_init_root_block
=
init_pdesc_
.
add_blocks
();
temp_init_root_block
->
set_idx
(
0
);
temp_init_root_block
->
set_parent_idx
(
-
1
);
// wrap to BlockDescBind
paddle
::
framework
::
ProgramDescBind
&
init_program
=
paddle
::
framework
::
ProgramDescBind
::
Instance
(
&
init_pdesc_
);
paddle
::
framework
::
BlockDescBind
*
init_root_block
=
init_program
.
Block
(
0
);
auto
temp_root_block
=
pdesc_
.
add_blocks
();
temp_root_block
->
set_idx
(
0
);
temp_root_block
->
set_parent_idx
(
-
1
);
paddle
::
framework
::
ProgramDescBind
&
program
=
paddle
::
framework
::
ProgramDescBind
::
Instance
(
&
pdesc_
);
paddle
::
framework
::
BlockDescBind
*
root_block
=
program
.
Block
(
0
);
// block[0]
AddOp
(
"gaussian_random"
,
{},
{{
"Out"
,
{
"w1"
}}},
{{
"dims"
,
std
::
vector
<
int
>
{
input_dim
,
embed_dim
}}},
init_
root_block
);
{{
"dims"
,
std
::
vector
<
int
>
{
input_dim
,
embed_dim
}}},
root_block
);
AddOp
(
"gaussian_random"
,
{},
{{
"Out"
,
{
"w2"
}}},
{{
"dims"
,
std
::
vector
<
int
>
{
embed_dim
,
input_dim
}}},
init_
root_block
);
{{
"dims"
,
std
::
vector
<
int
>
{
embed_dim
,
input_dim
}}},
root_block
);
AddOp
(
"fetch"
,
{{
"Input"
,
{
"w1"
}}},
{},
{{
"dims"
,
std
::
vector
<
int
>
{
input_dim
,
embed_dim
}},
{
"col"
,
0
}},
init_
root_block
);
root_block
);
AddOp
(
"fetch"
,
{{
"Input"
,
{
"w2"
}}},
{},
{{
"dims"
,
std
::
vector
<
int
>
{
embed_dim
,
input_dim
}},
{
"col"
,
1
}},
init_root_block
);
// flush
init_program
.
Proto
();
// run pdesc
auto
temp_root_block
=
pdesc_
.
add_blocks
();
temp_root_block
->
set_idx
(
0
);
temp_root_block
->
set_parent_idx
(
-
1
);
// wrap to BlockDescBind
paddle
::
framework
::
ProgramDescBind
&
program
=
paddle
::
framework
::
ProgramDescBind
::
Instance
(
&
pdesc_
);
paddle
::
framework
::
BlockDescBind
*
root_block
=
program
.
Block
(
0
);
root_block
);
// block[1]
paddle
::
framework
::
BlockDescBind
*
run_block
=
program
.
AppendBlock
(
*
root_block
);
AddOp
(
"gaussian_random"
,
{},
{{
"Out"
,
{
"a"
}}},
{{
"dims"
,
std
::
vector
<
int
>
{
batch_size
,
input_dim
}}},
r
oot
_block
);
{{
"dims"
,
std
::
vector
<
int
>
{
batch_size
,
input_dim
}}},
r
un
_block
);
AddOp
(
"mul"
,
{{
"X"
,
{
"a"
}},
{
"Y"
,
{
"w1"
}}},
{{
"Out"
,
{
"b"
}}},
{},
r
oot
_block
);
r
un
_block
);
AddOp
(
"mul"
,
{{
"X"
,
{
"b"
}},
{
"Y"
,
{
"w2"
}}},
{{
"Out"
,
{
"a_out"
}}},
{},
r
oot
_block
);
r
un
_block
);
AddOp
(
"squared_l2_distance"
,
{{
"X"
,
{
"a"
}},
{
"Y"
,
{
"a_out"
}}},
{{
"Out"
,
{
"l2_distance"
}},
{
"sub_result"
,
{
"l2_distance_sub"
}}},
{},
r
oot
_block
);
r
un
_block
);
AddOp
(
"fetch"
,
{{
"Input"
,
{
"l2_distance"
}}},
{},
{{
"dims"
,
std
::
vector
<
int
>
{
batch_size
}},
{
"col"
,
1
}},
root_block
);
{{
"dims"
,
std
::
vector
<
int
>
{
batch_size
}},
{
"col"
,
1
}},
run_block
);
// flush
program
.
Proto
();
...
...
@@ -157,7 +147,6 @@ class ExecutorTesterRandom : public ::testing::Test {
protected:
ProgramDesc
pdesc_
;
ProgramDesc
init_pdesc_
;
};
class
ExecutorTesterFeedAndFetch
:
public
::
testing
::
Test
{
...
...
@@ -211,8 +200,8 @@ TEST_F(ExecutorTesterRandom, CPU) {
std
::
unique_ptr
<
Executor
>
executor
(
new
Executor
(
places
));
executor
->
Run
(
init_pdesc_
,
GetGlobalScope
()
);
executor
->
Run
(
pdesc_
,
GetGlobalScope
());
executor
->
Run
(
pdesc_
,
GetGlobalScope
(),
0
);
executor
->
Run
(
pdesc_
,
GetGlobalScope
()
,
1
);
std
::
vector
<
std
::
vector
<
float
>>
result
=
GetFetchVariable
<
float
>
();
}
...
...
@@ -231,7 +220,7 @@ TEST_F(ExecutorTesterFeedAndFetch, CPU) {
for
(
int
batch_id
=
0
;
batch_id
<
3
;
batch_id
++
)
{
SetFeedVariable
<
float
>
(
inputs_
);
executor
->
Run
(
pdesc_
,
GetGlobalScope
());
executor
->
Run
(
pdesc_
,
GetGlobalScope
()
,
0
);
std
::
vector
<
std
::
vector
<
float
>>
result
=
GetFetchVariable
<
float
>
();
PADDLE_ENFORCE_EQ
(
result
.
size
(),
inputs_
.
size
());
for
(
size_t
i
=
0
;
i
<
result
.
size
();
++
i
)
{
...
...
@@ -259,8 +248,8 @@ TEST_F(ExecutorTesterRandom, GPU) {
std
::
unique_ptr
<
Executor
>
executor
(
new
Executor
(
places
));
executor
->
Run
(
init_pdesc_
,
GetGlobalScope
()
);
executor
->
Run
(
pdesc_
,
GetGlobalScope
());
executor
->
Run
(
pdesc_
,
GetGlobalScope
(),
0
);
executor
->
Run
(
pdesc_
,
GetGlobalScope
()
,
1
);
std
::
vector
<
std
::
vector
<
float
>>
result
=
GetFetchVariable
<
float
>
();
}
...
...
@@ -281,7 +270,7 @@ TEST_F(ExecutorTesterFeedAndFetch, GPU) {
for
(
int
batch_id
=
0
;
batch_id
<
3
;
batch_id
++
)
{
SetFeedVariable
<
float
>
(
inputs_
);
executor
->
Run
(
pdesc_
,
GetGlobalScope
());
executor
->
Run
(
pdesc_
,
GetGlobalScope
()
,
0
);
std
::
vector
<
std
::
vector
<
float
>>
result
=
GetFetchVariable
<
float
>
();
PADDLE_ENFORCE_EQ
(
result
.
size
(),
inputs_
.
size
());
for
(
size_t
i
=
0
;
i
<
result
.
size
();
++
i
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录