Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
abd3fa4a
P
Paddle
项目概览
PaddlePaddle
/
Paddle
1 年多 前同步成功
通知
2302
Star
20931
Fork
5422
代码
文件
提交
分支
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看板
提交
abd3fa4a
编写于
6月 11, 2021
作者:
P
phlrain
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add python fetch
上级
2d6bda5c
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
43 addition
and
22 deletion
+43
-22
paddle/fluid/framework/new_exec.h
paddle/fluid/framework/new_exec.h
+30
-16
paddle/fluid/pybind/pybind.cc
paddle/fluid/pybind/pybind.cc
+13
-6
未找到文件。
paddle/fluid/framework/new_exec.h
浏览文件 @
abd3fa4a
...
...
@@ -539,9 +539,9 @@ void build_op_func_list( const framework::ProgramDesc& pdesc, std::vector<Operat
for
(
auto
&
op
:
global_block
.
AllOps
()
)
{
cerr
<<
op
->
Type
()
<<
endl
;
//
cerr << op->Type() << endl;
//bool debug = op->Type() == "softmax_with_cross_entropy_grad";
bool
debug
=
tru
e
;
bool
debug
=
fals
e
;
//cerr << "create op" << endl;
//auto op_base_u = OpRegistry::CreateOp(*op);
...
...
@@ -638,16 +638,20 @@ void build_op_func_list( const framework::ProgramDesc& pdesc, std::vector<Operat
// add transfer log
//cerr << "in map size " << ins_map.size() << endl;
VariableValueMap
&
ins_map_temp
=
runtime_context
.
inputs
;
cerr
<<
"ins map siz"
<<
ins_map_temp
.
size
()
<<
endl
;
//
cerr << "ins map siz" << ins_map_temp.size() << endl;
for
(
auto
&
var_name_item
:
ins_map_temp
)
{
cerr
<<
"in name "
<<
var_name_item
.
first
<<
endl
;
//auto& vec_ids = ins_name2id[ var_name_item.first ];
for
(
size_t
i
=
0
;
i
<
var_name_item
.
second
.
size
();
++
i
)
{
auto
var
=
var_name_item
.
second
[
i
];
auto
tensor_in
=
static_cast
<
const
Tensor
*>
(
&
(
var
->
Get
<
LoDTensor
>
()));
cerr
<<
"i "
<<
i
<<
"
\t
"
<<
tensor_in
->
IsInitialized
()
<<
endl
;
if
(
!
tensor_in
->
IsInitialized
()
)
{
continue
;
}
//cerr << "i " << i << "\t" << tensor_in->IsInitialized() << endl;
auto
kernel_type_for_var
=
static_cast
<
const
framework
::
OperatorWithKernel
*>
(
op_base
)
->
GetKernelTypeForVar
(
var_name_item
.
first
,
*
tensor_in
,
expected_kernel_key
);
if
(
debug
)
...
...
@@ -669,7 +673,7 @@ void build_op_func_list( const framework::ProgramDesc& pdesc, std::vector<Operat
var_scope
->
var_list
.
push_back
(
std
::
unique_ptr
<
Variable
>
(
v
));
VariableNameMap
copy_in_map
;
cerr
<<
"ints name is "
<<
input_names
[
var_name_item
.
first
][
i
]
<<
endl
;
//
cerr << "ints name is " << input_names[var_name_item.first][i] << endl;
copy_in_map
[
"X"
]
=
{
input_names
[
var_name_item
.
first
][
i
]
};
VariableNameMap
copy_out_map
;
copy_out_map
[
"Out"
]
=
{
new_var_name
};
...
...
@@ -779,7 +783,7 @@ void exec_op_func_list( const std::vector<OpFuncNode>& vec_func_list,
input_vars
.
reserve
(
var_name_item
.
second
.
size
());
for
(
auto
&
id
:
var_name_item
.
second
)
{
cerr
<<
var_name_item
.
first
<<
"
\t
"
<<
id
<<
endl
;
//
cerr << var_name_item.first << "\t " << id << endl;
input_vars
.
emplace_back
(
var_scope
.
var_list
[
id
].
get
()
);
}
ins_map
.
emplace
(
var_name_item
.
first
,
std
::
move
(
input_vars
)
);
...
...
@@ -792,7 +796,7 @@ void exec_op_func_list( const std::vector<OpFuncNode>& vec_func_list,
out_vars
.
reserve
(
var_name_item
.
second
.
size
());
for
(
auto
&
id
:
var_name_item
.
second
)
{
cerr
<<
var_name_item
.
first
<<
"
\t
"
<<
id
<<
endl
;
//
cerr << var_name_item.first << "\t " << id << endl;
out_vars
.
emplace_back
(
var_scope
.
var_list
[
id
].
get
());
}
outs_map
.
emplace
(
var_name_item
.
first
,
std
::
move
(
out_vars
)
);
...
...
@@ -826,15 +830,23 @@ void exec_op_func_list( const std::vector<OpFuncNode>& vec_func_list,
class
InterpreterCore
{
public:
InterpreterCore
(
const
platform
::
Place
&
place
,
const
ProgramDesc
&
prog
)
:
place_
(
place
),
prog_
(
prog
)
{
InterpreterCore
(
const
platform
::
Place
&
place
,
const
ProgramDesc
&
prog
,
const
ProgramDesc
&
startup_prog
)
:
place_
(
place
),
prog_
(
prog
)
{
paddle
::
framework
::
InitDevices
();
is_build
=
false
;
paddle
::
framework
::
build_variable_scope
(
startup_prog
,
&
global_scope
);
std
::
vector
<
paddle
::
framework
::
OpFuncNode
>
vec_func_list
;
std
::
vector
<
paddle
::
framework
::
OperatorBase
*
>
op_list
;
paddle
::
framework
::
build_op_func_list
(
startup_prog
,
op_list
,
vec_func_list
,
&
global_scope
,
place_
);
}
void
run
(
const
std
::
vector
<
std
::
string
>
vec_name
,
const
std
::
vector
<
framework
::
Tensor
>&
vec_tensor
,
const
vector
<
std
::
string
>&
vec_fetch_name
)
void
run
(
const
std
::
vector
<
std
::
string
>
vec_name
,
const
std
::
vector
<
framework
::
Tensor
>&
vec_tensor
,
const
vector
<
std
::
string
>&
vec_fetch_name
,
std
::
vector
<
framework
::
Tensor
>&
vec_out
)
{
cerr
<<
"run"
<<
endl
;
//
cerr << "run" << endl;
// set static data
if
(
is_build
==
false
)
{
...
...
@@ -843,13 +855,13 @@ public:
for
(
size_t
i
=
0
;
i
<
vec_name
.
size
();
++
i
)
{
auto
it
=
global_scope
.
name2id
.
find
(
vec_name
[
i
]
);
cerr
<<
"find "
<<
(
it
!=
global_scope
.
name2id
.
end
()
)
<<
endl
;
//
cerr << "find " << ( it != global_scope.name2id.end() ) <<endl;
assert
(
it
!=
global_scope
.
name2id
.
end
()
);
auto
feed_tensor
=
global_scope
.
var_list
[
it
->
second
]
->
GetMutable
<
framework
::
LoDTensor
>
();
cerr
<<
" get tensor"
<<
endl
;
//
cerr << " get tensor" << endl;
feed_tensor
->
ShareDataWith
(
vec_tensor
[
i
]
);
cerr
<<
"share buffer with"
<<
endl
;
//
cerr << "share buffer with" << endl;
}
if
(
is_build
==
false
)
...
...
@@ -873,14 +885,16 @@ public:
//cerr << "out " << fetch_tensor->data<float>()[0] << endl;
if
(
platform
::
is_gpu_place
(
fetch_tensor
->
place
()
)
)
{
cerr
<<
"fetch gpu"
<<
endl
;
//
cerr << "fetch gpu" << endl;
Tensor
out
;
platform
::
DeviceContextPool
&
pool
=
platform
::
DeviceContextPool
::
Instance
();
auto
*
dev_ctx
=
pool
.
Get
(
place_
);
dev_ctx
->
Wait
();
TensorCopySync
(
*
fetch_tensor
,
platform
::
CPUPlace
(),
&
out
);
dev_ctx
->
Wait
();
cerr
<<
"out "
<<
out
<<
endl
;
//cerr << "out " << out << endl;
//cout << out.data<float>()[0] << endl;
vec_out
.
push_back
(
out
);
}
else
{
...
...
paddle/fluid/pybind/pybind.cc
浏览文件 @
abd3fa4a
...
...
@@ -1980,7 +1980,7 @@ All parameter, weight, gradient are variables in Paddle.
});
py
::
class_
<
framework
::
InterpreterCore
>
(
m
,
"InterpreterCore"
)
.
def
(
py
::
init
<
const
platform
::
Place
&
,
const
ProgramDesc
&>
())
.
def
(
py
::
init
<
const
platform
::
Place
&
,
const
ProgramDesc
&
,
const
ProgramDesc
&
>
())
.
def
(
"run"
,
[](
InterpreterCore
&
self
,
const
std
::
unordered_map
<
std
::
string
,
py
::
array
>&
input_dict
,
std
::
vector
<
std
::
string
>
vec_fetch_name
)
{
pybind11
::
gil_scoped_release
release
;
std
::
vector
<
framework
::
Tensor
>
vec_tensor
;
...
...
@@ -1993,13 +1993,13 @@ All parameter, weight, gradient are variables in Paddle.
for
(
auto
&
item
:
input_dict
)
{
//cerr << "test flag " << test_flag << endl;
cerr
<<
item
.
first
<<
endl
;
//
cerr << item.first << endl;
framework
::
LoDTensor
t
;
SetTensorFromPyArray
<
platform
::
CPUPlace
>
(
&
t
,
item
.
second
,
platform
::
CPUPlace
(),
false
);
cerr
<<
t
.
dims
()
<<
endl
;
cerr
<<
t
.
data
<
float
>
()[
0
]
<<
endl
;
//
cerr << t.dims() << endl;
//
cerr << t.data<float>()[0] << endl;
vec_name
.
push_back
(
item
.
first
);
vec_tensor
.
push_back
(
t
);
...
...
@@ -2007,10 +2007,17 @@ All parameter, weight, gradient are variables in Paddle.
std
::
cerr
<<
"11"
<<
std
::
endl
;
self
.
run
(
vec_name
,
vec_tensor
,
vec_fetch_name
);
//std::cerr << "11" << std::endl;
std
::
vector
<
framework
::
Tensor
>
vec_out
;
self
.
run
(
vec_name
,
vec_tensor
,
vec_fetch_name
,
vec_out
);
//self.Run(prog, scope, block_id, create_local_scope, create_vars,
// fetch_vars);
std
::
vector
<
py
::
array
>
vec_ret
;
for
(
size_t
i
=
0
;
i
<
vec_out
.
size
();
++
i
)
{
vec_ret
.
push_back
(
TensorToPyArray
(
vec_out
[
i
],
true
)
)
;
}
return
vec_ret
;
});
m
.
def
(
"init_gflags"
,
framework
::
InitGflags
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录