Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
MegEngine 天元
MegEngine
提交
bd7f885a
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看板
提交
bd7f885a
编写于
9月 21, 2020
作者:
M
Megvii Engine Team
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix(mge/pytest): remove __init__ in py-test
GitOrigin-RevId: e16eae9cbcb4038bd1abbf4c6089d9cbb7cd4afc
上级
06041f8a
变更
10
显示空白变更内容
内联
并排
Showing
10 changed file
with
86 addition
and
214 deletion
+86
-214
imperative/python/test/conftest.py
imperative/python/test/conftest.py
+4
-0
imperative/python/test/helpers/utils.py
imperative/python/test/helpers/utils.py
+66
-0
imperative/python/test/run.sh
imperative/python/test/run.sh
+2
-2
imperative/python/test/unit/data/__init__.py
imperative/python/test/unit/data/__init__.py
+0
-0
imperative/python/test/unit/functional/__init__.py
imperative/python/test/unit/functional/__init__.py
+0
-8
imperative/python/test/unit/functional/test_functional.py
imperative/python/test/unit/functional/test_functional.py
+1
-62
imperative/python/test/unit/functional/test_functional_distributed.py
...ython/test/unit/functional/test_functional_distributed.py
+0
-0
imperative/python/test/unit/functional/test_math.py
imperative/python/test/unit/functional/test_math.py
+1
-66
imperative/python/test/unit/functional/test_tensor.py
imperative/python/test/unit/functional/test_tensor.py
+12
-76
imperative/python/test/unit/module/test_module_tensor.py
imperative/python/test/unit/module/test_module_tensor.py
+0
-0
未找到文件。
imperative/python/test/conftest.py
0 → 100644
浏览文件 @
bd7f885a
import
os
import
sys
sys
.
path
.
append
(
os
.
path
.
join
(
os
.
path
.
dirname
(
__file__
),
"helpers"
))
imperative/python/test/helpers/utils.py
0 → 100644
浏览文件 @
bd7f885a
import
numpy
as
np
from
megengine
import
tensor
def
_default_compare_fn
(
x
,
y
):
np
.
testing
.
assert_allclose
(
x
.
numpy
(),
y
,
rtol
=
1e-6
)
def
opr_test
(
cases
,
func
,
compare_fn
=
_default_compare_fn
,
ref_fn
=
None
,
**
kwargs
):
"""
:param cases: the list which have dict element, the list length should be 2 for dynamic shape test.
and the dict should have input,
and should have output if ref_fn is None.
should use list for multiple inputs and outputs for each case.
:param func: the function to run opr.
:param compare_fn: the function to compare the result and expected, use assertTensorClose if None.
:param ref_fn: the function to generate expected data, should assign output if None.
Examples:
.. code-block::
dtype = np.float32
cases = [{"input": [10, 20]}, {"input": [20, 30]}]
opr_test(cases,
F.eye,
ref_fn=lambda n, m: np.eye(n, m).astype(dtype),
dtype=dtype)
"""
def
check_results
(
results
,
expected
):
if
not
isinstance
(
results
,
(
tuple
,
list
)):
results
=
(
results
,)
for
r
,
e
in
zip
(
results
,
expected
):
compare_fn
(
r
,
e
)
def
get_param
(
cases
,
idx
):
case
=
cases
[
idx
]
inp
=
case
.
get
(
"input"
,
None
)
outp
=
case
.
get
(
"output"
,
None
)
if
inp
is
None
:
raise
ValueError
(
"the test case should have input"
)
if
not
isinstance
(
inp
,
(
tuple
,
list
)):
inp
=
(
inp
,)
if
ref_fn
is
not
None
and
callable
(
ref_fn
):
outp
=
ref_fn
(
*
inp
)
if
outp
is
None
:
raise
ValueError
(
"the test case should have output or reference function"
)
if
not
isinstance
(
outp
,
(
tuple
,
list
)):
outp
=
(
outp
,)
return
inp
,
outp
if
len
(
cases
)
==
0
:
raise
ValueError
(
"should give one case at least"
)
if
not
callable
(
func
):
raise
ValueError
(
"the input func should be callable"
)
inp
,
outp
=
get_param
(
cases
,
0
)
inp_tensor
=
[
tensor
(
inpi
)
for
inpi
in
inp
]
results
=
func
(
*
inp_tensor
,
**
kwargs
)
check_results
(
results
,
outp
)
imperative/python/test/run.sh
浏览文件 @
bd7f885a
...
@@ -13,9 +13,9 @@ else
...
@@ -13,9 +13,9 @@ else
fi
fi
pushd
$(
dirname
"
${
BASH_SOURCE
[0]
}
"
)
/..
>
/dev/null
pushd
$(
dirname
"
${
BASH_SOURCE
[0]
}
"
)
/..
>
/dev/null
PYTHONPATH
=
"."
PY_IGNORE_IMPORTMISMATCH
=
1
python3
-m
pytest
$test_dirs
-m
'not isolated_distributed'
PYTHONPATH
=
"."
python3
-m
pytest
$test_dirs
-m
'not isolated_distributed'
if
[[
"
$TEST_PLAT
"
==
cuda
]]
;
then
if
[[
"
$TEST_PLAT
"
==
cuda
]]
;
then
echo
"test GPU pytest now"
echo
"test GPU pytest now"
PYTHONPATH
=
"."
PY_IGNORE_IMPORTMISMATCH
=
1
python3
-m
pytest
$test_dirs
-m
'isolated_distributed'
PYTHONPATH
=
"."
python3
-m
pytest
$test_dirs
-m
'isolated_distributed'
fi
fi
popd
>
/dev/null
popd
>
/dev/null
imperative/python/test/unit/data/__init__.py
已删除
100644 → 0
浏览文件 @
06041f8a
imperative/python/test/unit/functional/__init__.py
已删除
100644 → 0
浏览文件 @
06041f8a
# -*- coding: utf-8 -*-
# MegEngine is Licensed under the Apache License, Version 2.0 (the "License")
#
# Copyright (c) 2014-2020 Megvii Inc. All rights reserved.
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT ARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
imperative/python/test/unit/functional/test_functional.py
浏览文件 @
bd7f885a
...
@@ -10,6 +10,7 @@ import itertools
...
@@ -10,6 +10,7 @@ import itertools
import
numpy
as
np
import
numpy
as
np
import
pytest
import
pytest
from
utils
import
opr_test
import
megengine.core.ops.builtin
as
builtin
import
megengine.core.ops.builtin
as
builtin
import
megengine.core.tensor.dtype
as
dtype
import
megengine.core.tensor.dtype
as
dtype
...
@@ -21,68 +22,6 @@ from megengine.core.tensor.utils import make_shape_tuple
...
@@ -21,68 +22,6 @@ from megengine.core.tensor.utils import make_shape_tuple
from
megengine.test
import
assertTensorClose
from
megengine.test
import
assertTensorClose
def
_default_compare_fn
(
x
,
y
):
assertTensorClose
(
x
.
numpy
(),
y
)
def
opr_test
(
cases
,
func
,
compare_fn
=
_default_compare_fn
,
ref_fn
=
None
,
**
kwargs
):
"""
func: the function to run opr.
compare_fn: the function to compare the result and expected, use assertTensorClose if None.
ref_fn: the function to generate expected data, should assign output if None.
cases: the list which have dict element, the list length should be 2 for dynamic shape test.
and the dict should have input,
and should have output if ref_fn is None.
should use list for multiple inputs and outputs for each case.
kwargs: The additional kwargs for opr func.
simple examples:
dtype = np.float32
cases = [{"input": [10, 20]}, {"input": [20, 30]}]
opr_test(cases,
F.eye,
ref_fn=lambda n, m: np.eye(n, m).astype(dtype),
dtype=dtype)
"""
def
check_results
(
results
,
expected
):
if
not
isinstance
(
results
,
(
tuple
,
list
)):
results
=
(
results
,)
for
r
,
e
in
zip
(
results
,
expected
):
compare_fn
(
r
,
e
)
def
get_param
(
cases
,
idx
):
case
=
cases
[
idx
]
inp
=
case
.
get
(
"input"
,
None
)
outp
=
case
.
get
(
"output"
,
None
)
if
inp
is
None
:
raise
ValueError
(
"the test case should have input"
)
if
not
isinstance
(
inp
,
(
tuple
,
list
)):
inp
=
(
inp
,)
if
ref_fn
is
not
None
and
callable
(
ref_fn
):
outp
=
ref_fn
(
*
inp
)
if
outp
is
None
:
raise
ValueError
(
"the test case should have output or reference function"
)
if
not
isinstance
(
outp
,
(
tuple
,
list
)):
outp
=
(
outp
,)
return
inp
,
outp
if
len
(
cases
)
==
0
:
raise
ValueError
(
"should give one case at least"
)
if
not
callable
(
func
):
raise
ValueError
(
"the input func should be callable"
)
inp
,
outp
=
get_param
(
cases
,
0
)
inp_tensor
=
[
tensor
(
inpi
)
for
inpi
in
inp
]
results
=
func
(
*
inp_tensor
,
**
kwargs
)
check_results
(
results
,
outp
)
def
test_where
():
def
test_where
():
maskv0
=
np
.
array
([[
1
,
0
],
[
0
,
1
]],
dtype
=
np
.
bool_
)
maskv0
=
np
.
array
([[
1
,
0
],
[
0
,
1
]],
dtype
=
np
.
bool_
)
xv0
=
np
.
array
([[
1
,
np
.
inf
],
[
np
.
nan
,
4
]],
dtype
=
np
.
float32
)
xv0
=
np
.
array
([[
1
,
np
.
inf
],
[
np
.
nan
,
4
]],
dtype
=
np
.
float32
)
...
...
imperative/python/test/unit/functional/test_distributed.py
→
imperative/python/test/unit/functional/test_
functional_
distributed.py
浏览文件 @
bd7f885a
文件已移动
imperative/python/test/unit/functional/test_math.py
浏览文件 @
bd7f885a
...
@@ -9,78 +9,13 @@
...
@@ -9,78 +9,13 @@
from
functools
import
partial
from
functools
import
partial
import
numpy
as
np
import
numpy
as
np
from
utils
import
opr_test
import
megengine.functional
as
F
import
megengine.functional
as
F
from
megengine
import
tensor
from
megengine
import
tensor
from
megengine.test
import
assertTensorClose
from
megengine.test
import
assertTensorClose
def
_default_compare_fn
(
x
,
y
):
assertTensorClose
(
x
.
numpy
(),
y
)
def
opr_test
(
cases
,
func
,
compare_fn
=
_default_compare_fn
,
ref_fn
=
None
,
**
kwargs
):
"""
func: the function to run opr.
compare_fn: the function to compare the result and expected, use assertTensorClose if None.
ref_fn: the function to generate expected data, should assign output if None.
cases: the list which have dict element, the list length should be 2 for dynamic shape test.
and the dict should have input,
and should have output if ref_fn is None.
should use list for multiple inputs and outputs for each case.
kwargs: The additional kwargs for opr func.
simple examples:
dtype = np.float32
cases = [{"input": [10, 20]}, {"input": [20, 30]}]
opr_test(cases,
F.eye,
ref_fn=lambda n, m: np.eye(n, m).astype(dtype),
dtype=dtype)
"""
def
check_results
(
results
,
expected
):
if
not
isinstance
(
results
,
tuple
):
results
=
(
results
,)
for
r
,
e
in
zip
(
results
,
expected
):
compare_fn
(
r
,
e
)
def
get_param
(
cases
,
idx
):
case
=
cases
[
idx
]
inp
=
case
.
get
(
"input"
,
None
)
outp
=
case
.
get
(
"output"
,
None
)
if
inp
is
None
:
raise
ValueError
(
"the test case should have input"
)
if
not
isinstance
(
inp
,
list
):
inp
=
(
inp
,)
else
:
inp
=
tuple
(
inp
)
if
ref_fn
is
not
None
and
callable
(
ref_fn
):
outp
=
ref_fn
(
*
inp
)
if
outp
is
None
:
raise
ValueError
(
"the test case should have output or reference function"
)
if
not
isinstance
(
outp
,
list
):
outp
=
(
outp
,)
else
:
outp
=
tuple
(
outp
)
return
inp
,
outp
if
len
(
cases
)
==
0
:
raise
ValueError
(
"should give one case at least"
)
if
not
callable
(
func
):
raise
ValueError
(
"the input func should be callable"
)
inp
,
outp
=
get_param
(
cases
,
0
)
inp_tensor
=
[
tensor
(
inpi
)
for
inpi
in
inp
]
results
=
func
(
*
inp_tensor
,
**
kwargs
)
check_results
(
results
,
outp
)
def
common_test_reduce
(
opr
,
ref_opr
):
def
common_test_reduce
(
opr
,
ref_opr
):
data1_shape
=
(
5
,
6
,
7
)
data1_shape
=
(
5
,
6
,
7
)
data2_shape
=
(
2
,
9
,
12
)
data2_shape
=
(
2
,
9
,
12
)
...
...
imperative/python/test/unit/functional/test_tensor.py
浏览文件 @
bd7f885a
...
@@ -6,10 +6,12 @@
...
@@ -6,10 +6,12 @@
# Unless required by applicable law or agreed to in writing,
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT ARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# "AS IS" BASIS, WITHOUT ARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
import
os
import
platform
import
platform
import
numpy
as
np
import
numpy
as
np
import
pytest
import
pytest
from
utils
import
opr_test
import
megengine.functional
as
F
import
megengine.functional
as
F
from
megengine
import
tensor
from
megengine
import
tensor
...
@@ -19,72 +21,6 @@ from megengine.distributed.helper import get_device_count_by_fork
...
@@ -19,72 +21,6 @@ from megengine.distributed.helper import get_device_count_by_fork
from
megengine.test
import
assertTensorClose
from
megengine.test
import
assertTensorClose
def
_default_compare_fn
(
x
,
y
):
assertTensorClose
(
x
.
numpy
(),
y
)
def
opr_test
(
cases
,
func
,
compare_fn
=
_default_compare_fn
,
ref_fn
=
None
,
**
kwargs
):
"""
func: the function to run opr.
compare_fn: the function to compare the result and expected, use assertTensorClose if None.
ref_fn: the function to generate expected data, should assign output if None.
cases: the list which have dict element, the list length should be 2 for dynamic shape test.
and the dict should have input,
and should have output if ref_fn is None.
should use list for multiple inputs and outputs for each case.
kwargs: The additional kwargs for opr func.
simple examples:
dtype = np.float32
cases = [{"input": [10, 20]}, {"input": [20, 30]}]
opr_test(cases,
F.eye,
ref_fn=lambda n, m: np.eye(n, m).astype(dtype),
dtype=dtype)
"""
def
check_results
(
results
,
expected
):
if
not
isinstance
(
results
,
tuple
):
results
=
(
results
,)
for
r
,
e
in
zip
(
results
,
expected
):
compare_fn
(
r
,
e
)
def
get_param
(
cases
,
idx
):
case
=
cases
[
idx
]
inp
=
case
.
get
(
"input"
,
None
)
outp
=
case
.
get
(
"output"
,
None
)
if
inp
is
None
:
raise
ValueError
(
"the test case should have input"
)
if
not
isinstance
(
inp
,
list
):
inp
=
(
inp
,)
else
:
inp
=
tuple
(
inp
)
if
ref_fn
is
not
None
and
callable
(
ref_fn
):
outp
=
ref_fn
(
*
inp
)
if
outp
is
None
:
raise
ValueError
(
"the test case should have output or reference function"
)
if
not
isinstance
(
outp
,
list
):
outp
=
(
outp
,)
else
:
outp
=
tuple
(
outp
)
return
inp
,
outp
if
len
(
cases
)
==
0
:
raise
ValueError
(
"should give one case at least"
)
if
not
callable
(
func
):
raise
ValueError
(
"the input func should be callable"
)
inp
,
outp
=
get_param
(
cases
,
0
)
inp_tensor
=
[
tensor
(
inpi
)
for
inpi
in
inp
]
results
=
func
(
*
inp_tensor
,
**
kwargs
)
check_results
(
results
,
outp
)
def
test_eye
():
def
test_eye
():
dtype
=
np
.
float32
dtype
=
np
.
float32
cases
=
[{
"input"
:
[
10
,
20
]},
{
"input"
:
[
20
,
30
]}]
cases
=
[{
"input"
:
[
10
,
20
]},
{
"input"
:
[
20
,
30
]}]
...
@@ -265,37 +201,37 @@ def test_flatten():
...
@@ -265,37 +201,37 @@ def test_flatten():
data1
=
np
.
random
.
random
(
data1_shape
).
astype
(
np
.
float32
)
data1
=
np
.
random
.
random
(
data1_shape
).
astype
(
np
.
float32
)
def
compare_fn
(
x
,
y
):
def
compare_fn
(
x
,
y
):
assert
x
.
numpy
().
shape
==
y
[
0
]
assert
x
.
shape
[
0
]
==
y
output0
=
(
2
*
3
*
4
*
5
,)
output0
=
(
2
*
3
*
4
*
5
,)
output1
=
(
4
*
5
*
6
*
7
,)
output1
=
(
4
*
5
*
6
*
7
,)
cases
=
[
cases
=
[
{
"input"
:
data0
,
"output"
:
(
output0
,)
},
{
"input"
:
data0
,
"output"
:
output0
},
{
"input"
:
data1
,
"output"
:
(
output1
,)
},
{
"input"
:
data1
,
"output"
:
output1
},
]
]
opr_test
(
cases
,
F
.
flatten
,
compare_fn
=
compare_fn
)
opr_test
(
cases
,
F
.
flatten
,
compare_fn
=
compare_fn
)
output0
=
(
2
,
3
*
4
*
5
)
output0
=
(
2
,
3
*
4
*
5
)
output1
=
(
4
,
5
*
6
*
7
)
output1
=
(
4
,
5
*
6
*
7
)
cases
=
[
cases
=
[
{
"input"
:
data0
,
"output"
:
(
output0
,)
},
{
"input"
:
data0
,
"output"
:
output0
},
{
"input"
:
data1
,
"output"
:
(
output1
,)
},
{
"input"
:
data1
,
"output"
:
output1
},
]
]
opr_test
(
cases
,
F
.
flatten
,
compare_fn
=
compare_fn
,
start_axis
=
1
)
opr_test
(
cases
,
F
.
flatten
,
compare_fn
=
compare_fn
,
start_axis
=
1
)
output0
=
(
2
,
3
,
4
*
5
)
output0
=
(
2
,
3
,
4
*
5
)
output1
=
(
4
,
5
,
6
*
7
)
output1
=
(
4
,
5
,
6
*
7
)
cases
=
[
cases
=
[
{
"input"
:
data0
,
"output"
:
(
output0
,)
},
{
"input"
:
data0
,
"output"
:
output0
},
{
"input"
:
data1
,
"output"
:
(
output1
,)
},
{
"input"
:
data1
,
"output"
:
output1
},
]
]
opr_test
(
cases
,
F
.
flatten
,
compare_fn
=
compare_fn
,
start_axis
=
2
)
opr_test
(
cases
,
F
.
flatten
,
compare_fn
=
compare_fn
,
start_axis
=
2
)
output0
=
(
2
,
3
*
4
,
5
)
output0
=
(
2
,
3
*
4
,
5
)
output1
=
(
4
,
5
*
6
,
7
)
output1
=
(
4
,
5
*
6
,
7
)
cases
=
[
cases
=
[
{
"input"
:
data0
,
"output"
:
(
output0
,)
},
{
"input"
:
data0
,
"output"
:
output0
},
{
"input"
:
data1
,
"output"
:
(
output1
,)
},
{
"input"
:
data1
,
"output"
:
output1
},
]
]
opr_test
(
cases
,
F
.
flatten
,
compare_fn
=
compare_fn
,
start_axis
=
1
,
end_axis
=
2
)
opr_test
(
cases
,
F
.
flatten
,
compare_fn
=
compare_fn
,
start_axis
=
1
,
end_axis
=
2
)
...
@@ -310,7 +246,7 @@ def test_broadcast():
...
@@ -310,7 +246,7 @@ def test_broadcast():
data2
=
np
.
random
.
random
(
input2_shape
).
astype
(
np
.
float32
)
data2
=
np
.
random
.
random
(
input2_shape
).
astype
(
np
.
float32
)
def
compare_fn
(
x
,
y
):
def
compare_fn
(
x
,
y
):
assert
x
.
numpy
().
shape
==
y
assert
x
.
shape
[
0
]
==
y
cases
=
[
cases
=
[
{
"input"
:
[
data1
,
output1_shape
],
"output"
:
output1_shape
},
{
"input"
:
[
data1
,
output1_shape
],
"output"
:
output1_shape
},
...
...
imperative/python/test/unit/module/test_tensor.py
→
imperative/python/test/unit/module/test_
module_
tensor.py
浏览文件 @
bd7f885a
文件已移动
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录