Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
慢慢CG
Mace
提交
92f6d362
Mace
项目概览
慢慢CG
/
Mace
与 Fork 源项目一致
Fork自
Xiaomi / Mace
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
Mace
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
92f6d362
编写于
11月 29, 2018
作者:
Y
yulianfei
提交者:
liukai6
4月 25, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add FP16_GATHER_WEIGHT
上级
00febe43
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
59 addition
and
0 deletion
+59
-0
mace/ops/cast.cc
mace/ops/cast.cc
+8
-0
mace/ops/gather.cc
mace/ops/gather.cc
+4
-0
mace/python/tools/converter_tool/base_converter.py
mace/python/tools/converter_tool/base_converter.py
+1
-0
mace/python/tools/converter_tool/transformer.py
mace/python/tools/converter_tool/transformer.py
+46
-0
未找到文件。
mace/ops/cast.cc
浏览文件 @
92f6d362
...
@@ -14,6 +14,10 @@
...
@@ -14,6 +14,10 @@
#include "mace/core/operator.h"
#include "mace/core/operator.h"
#if defined(MACE_ENABLE_NEON) && defined(__ANDROID__)
#include <arm_neon.h>
#endif
namespace
mace
{
namespace
mace
{
namespace
ops
{
namespace
ops
{
...
@@ -55,6 +59,10 @@ void RegisterCast(OpRegistryBase *op_registry) {
...
@@ -55,6 +59,10 @@ void RegisterCast(OpRegistryBase *op_registry) {
DeviceType
::
CPU
,
float
);
DeviceType
::
CPU
,
float
);
MACE_REGISTER_OP
(
op_registry
,
"Cast"
,
CastOp
,
MACE_REGISTER_OP
(
op_registry
,
"Cast"
,
CastOp
,
DeviceType
::
CPU
,
int32_t
);
DeviceType
::
CPU
,
int32_t
);
#if defined(MACE_ENABLE_NEON) && defined(__ANDROID__)
MACE_REGISTER_OP
(
op_registry
,
"Cast"
,
CastOp
,
DeviceType
::
CPU
,
float16_t
);
#endif
}
}
}
// namespace ops
}
// namespace ops
...
...
mace/ops/gather.cc
浏览文件 @
92f6d362
...
@@ -93,6 +93,10 @@ void RegisterGather(OpRegistryBase *op_registry) {
...
@@ -93,6 +93,10 @@ void RegisterGather(OpRegistryBase *op_registry) {
MACE_REGISTER_OP
(
op_registry
,
"Gather"
,
GatherOp
,
MACE_REGISTER_OP
(
op_registry
,
"Gather"
,
GatherOp
,
DeviceType
::
CPU
,
uint8_t
);
DeviceType
::
CPU
,
uint8_t
);
#endif // MACE_ENABLE_QUANTIZE
#endif // MACE_ENABLE_QUANTIZE
#if defined(MACE_ENABLE_NEON) && defined(__ANDROID__)
MACE_REGISTER_OP
(
op_registry
,
"Gather"
,
GatherOp
,
DeviceType
::
CPU
,
float16_t
);
#endif
}
}
}
// namespace ops
}
// namespace ops
...
...
mace/python/tools/converter_tool/base_converter.py
浏览文件 @
92f6d362
...
@@ -315,6 +315,7 @@ class TransformerRule(Enum):
...
@@ -315,6 +315,7 @@ class TransformerRule(Enum):
UPDATE_DATA_FORMAT
=
39
UPDATE_DATA_FORMAT
=
39
QUANTIZE_SPECIFIC_OPS_ONLY
=
40
QUANTIZE_SPECIFIC_OPS_ONLY
=
40
FP16_MATMUL_WEIGHT
=
41
FP16_MATMUL_WEIGHT
=
41
FP16_GATHER_WEIGHT
=
42
class
ConverterInterface
(
object
):
class
ConverterInterface
(
object
):
...
...
mace/python/tools/converter_tool/transformer.py
浏览文件 @
92f6d362
...
@@ -108,6 +108,8 @@ class Transformer(base_converter.ConverterInterface):
...
@@ -108,6 +108,8 @@ class Transformer(base_converter.ConverterInterface):
self
.
quantize_specific_ops_only
,
self
.
quantize_specific_ops_only
,
TransformerRule
.
FP16_MATMUL_WEIGHT
:
TransformerRule
.
FP16_MATMUL_WEIGHT
:
self
.
fp16_matmul_weight
,
self
.
fp16_matmul_weight
,
TransformerRule
.
FP16_GATHER_WEIGHT
:
self
.
fp16_gather_weight
,
}
}
self
.
_option
=
option
self
.
_option
=
option
...
@@ -1855,6 +1857,50 @@ class Transformer(base_converter.ConverterInterface):
...
@@ -1855,6 +1857,50 @@ class Transformer(base_converter.ConverterInterface):
op
.
quantize_info
[
i
].
minval
,
op
.
quantize_info
[
i
].
minval
,
op
.
quantize_info
[
i
].
maxval
))
op
.
quantize_info
[
i
].
maxval
))
def
fp16_gather_weight
(
self
):
for
op
in
self
.
_model
.
op
:
if
op
.
type
!=
MaceOp
.
Gather
.
name
:
continue
if
op
.
input
[
0
]
not
in
self
.
_consts
:
raise
KeyError
(
"Not in const tensor: "
+
str
(
op
.
input
[
0
]))
const_tensor
=
self
.
_consts
[
op
.
input
[
0
]]
if
const_tensor
.
data_type
==
mace_pb2
.
DT_FLOAT16
:
print
(
str
(
const_tensor
.
name
)
+
" is alreay float16"
)
continue
print
(
"FP16 Embedding Lookup Weights: %s"
%
const_tensor
.
name
)
op_outputs
=
[
x
for
x
in
op
.
output
]
new_gather_name
=
op
.
name
+
'_fp16'
new_gather_output_name
=
new_gather_name
+
":0"
dehalve_name
=
op
.
name
# fp16 weights
const_tensor
.
data_type
=
mace_pb2
.
DT_FLOAT16
# change gather
op
.
name
=
new_gather_name
op
.
output
[:]
=
[
new_gather_output_name
]
# op.output.extend([new_gather_output_name])
data_type_arg
=
ConverterUtil
.
get_arg
(
op
,
MaceKeyword
.
mace_op_data_type_str
)
# noqa
if
data_type_arg
is
None
:
data_type_arg
=
op
.
arg
.
add
()
data_type_arg
.
name
=
MaceKeyword
.
mace_op_data_type_str
data_type_arg
.
i
=
mace_pb2
.
DT_FLOAT16
# add dehalve
dehalve_op
=
self
.
_model
.
op
.
add
()
dehalve_op
.
name
=
dehalve_name
dehalve_op
.
type
=
MaceOp
.
Cast
.
name
dehalve_op
.
input
.
extend
([
new_gather_output_name
])
dehalve_op
.
output
.
extend
(
op_outputs
)
dehalve_op
.
output_shape
.
extend
(
op
.
output_shape
)
dehalve_op
.
output_type
.
extend
([
mace_pb2
.
DT_FLOAT
])
data_type_arg
=
dehalve_op
.
arg
.
add
()
data_type_arg
.
name
=
MaceKeyword
.
mace_op_data_type_str
data_type_arg
.
i
=
mace_pb2
.
DT_FLOAT16
def
fp16_matmul_weight
(
self
):
def
fp16_matmul_weight
(
self
):
if
self
.
_option
.
device
!=
DeviceType
.
CPU
.
value
:
if
self
.
_option
.
device
!=
DeviceType
.
CPU
.
value
:
return
return
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录