Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
兔爷不爱我
mindspore
提交
17adba5e
M
mindspore
项目概览
兔爷不爱我
/
mindspore
与 Fork 源项目一致
Fork自
MindSpore / mindspore
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
M
mindspore
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
17adba5e
编写于
4月 23, 2020
作者:
F
fary86
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Optimize flow of exproting onnx
上级
c8035696
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
34 addition
and
19 deletion
+34
-19
mindspore/ccsrc/pipeline/pipeline.cc
mindspore/ccsrc/pipeline/pipeline.cc
+26
-14
mindspore/ccsrc/pipeline/pipeline.h
mindspore/ccsrc/pipeline/pipeline.h
+1
-0
mindspore/ccsrc/utils/profile.cc
mindspore/ccsrc/utils/profile.cc
+2
-2
mindspore/common/api.py
mindspore/common/api.py
+4
-2
mindspore/train/serialization.py
mindspore/train/serialization.py
+1
-1
未找到文件。
mindspore/ccsrc/pipeline/pipeline.cc
浏览文件 @
17adba5e
...
...
@@ -294,6 +294,30 @@ void ExecutorPy::SaveCompiledGraph(const std::string &phase_s) {
MS_LOG
(
INFO
)
<<
"End save compiled func graph!"
;
}
void
ExecutorPy
::
SaveCompiledGraphToPb
(
const
std
::
string
&
phase_s
)
{
#ifdef ENABLE_DUMP_IR
// save the graph to file in protobuf format
FuncGraphPtr
func_graph
=
info_
[
phase_s
]
->
resource
->
func_graph
();
MS_EXCEPTION_IF_NULL
(
func_graph
);
std
::
string
name_prefix
=
phase_s
.
substr
(
0
,
phase_s
.
find
(
"."
));
std
::
string
pb_filename
=
std
::
string
(
"ms_output_"
)
+
name_prefix
+
".pb"
;
std
::
string
filename
=
GetFilePathName
(
pb_filename
);
MS_LOG
(
INFO
)
<<
"Begin saving graph to file <<'"
<<
filename
<<
"' in protobuf formart."
;
ChangeFileMode
(
filename
,
S_IRWXU
);
std
::
ofstream
ofs
(
filename
);
if
(
!
ofs
.
is_open
())
{
MS_LOG
(
ERROR
)
<<
"Open file '"
<<
filename
<<
"' failed!"
;
return
;
}
ofs
<<
GetFuncGraphProtoString
(
func_graph
);
ofs
.
close
();
// set file mode to read only by user
ChangeFileMode
(
filename
,
S_IRUSR
);
MS_LOG
(
INFO
)
<<
"End saving graph to file in protobuf format"
;
#endif
}
bool
ExecutorPy
::
ChangeExportGeirUseVmFlag
(
bool
use_vm
,
const
std
::
string
&
phase_s
)
const
{
std
::
string
phase_prefix
=
GetPhasePrefix
(
phase_s
);
...
...
@@ -365,6 +389,8 @@ bool ExecutorPy::CompileInner(const py::object &obj, const py::tuple &args, cons
info_
[
phase_s
]
=
executor_info
;
pip
->
Run
();
// save compile graph to file in protobuf format
SaveCompiledGraphToPb
(
phase_s
);
// save the run graph func to MsPipeLine
SaveCompiledGraph
(
phase_s
);
...
...
@@ -557,20 +583,6 @@ void Pipeline::Run() {
std
::
string
user_graph_file
=
GetFilePathName
(
"ModelDigraph.dot"
);
MS_LOG
(
DEBUG
)
<<
"Save user graph to: "
<<
user_graph_file
;
draw
::
DrawUserFuncGraph
(
user_graph_file
,
user_graph
);
#ifdef ENABLE_DUMP_IR
std
::
string
filename
=
GetFilePathName
(
"ms_output.pb"
);
ChangeFileMode
(
filename
,
S_IRWXU
);
std
::
ofstream
ofs
(
filename
);
if
(
!
ofs
.
is_open
())
{
MS_LOG
(
ERROR
)
<<
"Open file '"
<<
filename
<<
"' failed!"
;
return
;
}
ofs
<<
GetFuncGraphProtoString
(
user_graph
);
ofs
.
close
();
// set file mode to read only by user
ChangeFileMode
(
filename
,
S_IRUSR
);
#endif
}
MS_LOG
(
INFO
)
<<
"End"
;
}
...
...
mindspore/ccsrc/pipeline/pipeline.h
浏览文件 @
17adba5e
...
...
@@ -70,6 +70,7 @@ class ExecutorPy : public std::enable_shared_from_this<ExecutorPy> {
~
ExecutorPy
();
void
SaveCompiledGraph
(
const
std
::
string
&
phase_s
);
void
SaveCompiledGraphToPb
(
const
std
::
string
&
phase_s
);
bool
CompileInner
(
const
py
::
object
&
obj
,
const
py
::
tuple
&
args
,
const
py
::
object
&
phase
,
bool
use_vm
);
bool
Compile
(
const
py
::
object
&
obj
,
const
py
::
tuple
&
args
,
const
py
::
object
&
phase
,
bool
use_vm
);
...
...
mindspore/ccsrc/utils/profile.cc
浏览文件 @
17adba5e
...
...
@@ -158,7 +158,7 @@ void Profile::Print(void) {
std
::
ostringstream
oss
;
PrintProfile
(
oss
,
*
ctx_ptr_
->
time_info_
);
std
::
string
text
=
oss
.
str
();
//
the length of text is too long to use MS_LOGINFO, use printf to print it
//
here use printf to output profile info, not use MS_LOG(INFO) since when open log, it affects performace
(
void
)
printf
(
"%s"
,
text
.
c_str
());
(
void
)
fflush
(
stdout
);
}
...
...
@@ -358,7 +358,7 @@ void MsProfile::Print() {
PrintTimeStat
(
oss
,
groups
[
i
],
prefix
);
}
std
::
string
text
=
oss
.
str
();
//
the length of text is too long to use MS_LOGINFO, use printf to print it
//
here use printf to output profile info, not use MS_LOG(INFO) since when open log, it affects performace
(
void
)
printf
(
"
\n
Time group info:
\n
%s"
,
text
.
c_str
());
(
void
)
fflush
(
stdout
);
}
...
...
mindspore/common/api.py
浏览文件 @
17adba5e
...
...
@@ -328,7 +328,7 @@ class _Executor:
raise
TypeError
(
'Parameters need OrderedDict type, but got {}'
.
format
(
type
(
params
)))
def
compile
(
self
,
obj
,
*
args
,
phase
=
'predict'
,
params
=
None
):
def
compile
(
self
,
obj
,
*
args
,
phase
=
'predict'
,
params
=
None
,
do_convert
=
True
):
"""
Compiles graph.
...
...
@@ -337,6 +337,7 @@ class _Executor:
args (tuple): Function or cell input arguments.
phase (str): The name of compile phase. Default: 'predict'.
params (OrderedDict): The parameters dictionary used for init data graph. Default: None.
do_convert (bool): When set to True, convert ME graph to GE graph after compiling graph.
Return:
Str, the full phase of the cell.
...
...
@@ -368,7 +369,8 @@ class _Executor:
if
graph
is
None
:
logger
.
error
(
"%r graph compile failed."
,
phase
)
if
not
do_convert
:
return
phase
,
True
if
not
enable_debug_runtime
or
enable_ge
:
if
_get_parallel_mode
()
in
[
"auto_parallel"
,
"semi_auto_parallel"
]:
obj
.
parameter_layout_dict
=
self
.
_executor
.
get_parameter_layout
(
phase
)
...
...
mindspore/train/serialization.py
浏览文件 @
17adba5e
...
...
@@ -450,7 +450,7 @@ def export(net, *inputs, file_name, file_format='GEIR'):
_executor
.
export
(
net
,
file_name
,
file_format
)
elif
file_format
==
'ONNX'
:
# file_format is 'ONNX'
phase_name
=
'export_onnx'
graph_id
,
_
=
_executor
.
compile
(
net
,
*
inputs
,
phase
=
phase_name
)
graph_id
,
_
=
_executor
.
compile
(
net
,
*
inputs
,
phase
=
phase_name
,
do_convert
=
False
)
onnx_stream
=
_executor
.
_get_func_graph_proto
(
graph_id
)
with
open
(
file_name
,
'wb'
)
as
f
:
os
.
chmod
(
file_name
,
stat
.
S_IWUSR
|
stat
.
S_IRUSR
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录