Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleSlim
提交
e19de504
P
PaddleSlim
项目概览
PaddlePaddle
/
PaddleSlim
大约 1 年 前同步成功
通知
51
Star
1434
Fork
344
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
53
列表
看板
标记
里程碑
合并请求
16
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleSlim
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
53
Issue
53
列表
看板
标记
里程碑
合并请求
16
合并请求
16
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
e19de504
编写于
5月 09, 2022
作者:
C
ceci3
提交者:
GitHub
5月 09, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
limit prune ratio in transformer pruner (#1087)
上级
dede4a80
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
22 addition
and
2 deletion
+22
-2
paddleslim/auto_compression/config_helpers.py
paddleslim/auto_compression/config_helpers.py
+3
-0
paddleslim/auto_compression/transformer_pruner.py
paddleslim/auto_compression/transformer_pruner.py
+19
-2
未找到文件。
paddleslim/auto_compression/config_helpers.py
浏览文件 @
e19de504
...
...
@@ -39,6 +39,9 @@ def load_config(config_path):
else
:
train_config
=
None
if
len
(
compress_config
)
==
0
:
compress_config
=
None
return
compress_config
,
train_config
...
...
paddleslim/auto_compression/transformer_pruner.py
浏览文件 @
e19de504
...
...
@@ -19,6 +19,7 @@ from ..core import GraphWrapper
from
..common
import
get_logger
from
..common.recover_program
import
recover_inference_program
from
..common.transformer_pattern
import
preprocess_transformer_patterns
from
..common.patterns_common
import
is_dynamic_weight_op
_logger
=
get_logger
(
__name__
,
level
=
logging
.
INFO
)
...
...
@@ -228,13 +229,21 @@ class TransformerPruner:
self
.
graph
=
GraphWrapper
(
inference_program
)
self
.
patterns
=
patterns
self
.
label_info
=
label_info
self
.
width_mult
=
width_mult
self
.
fetch_targets
=
fetch_targets
self
.
dataloader
=
dataloader
self
.
scope
=
paddle
.
static
.
global_scope
()
input_mask_op
,
layer_num
,
head_num
,
mha_weight
,
ffn_weight
=
self
.
_preprocess_patterns
(
patterns
,
self
.
graph
)
### the prune ratio * head_num need to be an integer.
pruned_head
=
round
(
width_mult
*
head_num
)
self
.
width_mult
=
float
(
pruned_head
)
/
head_num
if
self
.
width_mult
!=
width_mult
:
_logger
.
info
(
"the prune ratio * head_num need to be an integer. so change prune ratio from {} to {}"
.
format
(
str
(
1.0
-
width_mult
),
str
(
1.0
-
self
.
width_mult
)))
self
.
input_mask_op
=
input_mask_op
self
.
mha_weight
=
mha_weight
self
.
ffn_weight
=
ffn_weight
...
...
@@ -247,7 +256,15 @@ class TransformerPruner:
""" Preprocess pattern of the program, get some info need by reorder"""
input_mask_op
=
patterns
[
'input_mask'
]
layer_num
=
int
((
len
(
patterns
)
-
1
)
/
2
)
head_num
=
len
(
input_mask_op
.
input_arg_names
)
### get real head number
head_num
=
-
1
tmp_mha_ops
=
patterns
[
'MHA$0'
]
for
op
in
tmp_mha_ops
:
if
op
.
type
()
in
[
'matmul'
,
'matmul_v2'
]
and
(
not
is_dynamic_weight_op
(
op
))
and
head_num
==
-
1
:
inp_var
=
op
.
inputs
(
"X"
)
head_num
=
inp_var
[
0
].
shape
()[
1
]
mha_weight
,
ffn_weight
=
preprocess_transformer_patterns
(
patterns
,
graph
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录