Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleSlim
提交
9f8f1a4e
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看板
未验证
提交
9f8f1a4e
编写于
6月 27, 2022
作者:
C
ceci3
提交者:
GitHub
6月 27, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix transformer prune reorder (#1194)
上级
b3499dc9
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
26 addition
and
5 deletion
+26
-5
paddleslim/auto_compression/auto_strategy.py
paddleslim/auto_compression/auto_strategy.py
+3
-2
paddleslim/auto_compression/transformer_pruner.py
paddleslim/auto_compression/transformer_pruner.py
+23
-3
未找到文件。
paddleslim/auto_compression/auto_strategy.py
浏览文件 @
9f8f1a4e
...
...
@@ -76,8 +76,9 @@ EXPERIENCE_STRATEGY_WITHOUT_LOSS = [
]
MAGIC_SPARSE_RATIO
=
0.75
### TODO: 0.02 threshold maybe not suitable, need to check
MAGIC_MAX_EMD_DISTANCE
=
0.02
MAGIC_MIN_EMD_DISTANCE
=
0.01
### NOTE: reduce magic data to choose quantization aware training.
MAGIC_MAX_EMD_DISTANCE
=
0.0002
#0.02
MAGIC_MIN_EMD_DISTANCE
=
0.0001
#0.01
DEFAULT_TRANSFORMER_STRATEGY
=
'prune_0.25_int8'
DEFAULT_STRATEGY
=
'origin_int8'
...
...
paddleslim/auto_compression/transformer_pruner.py
浏览文件 @
9f8f1a4e
...
...
@@ -204,6 +204,23 @@ def softmax_with_cross_entropy_op(block, logits, labels):
return
loss
,
softmax
def
kl_div_op
(
block
,
logits
,
labels
):
""" Insert kl_div op to program"""
global
global_idx
loss
=
block
.
create_var
(
name
=
'{}.kl_div_tmp_{}'
.
format
(
logits
.
name
,
global_idx
),
shape
=
logits
.
shape
,
dtype
=
logits
.
dtype
)
global_idx
+=
1
attrs
=
{
'reduction'
:
"mean"
}
### maybe take a long time use this attrs
inputs
=
{
'X'
:
logits
,
'Target'
:
labels
}
outputs
=
{
'Loss'
:
loss
}
block
.
append_op
(
type
=
'kldiv_loss'
,
inputs
=
inputs
,
outputs
=
outputs
,
attrs
=
attrs
)
return
loss
def
mean_op
(
block
,
inputs
,
axis
=
None
,
keepdim
=
False
):
""" Insert mean op to program"""
global
global_idx
...
...
@@ -331,9 +348,12 @@ class TransformerPruner:
dtype
=
label_info
[
'dtype'
],
persistable
=
False
)
labels
=
feed_op
(
block
,
feed_num
,
labels
)
ce_loss
,
probs
=
softmax_with_cross_entropy_op
(
if
label_info
[
'dtype'
]
==
np
.
float32
:
loss
=
kl_div_op
(
block
,
logits
=
logits
,
labels
=
labels
)
else
:
loss
,
probs
=
softmax_with_cross_entropy_op
(
block
,
logits
=
logits
,
labels
=
labels
)
loss
=
mean_op
(
block
,
ce_
loss
)
loss
=
mean_op
(
block
,
loss
)
program
.
_sync_with_cpp
()
paddle
.
static
.
append_backward
(
loss
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录