Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
MegEngine 天元
MegEngine
提交
bf0f3d31
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看板
提交
bf0f3d31
编写于
11月 03, 2021
作者:
M
Megvii Engine Team
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix(mge/traced_module): fix treedef repr
GitOrigin-RevId: 3df05e9c22f87ff68c56aed01dc668d241385ea4
上级
3b41840b
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
48 addition
and
5 deletion
+48
-5
imperative/python/megengine/traced_module/pytree.py
imperative/python/megengine/traced_module/pytree.py
+42
-4
imperative/python/megengine/traced_module/traced_module.py
imperative/python/megengine/traced_module/traced_module.py
+6
-1
未找到文件。
imperative/python/megengine/traced_module/pytree.py
浏览文件 @
bf0f3d31
...
...
@@ -10,7 +10,7 @@ import collections
from
collections
import
OrderedDict
,
defaultdict
from
functools
import
partial
from
inspect
import
FullArgSpec
from
typing
import
Any
,
Callable
,
List
,
NamedTuple
,
Tuple
from
typing
import
Any
,
Callable
,
Dict
,
List
,
NamedTuple
,
Tuple
import
numpy
as
np
...
...
@@ -284,8 +284,43 @@ class TreeDef:
and
self
.
children_defs
==
other
.
children_defs
)
def
_args_kwargs_repr
(
self
):
if
(
len
(
self
.
children_defs
)
==
2
and
issubclass
(
self
.
children_defs
[
0
].
type
,
(
List
,
Tuple
))
and
issubclass
(
self
.
children_defs
[
1
].
type
,
Dict
)
):
args_def
=
self
.
children_defs
[
0
]
content
=
", "
.
join
(
repr
(
i
)
for
i
in
args_def
.
children_defs
)
kwargs_def
=
self
.
children_defs
[
1
]
if
kwargs_def
.
aux_data
:
content
+=
", "
content
+=
", "
.
join
(
str
(
i
)
+
"="
+
repr
(
j
)
for
i
,
j
in
zip
(
kwargs_def
.
aux_data
,
kwargs_def
.
children_defs
)
)
return
content
else
:
return
repr
(
self
)
def
__repr__
(
self
):
return
"{}[{}]"
.
format
(
self
.
type
.
__name__
,
self
.
children_defs
)
format_str
=
self
.
type
.
__name__
+
"({})"
aux_data_delimiter
=
"="
if
issubclass
(
self
.
type
,
List
):
format_str
=
"[{}]"
if
issubclass
(
self
.
type
,
Tuple
):
format_str
=
"({})"
if
issubclass
(
self
.
type
,
Dict
):
format_str
=
"{{{}}}"
aux_data_delimiter
=
":"
if
self
.
aux_data
:
content
=
", "
.
join
(
repr
(
i
)
+
aux_data_delimiter
+
repr
(
j
)
for
i
,
j
in
zip
(
self
.
aux_data
,
self
.
children_defs
)
)
else
:
content
=
", "
.
join
(
repr
(
i
)
for
i
in
self
.
children_defs
)
return
format_str
.
format
(
content
)
class
LeafDef
(
TreeDef
):
...
...
@@ -315,6 +350,9 @@ class LeafDef(TreeDef):
return
hash
(
tuple
([
self
.
type
,
self
.
const_val
]))
def
__repr__
(
self
):
return
"Leaf({}[{}])"
.
format
(
", "
.
join
(
t
.
__name__
for
t
in
self
.
type
),
self
.
const_val
return
"{}"
.
format
(
self
.
const_val
if
self
.
const_val
is
not
None
or
type
(
None
)
in
self
.
type
else
self
.
type
[
0
].
__name__
)
imperative/python/megengine/traced_module/traced_module.py
浏览文件 @
bf0f3d31
...
...
@@ -1977,7 +1977,12 @@ class TracedModule(Module):
if
hasattr
(
self
,
"argspec"
)
and
self
.
argspec
is
not
None
:
args
,
kwargs
=
_convert_kwargs_to_args
(
self
.
argspec
,
args
,
kwargs
,
True
)
inputs
,
treedef
=
tree_flatten
(((
self
,
*
args
),
kwargs
))
assert
treedef
in
self
.
argdef_graph_map
assert
(
treedef
in
self
.
argdef_graph_map
),
"support input args kwargs format:
\n
{}, but get:
\n
{}"
.
format
(
"
\n
"
.
join
(
"forward({})"
.
format
(
i
.
_args_kwargs_repr
())
for
i
in
self
.
argdef_graph_map
.
keys
()),
treedef
.
_args_kwargs_repr
(),
)
inputs
=
filter
(
lambda
i
:
isinstance
(
i
,
(
Module
,
TracedModuleBuilder
,
RawTensor
)),
inputs
)
# allow TracedModuleBuilder for retrace.
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录