Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
MegEngine 天元
MegEngine
提交
82b0f677
MegEngine
项目概览
MegEngine 天元
/
MegEngine
9 个月 前同步成功
通知
392
Star
4702
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看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
82b0f677
编写于
11月 16, 2020
作者:
M
Megvii Engine Team
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix(mge/core): fix dtype promotion issue for quantized dtype
GitOrigin-RevId: 9d09c8fa6f355b3c84ba4b9ec7872c1a21393726
上级
8118a594
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
19 addition
and
8 deletion
+19
-8
imperative/python/megengine/core/tensor/utils.py
imperative/python/megengine/core/tensor/utils.py
+2
-2
imperative/python/megengine/module/module.py
imperative/python/megengine/module/module.py
+1
-6
imperative/python/test/unit/functional/test_elemwise.py
imperative/python/test/unit/functional/test_elemwise.py
+16
-0
未找到文件。
imperative/python/megengine/core/tensor/utils.py
浏览文件 @
82b0f677
...
...
@@ -14,7 +14,7 @@ import numpy as np
from
..ops
import
builtin
from
..ops.special
import
Const
from
..tensor.core
import
OpBase
,
TensorBase
,
TensorWrapperBase
,
apply
from
.dtype
import
is_equal
from
.dtype
import
is_equal
,
is_quantize
def
dtype_promotion
(
inputs
):
...
...
@@ -122,7 +122,7 @@ def convert_single_value(v, inputs, *, dtype=None, device=None):
tensors
=
[
i
for
i
in
inputs
if
isinstance
(
i
,
(
TensorBase
,
TensorWrapperBase
))]
assert
len
(
tensors
)
>
0
if
isinstance
(
v
,
(
TensorWrapperBase
,
TensorBase
)):
v
=
astype
(
v
,
dtype
)
v
=
astype
(
v
,
v
.
dtype
if
is_quantize
(
v
.
dtype
)
else
dtype
)
else
:
(
v
,)
=
Const
(
v
,
dtype
=
dtype
,
device
=
device
)(
*
tensors
)
return
v
...
...
imperative/python/megengine/module/module.py
浏览文件 @
82b0f677
...
...
@@ -12,7 +12,6 @@ from typing import Any, Callable, Iterable, Optional, Set, Tuple, Union
import
numpy
as
np
from
..core.tensor.dtype
import
is_quantize
from
..core.tensor.utils
import
make_shape_tuple
from
..logger
import
get_logger
from
..tensor
import
Parameter
,
Tensor
...
...
@@ -529,11 +528,7 @@ class Module(metaclass=ABCMeta):
),
"param `{}` shape mismatch, should be {}, get {}"
.
format
(
k
,
var
.
shape
,
to_be_load
.
shape
)
# For quantized dtype, the initialized dtype
# scale/zero_points maybe invalid, use pretrained dtype instead.
if
is_quantize
(
to_be_load
.
dtype
)
and
is_quantize
(
var
.
dtype
):
var
=
var
.
astype
(
to_be_load
.
dtype
)
var
.
_reset
(
to_be_load
)
var
.
_reset
(
type
(
var
)(
to_be_load
,
dtype
=
to_be_load
.
dtype
,
device
=
var
.
device
))
loaded
.
append
(
k
)
return
set
(
loaded
),
set
(
skipped
)
...
...
imperative/python/test/unit/functional/test_elemwise.py
浏览文件 @
82b0f677
...
...
@@ -10,6 +10,7 @@ import numpy as np
import
megengine.functional
as
F
from
megengine
import
tensor
from
megengine.core.tensor
import
dtype
from
megengine.functional.elemwise
import
_elwise
...
...
@@ -150,3 +151,18 @@ def test_logical_oprs():
np
.
testing
.
assert_equal
(
x
&
y
,
F
.
logical_and
(
xx
,
yy
).
numpy
())
np
.
testing
.
assert_equal
(
x
|
y
,
F
.
logical_or
(
xx
,
yy
).
numpy
())
np
.
testing
.
assert_equal
(
x
^
y
,
F
.
logical_xor
(
xx
,
yy
).
numpy
())
def
test_qadd
():
inp_scale
=
0.5
outp_scale
=
0.2
x
=
np
.
arange
(
6
).
reshape
(
2
,
3
).
astype
(
"float32"
)
y
=
np
.
arange
(
6
).
reshape
(
2
,
3
).
astype
(
"float32"
)
x
=
tensor
(
x
,
dtype
=
dtype
.
qint8
(
inp_scale
))
y
=
tensor
(
y
,
dtype
=
dtype
.
qint8
(
inp_scale
))
result_mge
=
F
.
elemwise
.
_elemwise_multi_type
(
x
,
y
,
mode
=
"QADD"
,
dtype
=
dtype
.
qint8
(
outp_scale
)
)
result_mge
=
result_mge
.
astype
(
"float32"
).
numpy
()
result_expect
=
x
.
astype
(
"float32"
).
numpy
()
+
y
.
astype
(
"float32"
).
numpy
()
np
.
testing
.
assert_almost_equal
(
result_mge
,
result_expect
,
decimal
=
6
)
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录