Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
MegEngine 天元
MegEngine
提交
9748aebe
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看板
提交
9748aebe
编写于
10月 14, 2020
作者:
M
Megvii Engine Team
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refactor(mge): tensor_shape -> symbolic_shape
GitOrigin-RevId: 366dc048bfd7473a6bd148cb5d1ab70235aa43f1
上级
8acc3acf
变更
10
隐藏空白更改
内联
并排
Showing
10 changed file
with
31 addition
and
31 deletion
+31
-31
imperative/python/megengine/core/_trace_option.py
imperative/python/megengine/core/_trace_option.py
+8
-8
imperative/python/megengine/core/tensor/indexing.py
imperative/python/megengine/core/tensor/indexing.py
+3
-3
imperative/python/megengine/core/tensor/tensor_wrapper.py
imperative/python/megengine/core/tensor/tensor_wrapper.py
+4
-4
imperative/python/megengine/jit/tracing.py
imperative/python/megengine/jit/tracing.py
+4
-4
imperative/python/test/integration/test_correctness.py
imperative/python/test/integration/test_correctness.py
+1
-1
imperative/python/test/unit/core/test_indexing_op.py
imperative/python/test/unit/core/test_indexing_op.py
+2
-2
imperative/python/test/unit/functional/test_functional.py
imperative/python/test/unit/functional/test_functional.py
+1
-1
imperative/python/test/unit/functional/test_tensor.py
imperative/python/test/unit/functional/test_tensor.py
+1
-1
imperative/python/test/unit/module/test_batchnorm.py
imperative/python/test/unit/module/test_batchnorm.py
+1
-1
imperative/python/test/unit/test_tracing.py
imperative/python/test/unit/test_tracing.py
+6
-6
未找到文件。
imperative/python/megengine/core/_trace_option.py
浏览文件 @
9748aebe
...
...
@@ -9,20 +9,20 @@
import
os
_use_
tensor
_shape
=
False
if
os
.
environ
.
get
(
"MEGENGINE_USE_
TENSOR
_SHAPE"
):
_use_
tensor
_shape
=
True
_use_
symbolic
_shape
=
False
if
os
.
environ
.
get
(
"MEGENGINE_USE_
SYMBOLIC
_SHAPE"
):
_use_
symbolic
_shape
=
True
def
use_
tensor
_shape
()
->
bool
:
def
use_
symbolic
_shape
()
->
bool
:
"""Returns whether tensor.shape returns a tensor instead of a tuple
"""
return
_use_
tensor
_shape
return
_use_
symbolic
_shape
def
set_
tensor
_shape
(
option
:
bool
):
def
set_
symbolic
_shape
(
option
:
bool
):
""" Sets whether tensor.shape returns a tensor instead of a tuple
"""
global
_use_
tensor
_shape
_use_
tensor
_shape
=
option
global
_use_
symbolic
_shape
_use_
symbolic
_shape
=
option
imperative/python/megengine/core/tensor/indexing.py
浏览文件 @
9748aebe
...
...
@@ -10,7 +10,7 @@ from typing import Iterable
import
numpy
as
np
from
.._trace_option
import
use_
tensor
_shape
from
.._trace_option
import
use_
symbolic
_shape
from
..ops
import
builtin
from
..ops.special
import
Const
from
.core
import
TensorBase
,
TensorWrapperBase
,
apply
...
...
@@ -58,7 +58,7 @@ def check_bool_index(tensor, tuple_val):
)
)
i
=
i
.
reshape
(
-
1
)
if
not
use_
tensor
_shape
():
if
not
use_
symbolic
_shape
():
cur_shape
=
(
cur_shape
[:
idx
]
+
(
i
.
shape
[
0
],)
...
...
@@ -76,7 +76,7 @@ def check_bool_index(tensor, tuple_val):
offset
+=
1
tensor
=
tensor
.
reshape
(
cur_shape
)
tdim
+=
tot
if
use_
tensor
_shape
():
if
use_
symbolic
_shape
():
cur_shape
=
make_shape_tuple
(
cur_shape
)
new_tuple_val
.
append
(
i
)
else
:
...
...
imperative/python/megengine/core/tensor/tensor_wrapper.py
浏览文件 @
9748aebe
...
...
@@ -11,7 +11,7 @@ import collections
import
numpy
as
np
from
.._trace_option
import
use_
tensor
_shape
from
.._trace_option
import
use_
symbolic
_shape
from
..ops
import
builtin
from
..ops.builtin
import
GetVarShape
from
..ops.special
import
Const
...
...
@@ -342,7 +342,7 @@ class ArrayMethodMixin(abc.ABC):
def
__len__
(
self
):
shape
=
self
.
shape
if
use_
tensor
_shape
():
if
use_
symbolic
_shape
():
shape
=
shape
.
numpy
()
if
shape
:
return
int
(
shape
[
0
])
...
...
@@ -372,7 +372,7 @@ class ArrayMethodMixin(abc.ABC):
@
property
def
size
(
self
):
if
use_
tensor
_shape
():
if
use_
symbolic
_shape
():
return
self
.
shape
.
prod
()
return
np
.
prod
(
self
.
shape
).
item
()
...
...
@@ -462,7 +462,7 @@ class GenericTensorWrapper(ArrayMethodMixin, TensorWrapperBase):
@
property
def
shape
(
self
):
if
use_
tensor
_shape
():
if
use_
symbolic
_shape
():
return
apply
(
GetVarShape
(),
self
)[
0
]
else
:
return
self
.
__wrapped__
.
shape
...
...
imperative/python/megengine/jit/tracing.py
浏览文件 @
9748aebe
...
...
@@ -19,7 +19,7 @@ import numpy as np
from
..core._imperative_rt
import
GraphProfiler
from
..core._imperative_rt.ops
import
OprAttr
from
..core._trace_option
import
set_
tensor
_shape
from
..core._trace_option
import
set_
symbolic
_shape
from
..core.ops.special
import
Const
from
..core.tensor
import
megbrain_graph
as
G
from
..core.tensor.core
import
OpBase
,
TensorBase
,
TensorWrapperBase
,
apply
...
...
@@ -121,7 +121,7 @@ class trace:
sublinear_memory_config
:
SublinearMemoryConfig
=
None
,
profiling
:
bool
=
False
,
opt_level
:
int
=
None
,
tensor
_shape
:
bool
=
True
,
symbolic
_shape
:
bool
=
True
,
):
self
.
__wrapped__
=
function
self
.
_symbolic
=
symbolic
...
...
@@ -130,7 +130,7 @@ class trace:
self
.
_profiling
=
profiling
self
.
_profiler
=
None
self
.
_graph_opt_level
=
opt_level
self
.
_
tensor_shape
=
tensor
_shape
self
.
_
symbolic_shape
=
symbolic
_shape
self
.
_reset
()
...
...
@@ -152,7 +152,7 @@ class trace:
self
.
_output_bindings
=
None
self
.
_output_names
=
None
set_
tensor_shape
(
self
.
_tensor
_shape
)
set_
symbolic_shape
(
self
.
_symbolic
_shape
)
def
_new_handle
(
self
):
handle
=
len
(
self
.
_tinfo
)
...
...
imperative/python/test/integration/test_correctness.py
浏览文件 @
9748aebe
...
...
@@ -18,7 +18,7 @@ import megengine as mge
import
megengine.autodiff
as
ad
import
megengine.functional
as
F
from
megengine
import
jit
from
megengine.core._trace_option
import
set_
tensor
_shape
from
megengine.core._trace_option
import
set_
symbolic
_shape
from
megengine.core.tensor.utils
import
make_shape_tuple
from
megengine.functional.debug_param
import
set_conv_execution_strategy
from
megengine.jit
import
SublinearMemoryConfig
...
...
imperative/python/test/unit/core/test_indexing_op.py
浏览文件 @
9748aebe
...
...
@@ -13,7 +13,7 @@ import pytest
import
megengine.core.ops.builtin
import
megengine.core.tensor.raw_tensor
from
megengine.core._trace_option
import
use_
tensor
_shape
from
megengine.core._trace_option
import
use_
symbolic
_shape
from
megengine.core.ops._internal
import
all_ops
from
megengine.core.tensor
import
Tensor
from
megengine.core.tensor.core
import
apply
...
...
@@ -532,7 +532,7 @@ def test_advance_indexing_with_bool():
np
.
testing
.
assert_equal
(
a
,
aa
.
numpy
())
# XXX: trace does not expect empty condtake tensor
if
not
use_
tensor
_shape
():
if
not
use_
symbolic
_shape
():
a
=
np
.
ones
((
2
,
2
),
dtype
=
np
.
int32
)
b
=
np
.
array
([[
False
,
False
],
[
False
,
False
]])
aa
=
Tensor
(
a
)
...
...
imperative/python/test/unit/functional/test_functional.py
浏览文件 @
9748aebe
...
...
@@ -17,7 +17,7 @@ import megengine.core.ops.builtin as builtin
import
megengine.core.tensor.dtype
as
dtype
import
megengine.functional
as
F
from
megengine
import
Parameter
,
Tensor
,
is_cuda_available
,
tensor
from
megengine.core._trace_option
import
use_
tensor
_shape
from
megengine.core._trace_option
import
use_
symbolic
_shape
from
megengine.core.autodiff.grad
import
Grad
from
megengine.core.tensor.utils
import
make_shape_tuple
...
...
imperative/python/test/unit/functional/test_tensor.py
浏览文件 @
9748aebe
...
...
@@ -15,7 +15,7 @@ from utils import opr_test
import
megengine.functional
as
F
from
megengine
import
tensor
from
megengine.core._trace_option
import
use_
tensor
_shape
from
megengine.core._trace_option
import
use_
symbolic
_shape
from
megengine.core.tensor.utils
import
astensor1d
from
megengine.distributed.helper
import
get_device_count_by_fork
...
...
imperative/python/test/unit/module/test_batchnorm.py
浏览文件 @
9748aebe
...
...
@@ -16,7 +16,7 @@ import pytest
import
megengine
as
mge
import
megengine.distributed
as
dist
from
megengine
import
Tensor
from
megengine.core._trace_option
import
use_
tensor
_shape
from
megengine.core._trace_option
import
use_
symbolic
_shape
from
megengine.module
import
BatchNorm1d
,
BatchNorm2d
,
SyncBatchNorm
_assert_allclose
=
functools
.
partial
(
np
.
testing
.
assert_allclose
,
atol
=
5e-6
,
rtol
=
5e-6
)
...
...
imperative/python/test/unit/test_tracing.py
浏览文件 @
9748aebe
...
...
@@ -15,7 +15,7 @@ import pytest
import
megengine.core.tensor.megbrain_graph
as
G
import
megengine.functional
as
F
from
megengine
import
cgtools
,
tensor
from
megengine.core._trace_option
import
set_
tensor
_shape
from
megengine.core._trace_option
import
set_
symbolic
_shape
from
megengine.core.ops
import
builtin
as
ops
from
megengine.core.tensor.core
import
apply
from
megengine.core.tensor.raw_tensor
import
as_raw_tensor
...
...
@@ -238,7 +238,7 @@ def test_optimize_for_inference():
def
test_optimize_for_inference_broadcast
():
a
=
tensor
(
np
.
ones
(
1
,
dtype
=
np
.
float32
))
@
trace
(
capture_as_const
=
True
,
tensor
_shape
=
True
)
@
trace
(
capture_as_const
=
True
,
symbolic
_shape
=
True
)
def
f
():
(
b
,)
=
apply
(
ops
.
Broadcast
(),
a
,
tensor
([
1
,
10
],
dtype
=
np
.
int32
))
return
b
...
...
@@ -248,7 +248,7 @@ def test_optimize_for_inference_broadcast():
def
test_trace_cvt_bool
():
set_
tensor
_shape
(
True
)
set_
symbolic
_shape
(
True
)
x
=
tensor
([
0
],
dtype
=
np
.
int32
)
@
trace
(
symbolic
=
True
)
...
...
@@ -261,7 +261,7 @@ def test_trace_cvt_bool():
def
test_trace_reshape
():
for
symbolic
in
[
False
,
True
]:
set_
tensor
_shape
(
True
)
set_
symbolic
_shape
(
True
)
x1
=
tensor
(
np
.
random
.
randn
(
2
,
10
,
10
))
x2
=
tensor
(
np
.
random
.
randn
(
4
,
10
,
10
))
x3
=
tensor
(
np
.
random
.
randn
(
8
,
10
,
10
))
...
...
@@ -344,7 +344,7 @@ def test_raise_on_trace():
def
test_trace_broadcast
():
for
symbolic
in
[
False
,
True
]:
set_
tensor
_shape
(
True
)
set_
symbolic
_shape
(
True
)
x1
=
tensor
(
np
.
random
.
randn
(
3
,
1
,
1
))
x2
=
tensor
(
np
.
random
.
randn
(
1
,
4
,
1
))
x3
=
tensor
(
np
.
random
.
randn
(
1
,
1
,
5
))
...
...
@@ -382,7 +382,7 @@ def test_trace_nms():
def
test_trace_valid_broadcast
():
set_
tensor
_shape
(
True
)
set_
symbolic
_shape
(
True
)
x1
=
tensor
(
np
.
random
.
randn
(
1
,
1
))
x2
=
tensor
(
np
.
random
.
randn
(
1
,
2
))
shape
=
(
tensor
([
2
]),
tensor
([
2
]))
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录