Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
MegEngine 天元
MegEngine
提交
d02b0a08
MegEngine
项目概览
MegEngine 天元
/
MegEngine
1 年多 前同步成功
通知
403
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看板
提交
d02b0a08
编写于
9月 28, 2021
作者:
M
Megvii Engine Team
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat(lite): fix typo
GitOrigin-RevId: 8c46aa3a303b8a9ad5e29b8779bb4961fa3e3a85
上级
cebda6ff
变更
20
隐藏空白更改
内联
并排
Showing
20 changed file
with
39 addition
and
39 deletion
+39
-39
imperative/src/impl/backward_graph_opt.cpp
imperative/src/impl/backward_graph_opt.cpp
+1
-1
imperative/src/impl/op_def.cpp
imperative/src/impl/op_def.cpp
+4
-4
imperative/src/impl/ops/utility.cpp
imperative/src/impl/ops/utility.cpp
+6
-6
imperative/src/impl/proxy_graph.cpp
imperative/src/impl/proxy_graph.cpp
+2
-2
imperative/src/impl/proxy_graph.h
imperative/src/impl/proxy_graph.h
+1
-1
imperative/src/impl/proxy_graph_detail.cpp
imperative/src/impl/proxy_graph_detail.cpp
+1
-1
imperative/src/impl/subgraph.cpp
imperative/src/impl/subgraph.cpp
+2
-2
imperative/src/impl/subgraph_detail.cpp
imperative/src/impl/subgraph_detail.cpp
+3
-3
imperative/src/include/megbrain/imperative/backward_graph_opt.h
...tive/src/include/megbrain/imperative/backward_graph_opt.h
+1
-1
imperative/src/include/megbrain/imperative/graph_builder.h
imperative/src/include/megbrain/imperative/graph_builder.h
+1
-1
imperative/src/include/megbrain/imperative/op_def.h
imperative/src/include/megbrain/imperative/op_def.h
+2
-2
imperative/src/include/megbrain/imperative/ops/utility.h
imperative/src/include/megbrain/imperative/ops/utility.h
+1
-1
imperative/src/include/megbrain/imperative/proxy_graph_detail.h
...tive/src/include/megbrain/imperative/proxy_graph_detail.h
+1
-1
imperative/src/include/megbrain/imperative/subgraph.h
imperative/src/include/megbrain/imperative/subgraph.h
+5
-5
imperative/src/include/megbrain/imperative/subgraph_detail.h
imperative/src/include/megbrain/imperative/subgraph_detail.h
+2
-2
imperative/src/test/backward_graph.cpp
imperative/src/test/backward_graph.cpp
+1
-1
lite/pylite/pylite.md
lite/pylite/pylite.md
+2
-2
lite/pylite/test/test_global.py
lite/pylite/test/test_global.py
+1
-1
lite/pylite/test/test_network.py
lite/pylite/test/test_network.py
+1
-1
lite/pylite/test/test_network_cuda.py
lite/pylite/test/test_network_cuda.py
+1
-1
未找到文件。
imperative/src/impl/backward_graph_opt.cpp
浏览文件 @
d02b0a08
...
...
@@ -16,7 +16,7 @@
using
namespace
mgb
;
using
namespace
imperative
;
OptimizedBackwardGraphResult
::
OptimizedBackwardGraphResult
(
const
EncodedSubraph
&
src
)
OptimizedBackwardGraphResult
::
OptimizedBackwardGraphResult
(
const
EncodedSub
g
raph
&
src
)
:
input_has_grad
(
src
.
output_mask
)
{
if
(
src
.
graph
.
exprs
.
size
()
<=
1
)
{
// backward graph only contains a single op
...
...
imperative/src/impl/op_def.cpp
浏览文件 @
d02b0a08
...
...
@@ -80,12 +80,12 @@ std::tuple<SmallVector<LogicalTensorDesc>, bool> OpDef::infer_output_attrs_falli
return
def
.
trait
()
->
infer_output_attrs_fallible
(
def
,
inputs
);
}
EncodedSubraph
OpDef
::
make_backward_graph
(
EncodedSub
g
raph
OpDef
::
make_backward_graph
(
const
OpDef
&
def
,
const
SmallVector
<
LogicalTensorDesc
>&
inputs
,
const
SmallVector
<
bool
>&
input_requires_grad
,
const
SmallVector
<
bool
>&
output_has_grad
)
{
using
BackwardGraphCache
=
OpMethResultCache
<
EncodedSubraph
,
SmallVector
<
bool
>
,
SmallVector
<
bool
>>
;
using
BackwardGraphCache
=
OpMethResultCache
<
EncodedSub
g
raph
,
SmallVector
<
bool
>
,
SmallVector
<
bool
>>
;
thread_local
BackwardGraphCache
cache
;
decltype
(
cache
)
::
key_t
cache_key
{
const_cast
<
OpDef
&>
(
def
).
shared_from_this
(),
inputs
,
{
input_requires_grad
,
output_has_grad
}};
auto
iter
=
cache
.
find
(
cache_key
);
...
...
@@ -100,10 +100,10 @@ std::vector<std::pair<const char*, std::string>> OpDef::props(
return
def
.
trait
()
->
props
(
def
);
}
EncodedSubraph
OpDef
::
make_forward_graph
(
EncodedSub
g
raph
OpDef
::
make_forward_graph
(
const
OpDef
&
def
,
const
SmallVector
<
LogicalTensorDesc
>&
inputs
){
using
ForwardGraphCache
=
OpMethResultCache
<
EncodedSubraph
,
SmallVector
<
bool
>
,
SmallVector
<
bool
>>
;
using
ForwardGraphCache
=
OpMethResultCache
<
EncodedSub
g
raph
,
SmallVector
<
bool
>
,
SmallVector
<
bool
>>
;
thread_local
ForwardGraphCache
cache
;
decltype
(
cache
)
::
key_t
cache_key
{
const_cast
<
OpDef
&>
(
def
).
shared_from_this
(),
inputs
};
auto
iter
=
cache
.
find
(
cache_key
);
...
...
imperative/src/impl/ops/utility.cpp
浏览文件 @
d02b0a08
...
...
@@ -182,11 +182,11 @@ OP_TRAIT_REG(Identity, Identity)
namespace
{
namespace
subgraph
{
EncodedSubraph
make_forward_graph
(
const
OpDef
&
def
,
SmallVector
<
LogicalTensorDesc
>
inputs
)
{
return
EncodedSubraph
::
make
(
*
def
.
cast_final_safe
<
SubgraphOp
>
().
graph
);
EncodedSub
g
raph
make_forward_graph
(
const
OpDef
&
def
,
SmallVector
<
LogicalTensorDesc
>
inputs
)
{
return
EncodedSub
g
raph
::
make
(
*
def
.
cast_final_safe
<
SubgraphOp
>
().
graph
);
}
EncodedSubraph
make_backward_graph
(
EncodedSub
g
raph
make_backward_graph
(
const
OpDef
&
def
,
const
SmallVector
<
LogicalTensorDesc
>&
inputs
,
const
SmallVector
<
bool
>&
input_requires_grad
,
...
...
@@ -199,7 +199,7 @@ EncodedSubraph make_backward_graph(
}
}
auto
bgraph
=
subgraph_detail
::
make_backward_graph
(
def
,
inputs
,
input_requires_grad
,
output_has_grad
);
return
EncodedSubraph
::
make_single
(
return
EncodedSub
g
raph
::
make_single
(
SubgraphOp
::
make
(
op
.
name
+
"Grad"
,
std
::
make_shared
<
Subgraph
>
(
bgraph
.
graph
)),
bgraph
.
input_mask
,
bgraph
.
output_mask
);
...
...
@@ -430,7 +430,7 @@ std::tuple<SmallVector<MemoryDesc>, SmallVector<MemoryDesc>> infer_output_mem_de
return
{};
}
EncodedSubraph
make_backward_graph
(
EncodedSub
g
raph
make_backward_graph
(
const
OpDef
&
def
,
const
SmallVector
<
LogicalTensorDesc
>&
inputs
,
const
SmallVector
<
bool
>&
input_requires_grad
,
...
...
@@ -452,7 +452,7 @@ EncodedSubraph make_backward_graph(
grad_outputs_has_grad
,
key
);
}
auto
compiled_op
=
CompiledOp
::
make
(
bgraph_op
,
op
.
gopt_level
);
auto
encoded_graph
=
EncodedSubraph
::
make_single
(
compiled_op
,
backward_graph
.
input_mask
,
backward_graph
.
output_mask
);
auto
encoded_graph
=
EncodedSub
g
raph
::
make_single
(
compiled_op
,
backward_graph
.
input_mask
,
backward_graph
.
output_mask
);
return
encoded_graph
;
}
...
...
imperative/src/impl/proxy_graph.cpp
浏览文件 @
d02b0a08
...
...
@@ -669,7 +669,7 @@ struct ProxyGraph::GradGraph {
cg
::
VarNode
*
grad
;
};
EncodedSubraph
EncodedSub
g
raph
ProxyGraph
::
make_backward_graph
(
const
OpDef
&
opdef
,
const
SmallVector
<
LogicalTensorDesc
>&
input_descs
,
...
...
@@ -704,7 +704,7 @@ ProxyGraph::make_backward_graph(
}
auto
*
gfunc
=
cg
::
lookup_grad_func
(
fwd
->
dyn_typeinfo
());
EncodedSubraph
result
;
EncodedSub
g
raph
result
;
auto
&&
igraph
=
result
.
graph
;
size_t
nr_backward_graph_inputs
=
0
;
...
...
imperative/src/impl/proxy_graph.h
浏览文件 @
d02b0a08
...
...
@@ -40,7 +40,7 @@ public:
const
SmallVector
<
Tensor
*>&
outputs
,
const
SmallVector
<
Tensor
*>&
workspace
);
EncodedSubraph
make_backward_graph
(
EncodedSub
g
raph
make_backward_graph
(
const
OpDef
&
opdef
,
const
SmallVector
<
LogicalTensorDesc
>&
input_descs
,
const
SmallVector
<
bool
>&
input_requires_grad
,
...
...
imperative/src/impl/proxy_graph_detail.cpp
浏览文件 @
d02b0a08
...
...
@@ -113,7 +113,7 @@ void execute(const OpDef& def,
// return graph->infer_output_attrs_fallible(def, inputs);
// }
EncodedSubraph
EncodedSub
g
raph
make_backward_graph
(
const
OpDef
&
def
,
const
SmallVector
<
LogicalTensorDesc
>&
inputs
,
const
SmallVector
<
bool
>&
input_requires_grad
,
...
...
imperative/src/impl/subgraph.cpp
浏览文件 @
d02b0a08
...
...
@@ -101,7 +101,7 @@ void Subgraph::replace_vars(
}
}
std
::
string
EncodedSubraph
::
repr
()
const
{
std
::
string
EncodedSub
g
raph
::
repr
()
const
{
std
::
string
buffer
;
buffer
.
push_back
(
'|'
);
for
(
size_t
i
=
0
;
i
<
input_mask
.
size
();
++
i
)
{
...
...
@@ -118,7 +118,7 @@ std::string EncodedSubraph::repr() const {
return
buffer
;
}
size_t
EncodedSubraph
::
hash
()
const
{
size_t
EncodedSub
g
raph
::
hash
()
const
{
return
std
::
hash
<
std
::
string
>
{}(
repr
());
}
...
...
imperative/src/impl/subgraph_detail.cpp
浏览文件 @
d02b0a08
...
...
@@ -76,11 +76,11 @@ SmallVector<TensorPtr> apply_on_physical_tensor(
return
outputs
;
}
static
EncodedSubraph
make_backward_graph_from_forward
(
static
EncodedSub
g
raph
make_backward_graph_from_forward
(
const
SmallVector
<
LogicalTensorDesc
>&
inputs
,
const
SmallVector
<
bool
>&
input_requires_grad
,
const
SmallVector
<
bool
>&
output_has_grad
,
EncodedSubraph
forward_graph
)
{
EncodedSub
g
raph
forward_graph
)
{
using
namespace
std
::
placeholders
;
using
var_t
=
Subgraph
::
var_t
;
using
vars_t
=
Subgraph
::
vars_t
;
...
...
@@ -149,7 +149,7 @@ static EncodedSubraph make_backward_graph_from_forward(
return
backward_graph
;
}
EncodedSubraph
make_backward_graph
(
EncodedSub
g
raph
make_backward_graph
(
const
OpDef
&
def
,
const
SmallVector
<
LogicalTensorDesc
>&
inputs
,
const
SmallVector
<
bool
>&
input_requires_grad
,
...
...
imperative/src/include/megbrain/imperative/backward_graph_opt.h
浏览文件 @
d02b0a08
...
...
@@ -19,7 +19,7 @@ struct OptimizedBackwardGraphResult {
SmallVector
<
bool
>
save_for_backward
;
SmallVector
<
bool
>
input_has_grad
;
OptimizedBackwardGraphResult
(
const
EncodedSubraph
&
bgraph
);
OptimizedBackwardGraphResult
(
const
EncodedSub
g
raph
&
bgraph
);
};
}
// namespace mgb::imperative
imperative/src/include/megbrain/imperative/graph_builder.h
浏览文件 @
d02b0a08
...
...
@@ -29,7 +29,7 @@ class Subgraph::Builder {
using
desc_t
=
TDesc
;
using
descs_t
=
SmallVector
<
TDesc
>
;
using
infer_fn_t
=
std
::
function
<
descs_t
(
op_t
,
descs_t
,
size_t
)
>
;
using
encoded_graph_t
=
EncodedSubraph
;
using
encoded_graph_t
=
EncodedSub
g
raph
;
using
var_map_t
=
std
::
unordered_map
<
var_t
,
var_t
>
;
vars_t
m_inputs
;
SmallVector
<
std
::
pair
<
var_t
,
TensorPtr
>>
m_constants
;
...
...
imperative/src/include/megbrain/imperative/op_def.h
浏览文件 @
d02b0a08
...
...
@@ -87,7 +87,7 @@ public:
const
SmallVector
<
TensorPtr
>&
inputs_tensors
,
const
SmallVector
<
MemoryDesc
>&
inputs_mems
);
static
EncodedSubraph
make_backward_graph
(
static
EncodedSub
g
raph
make_backward_graph
(
const
OpDef
&
def
,
const
SmallVector
<
LogicalTensorDesc
>&
inputs
,
const
SmallVector
<
bool
>&
input_requires_grad
,
...
...
@@ -96,7 +96,7 @@ public:
static
std
::
vector
<
std
::
pair
<
const
char
*
,
std
::
string
>>
props
(
const
OpDef
&
def
);
static
EncodedSubraph
make_forward_graph
(
static
EncodedSub
g
raph
make_forward_graph
(
const
OpDef
&
def
,
const
SmallVector
<
LogicalTensorDesc
>&
inputs
);
...
...
imperative/src/include/megbrain/imperative/ops/utility.h
浏览文件 @
d02b0a08
...
...
@@ -40,7 +40,7 @@ struct ShapeInfer final : OpDefImplBase<ShapeInfer> {
std
::
shared_ptr
<
OpDef
>
op
;
SmallVector
<
CompNode
>
devices
;
SmallVector
<
DType
>
dtypes
;
EncodedSubraph
graph
;
EncodedSub
g
raph
graph
;
ShapeInfer
()
=
default
;
ShapeInfer
(
std
::
shared_ptr
<
OpDef
>
op
,
SmallVector
<
CompNode
>
devices
,
SmallVector
<
DType
>
dtypes
)
...
...
imperative/src/include/megbrain/imperative/proxy_graph_detail.h
浏览文件 @
d02b0a08
...
...
@@ -38,7 +38,7 @@ void exec(const OpDef& def,
const
SmallVector
<
TensorPtr
>&
inputs
,
const
SmallVector
<
TensorPtr
>&
outputs
);
EncodedSubraph
EncodedSub
g
raph
make_backward_graph
(
const
OpDef
&
def
,
const
SmallVector
<
LogicalTensorDesc
>&
inputs
,
const
SmallVector
<
bool
>&
input_requires_grad
,
...
...
imperative/src/include/megbrain/imperative/subgraph.h
浏览文件 @
d02b0a08
...
...
@@ -96,7 +96,7 @@ struct Subgraph {
bool
operator
==
(
const
Subgraph
&
rhs
)
const
;
};
struct
EncodedSubraph
{
struct
EncodedSub
g
raph
{
Subgraph
graph
;
SmallVector
<
bool
>
input_mask
;
SmallVector
<
bool
>
output_mask
;
...
...
@@ -146,8 +146,8 @@ struct EncodedSubraph {
return
decoded_outputs
;
}
static
EncodedSubraph
make
(
Subgraph
graph
)
{
EncodedSubraph
result
;
static
EncodedSub
g
raph
make
(
Subgraph
graph
)
{
EncodedSub
g
raph
result
;
result
.
input_mask
=
graph
.
gen_input_mask
();
result
.
output_mask
=
graph
.
gen_output_mask
();
graph
.
inputs
=
result
.
encode_inputs
(
graph
.
inputs
);
...
...
@@ -156,11 +156,11 @@ struct EncodedSubraph {
return
result
;
}
static
EncodedSubraph
make_single
(
static
EncodedSub
g
raph
make_single
(
std
::
shared_ptr
<
OpDef
>
op
,
SmallVector
<
bool
>
input_mask
,
SmallVector
<
bool
>
output_mask
)
{
EncodedSubraph
result
;
EncodedSub
g
raph
result
;
result
.
input_mask
=
input_mask
;
result
.
output_mask
=
output_mask
;
Subgraph
::
var_t
last_var
=
0
;
...
...
imperative/src/include/megbrain/imperative/subgraph_detail.h
浏览文件 @
d02b0a08
...
...
@@ -24,7 +24,7 @@ apply_on_physical_tensor(const OpDef& def,
std
::
tuple
<
SmallVector
<
LogicalTensorDesc
>
,
bool
>
infer_output_attrs_fallible
(
const
OpDef
&
def
,
const
SmallVector
<
LogicalTensorDesc
>&
inputs
);
EncodedSubraph
EncodedSub
g
raph
make_backward_graph
(
const
OpDef
&
def
,
const
SmallVector
<
LogicalTensorDesc
>&
inputs
,
const
SmallVector
<
bool
>&
input_requires_grad
,
...
...
@@ -35,7 +35,7 @@ apply_on_var_node(
const
OpDef
&
def
,
const
VarNodeArray
&
inputs
);
EncodedSubraph
make_backward_graph
(
EncodedSub
g
raph
make_backward_graph
(
const
OpDef
&
def
,
const
SmallVector
<
LogicalTensorDesc
>&
inputs
,
const
SmallVector
<
bool
>&
input_requires_grad
,
...
...
imperative/src/test/backward_graph.cpp
浏览文件 @
d02b0a08
...
...
@@ -22,7 +22,7 @@ using namespace cg;
using
namespace
imperative
;
template
<
typename
T
>
T
prepare_backward_graph_inputs
(
const
EncodedSubraph
&
bg
,
const
T
&
inputs
,
T
prepare_backward_graph_inputs
(
const
EncodedSub
g
raph
&
bg
,
const
T
&
inputs
,
const
T
&
outputs
,
const
T
&
grads
)
{
T
ret
;
size_t
i
=
0
;
...
...
lite/pylite/pylite.md
浏览文件 @
d02b0a08
...
...
@@ -143,7 +143,7 @@ LiteNetwork 主要为用户提供模型载入,运行等功能。使用的模
*
CPU 基本模型载入运行的 example
```
def test_network_basic():
source_dir = os.getenv("LITE_TEST_RESOUCE")
source_dir = os.getenv("LITE_TEST_RESOU
R
CE")
input_data_path = os.path.join(source_dir, "input_data.npy")
# read input to input_data
input_data = np.load(input_data_path)
...
...
@@ -176,7 +176,7 @@ def test_network_basic():
*
CUDA 上使用 device 内存作为模型输入,需要在构造 network 候配置 config 和 IO 信息
```
def test_network_device_IO():
source_dir = os.getenv("LITE_TEST_RESOUCE")
source_dir = os.getenv("LITE_TEST_RESOU
R
CE")
input_data_path = os.path.join(source_dir, "input_data.npy")
model_path = os.path.join(source_dir, "shufflenet.mge")
# read input to input_data
...
...
lite/pylite/test/test_global.py
浏览文件 @
d02b0a08
...
...
@@ -18,7 +18,7 @@ set_log_level(2)
class
TestShuffleNet
(
unittest
.
TestCase
):
source_dir
=
os
.
getenv
(
"LITE_TEST_RESOUCE"
)
source_dir
=
os
.
getenv
(
"LITE_TEST_RESOU
R
CE"
)
input_data_path
=
os
.
path
.
join
(
source_dir
,
"input_data.npy"
)
correct_data_path
=
os
.
path
.
join
(
source_dir
,
"output_data.npy"
)
correct_data
=
np
.
load
(
correct_data_path
).
flatten
()
...
...
lite/pylite/test/test_network.py
浏览文件 @
d02b0a08
...
...
@@ -52,7 +52,7 @@ def test_network_io():
class
TestShuffleNet
(
unittest
.
TestCase
):
source_dir
=
os
.
getenv
(
"LITE_TEST_RESOUCE"
)
source_dir
=
os
.
getenv
(
"LITE_TEST_RESOU
R
CE"
)
input_data_path
=
os
.
path
.
join
(
source_dir
,
"input_data.npy"
)
correct_data_path
=
os
.
path
.
join
(
source_dir
,
"output_data.npy"
)
model_path
=
os
.
path
.
join
(
source_dir
,
"shufflenet.mge"
)
...
...
lite/pylite/test/test_network_cuda.py
浏览文件 @
d02b0a08
...
...
@@ -33,7 +33,7 @@ def require_cuda(ngpu=1):
class
TestShuffleNetCuda
(
unittest
.
TestCase
):
source_dir
=
os
.
getenv
(
"LITE_TEST_RESOUCE"
)
source_dir
=
os
.
getenv
(
"LITE_TEST_RESOU
R
CE"
)
input_data_path
=
os
.
path
.
join
(
source_dir
,
"input_data.npy"
)
correct_data_path
=
os
.
path
.
join
(
source_dir
,
"output_data.npy"
)
model_path
=
os
.
path
.
join
(
source_dir
,
"shufflenet.mge"
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录