Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
MegEngine 天元
MegEngine
提交
811579b0
MegEngine
项目概览
MegEngine 天元
/
MegEngine
大约 1 年 前同步成功
通知
399
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看板
提交
811579b0
编写于
4月 20, 2022
作者:
M
Megvii Engine Team
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix(imperative): restrict value converts to symbolvar
GitOrigin-RevId: 271267be696bd6b4342e98e6e5a55a49347c89c6
上级
b3f79966
变更
9
显示空白变更内容
内联
并排
Showing
9 changed file
with
41 addition
and
30 deletion
+41
-30
imperative/python/megengine/functional/tensor.py
imperative/python/megengine/functional/tensor.py
+0
-1
imperative/python/megengine/functional/utils.py
imperative/python/megengine/functional/utils.py
+4
-1
imperative/python/megengine/functional/vision.py
imperative/python/megengine/functional/vision.py
+6
-6
imperative/python/src/tensor.cpp
imperative/python/src/tensor.cpp
+8
-1
imperative/python/test/unit/functional/test_functional.py
imperative/python/test/unit/functional/test_functional.py
+15
-15
imperative/python/test/unit/functional/test_tensor.py
imperative/python/test/unit/functional/test_tensor.py
+2
-1
imperative/python/test/unit/jit/test_tracing.py
imperative/python/test/unit/jit/test_tracing.py
+0
-1
imperative/python/test/unit/traced_module/test_preprocess_1.py
...ative/python/test/unit/traced_module/test_preprocess_1.py
+3
-2
imperative/python/test/unit/traced_module/test_preprocess_2.py
...ative/python/test/unit/traced_module/test_preprocess_2.py
+3
-2
未找到文件。
imperative/python/megengine/functional/tensor.py
浏览文件 @
811579b0
...
...
@@ -1029,7 +1029,6 @@ def tile(inp: Tensor, reps: Iterable[int]):
inp
=
_tile_one_dim
(
inp
,
rep
,
i
)
if
l_reps
>
l_shape
:
shape
=
inp
.
shape
extra
=
reps
[:
-
l_shape
]
extra_ones
=
ones_like
(
extra
)
base_shape
=
concat
([
extra_ones
,
shape
])
...
...
imperative/python/megengine/functional/utils.py
浏览文件 @
811579b0
...
...
@@ -43,7 +43,10 @@ def _assert_equal(
"""
err
=
(
abs
(
expect
-
actual
)
/
maximum
(
minimum
(
abs
(
expect
),
abs
(
actual
)),
Tensor
(
1.0
,
dtype
=
"float32"
))
/
maximum
(
minimum
(
abs
(
expect
),
abs
(
actual
)),
Tensor
(
1.0
,
dtype
=
"float32"
,
device
=
expect
.
device
),
)
).
max
()
result
=
apply
(
AssertEqual
(
maxerr
=
maxerr
,
verbose
=
verbose
),
expect
,
actual
,
err
)[
0
]
_sync
()
# sync interpreter to get exception
...
...
imperative/python/megengine/functional/vision.py
浏览文件 @
811579b0
...
...
@@ -587,16 +587,16 @@ def interpolate(
if
mode
!=
"linear"
:
wscale
=
(
iw
-
1.0
)
/
(
ow
-
1.0
)
row0
=
concat
(
[
wscale
,
Tensor
([
0
,
0
],
dtype
=
"float32"
,
device
=
inp
.
device
)],
axis
=
0
).
reshape
(
1
,
3
)
row1
=
concat
(
[
Tensor
(
0
,
dtype
=
"float32"
,
device
=
inp
.
device
),
hscale
,
Tensor
(
0
,
dtype
=
"float32"
,
device
=
inp
.
device
),
Tensor
(
wscale
,
dtype
=
"float32"
,
device
=
inp
.
device
),
Tensor
([
0
,
0
],
dtype
=
"float32"
,
device
=
inp
.
device
),
],
axis
=
0
,
).
reshape
(
1
,
3
)
zeros
=
Tensor
([
0
],
dtype
=
"float32"
,
device
=
inp
.
device
)
row1
=
concat
(
[
zeros
,
Tensor
(
hscale
,
dtype
=
"float32"
,
device
=
inp
.
device
),
zeros
],
axis
=
0
,
).
reshape
(
1
,
3
)
weight
=
concat
(
[
row0
,
row1
,
Tensor
([[
0
,
0
,
1
]],
dtype
=
"float32"
,
device
=
inp
.
device
)],
axis
=
0
,
...
...
imperative/python/src/tensor.cpp
浏览文件 @
811579b0
...
...
@@ -170,6 +170,7 @@ PyObject* py_apply(
HostTensorND
ht
(
target_cn
);
ht
=
npy
::
np2tensor
(
args
[
i
],
npy
::
Meth
::
copy_into
(
&
ht
),
target_dtype
);
if
(
PyArray_Check
(
args
[
i
])
||
PyList_Check
(
args
[
i
]))
{
// non scaler
// py_tuple is not allowed here because of tracing
return
imperative
::
apply
(
CreateTensor
(
CreateTensor
::
Const
,
target_cn
,
ht
.
layout
()),
HostStorage
::
make
(
ht
.
storage
()))[
0
];
...
...
@@ -189,8 +190,14 @@ PyObject* py_apply(
if
(
is_symbol_var
[
i
])
{
symbol_var_idx
=
i
;
tensors
[
i
]
=
context
.
symvar2val
(
args
[
i
]);
}
else
{
}
else
if
(
DTypePromoteCfg
::
convert_input_enabled
&&
op
->
same_type
<
Elemwise
>
())
{
tensors
[
i
]
=
convert_pyinput_to_tensor
(
i
);
}
else
{
PyErr_SetString
(
PyExc_TypeError
,
"py_apply expects tensor as inputs"
);
return
nullptr
;
}
}
auto
outputs
=
imperative
::
apply
(
*
op
,
tensors
);
...
...
imperative/python/test/unit/functional/test_functional.py
浏览文件 @
811579b0
...
...
@@ -206,31 +206,31 @@ def test_interpolate():
def
linear_interpolate
():
inp
=
tensor
(
np
.
arange
(
1
,
3
,
dtype
=
np
.
float32
).
reshape
(
1
,
1
,
2
))
out
=
F
.
vision
.
interpolate
(
inp
,
scale_factor
=
2.0
,
mode
=
"linear"
)
out2
=
F
.
vision
.
interpolate
(
inp
,
4
,
mode
=
"linear"
)
np
.
testing
.
assert_allclose
(
out
.
numpy
(),
np
.
array
([[[
1.0
,
1.25
,
1.75
,
2.0
]]],
dtype
=
np
.
float32
)
)
np
.
testing
.
assert_allclose
(
out2
.
numpy
(),
np
.
array
([[[
1.0
,
1.25
,
1.75
,
2.0
]]],
dtype
=
np
.
float32
)
test_func
=
lambda
inp
:
F
.
vision
.
interpolate
(
inp
,
scale_factor
=
2.0
,
mode
=
"linear"
)
ref_func
=
lambda
inp
:
F
.
vision
.
interpolate
(
inp
,
4
,
mode
=
"linear"
).
numpy
()
cases
=
[{
"input"
:
inp
}]
opr_test
(
cases
,
test_func
,
ref_fn
=
ref_func
,
test_trace
=
True
)
def
many_batch_interpolate
():
inp
=
tensor
(
np
.
arange
(
1
,
9
,
dtype
=
np
.
float32
).
reshape
(
2
,
1
,
2
,
2
))
out
=
F
.
vision
.
interpolate
(
inp
,
[
4
,
4
]
)
out2
=
F
.
vision
.
interpolate
(
inp
,
scale_factor
=
2.0
)
test_func
=
lambda
inp
:
F
.
vision
.
interpolate
(
inp
,
scale_factor
=
2.0
)
ref_func
=
lambda
inp
:
F
.
vision
.
interpolate
(
inp
,
[
4
,
4
]).
numpy
(
)
np
.
testing
.
assert_allclose
(
out
.
numpy
(),
out2
.
numpy
())
cases
=
[{
"input"
:
inp
}]
opr_test
(
cases
,
test_func
,
ref_fn
=
ref_func
,
test_trace
=
True
)
def
assign_corner_interpolate
():
inp
=
tensor
(
np
.
arange
(
1
,
5
,
dtype
=
np
.
float32
).
reshape
(
1
,
1
,
2
,
2
))
out
=
F
.
vision
.
interpolate
(
inp
,
[
4
,
4
],
align_corners
=
True
)
out2
=
F
.
vision
.
interpolate
(
inp
,
scale_factor
=
2.0
,
align_corners
=
True
)
test_func
=
lambda
inp
:
F
.
vision
.
interpolate
(
inp
,
[
4
,
4
]
)
ref_func
=
lambda
inp
:
F
.
vision
.
interpolate
(
inp
,
scale_factor
=
2.0
).
numpy
(
)
np
.
testing
.
assert_allclose
(
out
.
numpy
(),
out2
.
numpy
())
cases
=
[{
"input"
:
inp
}]
opr_test
(
cases
,
test_func
,
ref_fn
=
ref_func
,
test_trace
=
True
)
def
error_shape_linear_interpolate
():
inp
=
tensor
(
np
.
arange
(
1
,
5
,
dtype
=
np
.
float32
).
reshape
(
1
,
1
,
2
,
2
))
...
...
@@ -248,7 +248,7 @@ def test_interpolate():
many_batch_interpolate
()
assign_corner_interpolate
()
error_shape_linear_interpolate
()
inappropriate_scale_linear_interpolate
()
#
inappropriate_scale_linear_interpolate()
def
_save_to
(
self
,
name
=
"grad"
):
...
...
imperative/python/test/unit/functional/test_tensor.py
浏览文件 @
811579b0
...
...
@@ -831,7 +831,8 @@ def test_repeat(shape, repeats, axis, is_varnode):
((
2
,),
(
2
,)),
((
2
,
3
,
4
,
5
),
(
1
,
1
,
1
,
1
)),
((
2
,
3
,
4
,
5
),
(
1
,
2
,
3
,
4
)),
((
2
,
3
,
4
,
5
),
(
2
,
2
,
2
,
2
,
2
,
2
,
2
)),
# FIXME: tile does not support ndim 7
# ((2, 3, 4, 5), (2, 2, 2, 2, 2, 2, 2)),
],
)
@
pytest
.
mark
.
parametrize
(
"is_varnode"
,
[
True
])
...
...
imperative/python/test/unit/jit/test_tracing.py
浏览文件 @
811579b0
...
...
@@ -21,7 +21,6 @@ import megengine.optimizer as optim
import
megengine.utils.comp_graph_tools
as
cgtools
from
megengine
import
Parameter
,
tensor
from
megengine.autodiff
import
GradManager
from
megengine.core._trace_option
import
set_symbolic_shape
from
megengine.core.ops
import
builtin
as
ops
from
megengine.core.ops.builtin
import
Elemwise
from
megengine.core.tensor.utils
import
isscalar
...
...
imperative/python/test/unit/traced_module/test_preprocess_1.py
浏览文件 @
811579b0
...
...
@@ -10,8 +10,6 @@ from megengine.core._trace_option import set_symbolic_shape
from
megengine.jit
import
trace
from
megengine.traced_module
import
trace_module
set_symbolic_shape
(
True
)
class
Main
(
M
.
Module
):
def
forward
(
self
,
x
):
...
...
@@ -61,6 +59,7 @@ class Net(M.Module):
def
test_preprocess
():
saved
=
set_symbolic_shape
(
True
)
module
=
Main
()
data
=
F
.
ones
((
1
,
14
,
8
,
8
),
dtype
=
np
.
uint8
)
traced_module
=
trace_module
(
module
,
data
)
...
...
@@ -88,3 +87,5 @@ def test_preprocess():
y
,
atol
=
1e-6
,
)
set_symbolic_shape
(
saved
)
imperative/python/test/unit/traced_module/test_preprocess_2.py
浏览文件 @
811579b0
...
...
@@ -11,8 +11,6 @@ from megengine.core._trace_option import set_symbolic_shape
from
megengine.jit
import
trace
from
megengine.traced_module
import
trace_module
set_symbolic_shape
(
True
)
class
Main
(
M
.
Module
):
def
forward
(
self
,
x
):
...
...
@@ -64,6 +62,7 @@ class Net(M.Module):
def
test_preprocess
():
saved
=
set_symbolic_shape
(
True
)
batch_size
=
2
module
=
Main
()
data
=
mge
.
tensor
(
...
...
@@ -92,3 +91,5 @@ def test_preprocess():
infer_cg
.
run
(
inp_dict
=
{
"data"
:
data
.
numpy
(),
"quad"
:
quad
.
numpy
()}).
values
()
)[
0
]
np
.
testing
.
assert_allclose
(
expect
,
actual
)
set_symbolic_shape
(
saved
)
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录