Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
MegEngine 天元
MegEngine
提交
202b4071
MegEngine
项目概览
MegEngine 天元
/
MegEngine
1 年多 前同步成功
通知
404
Star
4705
Fork
582
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
MegEngine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
202b4071
编写于
12月 27, 2021
作者:
M
Megvii Engine Team
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix(core): fix output var replaced by optpass
GitOrigin-RevId: aea62de3454722df4610dc3799acbd362ae942e0
上级
e715423f
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
44 addition
and
2 deletion
+44
-2
lite/test/test_network.cpp
lite/test/test_network.cpp
+5
-2
src/serialization/impl/serializer.cpp
src/serialization/impl/serializer.cpp
+30
-0
src/serialization/impl/serializer_oss.cpp
src/serialization/impl/serializer_oss.cpp
+1
-0
src/serialization/include/megbrain/serialization/serializer.h
...serialization/include/megbrain/serialization/serializer.h
+8
-0
未找到文件。
lite/test/test_network.cpp
浏览文件 @
202b4071
...
@@ -510,7 +510,10 @@ void test_io_no_copy_ax(std::string model_name, int record = 1) {
...
@@ -510,7 +510,10 @@ void test_io_no_copy_ax(std::string model_name, int record = 1) {
std
::
vector
<
std
::
vector
<
std
::
shared_ptr
<
Tensor
>>>
inputs
;
std
::
vector
<
std
::
vector
<
std
::
shared_ptr
<
Tensor
>>>
inputs
;
std
::
vector
<
std
::
vector
<
std
::
shared_ptr
<
Tensor
>>>
outputs
;
std
::
vector
<
std
::
vector
<
std
::
shared_ptr
<
Tensor
>>>
outputs
;
std
::
shared_ptr
<
Network
>
network
=
std
::
make_shared
<
Network
>
();
Config
config
;
config
.
options
.
graph_opt_level
=
0
;
std
::
shared_ptr
<
Network
>
network
=
std
::
make_shared
<
Network
>
(
config
);
network
->
load_model
(
model_path
);
network
->
load_model
(
model_path
);
input_names
=
network
->
get_all_input_name
();
input_names
=
network
->
get_all_input_name
();
...
@@ -559,10 +562,10 @@ void test_io_no_copy_ax(std::string model_name, int record = 1) {
...
@@ -559,10 +562,10 @@ void test_io_no_copy_ax(std::string model_name, int record = 1) {
outputs
.
push_back
(
net_outputs
);
outputs
.
push_back
(
net_outputs
);
}
}
Config
config
;
config
.
options
.
force_output_use_user_specified_memory
=
true
;
config
.
options
.
force_output_use_user_specified_memory
=
true
;
config
.
options
.
comp_node_seq_record_level
=
record
;
config
.
options
.
comp_node_seq_record_level
=
record
;
config
.
options
.
const_shape
=
true
;
config
.
options
.
const_shape
=
true
;
config
.
options
.
graph_opt_level
=
2
;
std
::
shared_ptr
<
Network
>
network_record
=
std
::
make_shared
<
Network
>
(
config
);
std
::
shared_ptr
<
Network
>
network_record
=
std
::
make_shared
<
Network
>
(
config
);
...
...
src/serialization/impl/serializer.cpp
浏览文件 @
202b4071
...
@@ -10,6 +10,7 @@
...
@@ -10,6 +10,7 @@
*/
*/
#include "megbrain/serialization/serializer.h"
#include "megbrain/serialization/serializer.h"
#include "megbrain/gopt/inference.h"
#include "megbrain/opr/utility.h"
#include "megbrain/opr/utility.h"
namespace
mgb
{
namespace
mgb
{
...
@@ -27,6 +28,35 @@ std::unique_ptr<cg::AsyncExecutable> GraphLoader::LoadResult::graph_compile(
...
@@ -27,6 +28,35 @@ std::unique_ptr<cg::AsyncExecutable> GraphLoader::LoadResult::graph_compile(
return
ret
;
return
ret
;
}
}
void
GraphLoader
::
LoadResult
::
graph_compile_ahead
()
{
//! when force_output_use_user_specified_memory is set, the output var may
//! be changed by gopt, then the var in LoadResult can not exist, so here
//! just do basic optimize_for_inference ahead, and replace the var in
//! LoadResult
if
(
graph
->
options
().
force_output_use_user_specified_memory
)
{
auto
options
=
gopt
::
OptimizeForInferenceOptions
{};
auto
new_vars
=
gopt
::
optimize_for_inference
(
output_var_list
,
options
);
output_var_list
=
new_vars
;
output_var_map
.
clear
();
for
(
auto
&
var
:
new_vars
)
{
output_var_map
[
var
.
node
()
->
cname
()]
=
var
;
}
std
::
unordered_map
<
size_t
,
SymbolVar
>
var_map_id
;
for
(
auto
&
var
:
new_vars
)
{
bool
found
=
false
;
for
(
auto
&
old_var_it
:
output_var_map_id
)
{
if
(
old_var_it
.
second
.
node
()
->
name
()
==
var
.
node
()
->
name
())
{
found
=
true
;
var_map_id
[
old_var_it
.
first
]
=
var
;
}
}
mgb_assert
(
found
,
"can't find var name %s when optimize_for_inference. "
,
var
.
node
()
->
cname
());
}
}
}
GraphLoader
::
SharedTensorNameMap
GraphLoader
::
shared_tensor_name_map
()
{
GraphLoader
::
SharedTensorNameMap
GraphLoader
::
shared_tensor_name_map
()
{
SharedTensorNameMap
ret
;
SharedTensorNameMap
ret
;
for
(
auto
&&
i
:
shared_tensor_id_map
())
{
for
(
auto
&&
i
:
shared_tensor_id_map
())
{
...
...
src/serialization/impl/serializer_oss.cpp
浏览文件 @
202b4071
...
@@ -946,6 +946,7 @@ GraphLoader::LoadResult GraphLoaderOSS::load(const LoadConfig& config, bool rewi
...
@@ -946,6 +946,7 @@ GraphLoader::LoadResult GraphLoaderOSS::load(const LoadConfig& config, bool rewi
mgb_assert
(
fbs_end
>
cur
);
mgb_assert
(
fbs_end
>
cur
);
// Skip to Graph end
// Skip to Graph end
m_file
->
skip
(
fbs_end
-
cur
);
m_file
->
skip
(
fbs_end
-
cur
);
result
.
graph_compile_ahead
();
return
result
;
return
result
;
}
}
...
...
src/serialization/include/megbrain/serialization/serializer.h
浏览文件 @
202b4071
...
@@ -63,6 +63,14 @@ public:
...
@@ -63,6 +63,14 @@ public:
*/
*/
MGE_WIN_DECLSPEC_FUC
std
::
unique_ptr
<
cg
::
AsyncExecutable
>
graph_compile
(
MGE_WIN_DECLSPEC_FUC
std
::
unique_ptr
<
cg
::
AsyncExecutable
>
graph_compile
(
const
ComputingGraph
::
OutputSpec
&
outspec
);
const
ComputingGraph
::
OutputSpec
&
outspec
);
/*!
* \brief after graph is loaded, do some basic optimized_for_inference,
* because some dest var maybe replaced, case error when optimize flag
* force_output_use_user_specified_memory is on
*
*/
MGE_WIN_DECLSPEC_FUC
void
graph_compile_ahead
();
};
};
//! helper to disable inplace arith graph optimization during
//! helper to disable inplace arith graph optimization during
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录