Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleSlim
提交
7e3e14ae
P
PaddleSlim
项目概览
PaddlePaddle
/
PaddleSlim
大约 2 年 前同步成功
通知
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看板
未验证
提交
7e3e14ae
编写于
7月 29, 2022
作者:
Z
zhouzj
提交者:
GitHub
7月 29, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix the bug of pruning dw_conv. (#1311)
上级
419ffd3b
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
6 addition
and
9 deletion
+6
-9
paddleslim/prune/prune_worker.py
paddleslim/prune/prune_worker.py
+1
-4
paddleslim/prune/pruner.py
paddleslim/prune/pruner.py
+2
-2
tests/test_prune_walker.py
tests/test_prune_walker.py
+3
-3
未找到文件。
paddleslim/prune/prune_worker.py
浏览文件 @
7e3e14ae
...
...
@@ -522,7 +522,6 @@ class depthwise_conv2d(PruneWorker):
channel_axis
=
1
if
data_format
==
"NHWC"
:
channel_axis
=
3
if
var
==
_in_var
:
assert
pruned_axis
==
channel_axis
,
"The Input of conv2d can only be pruned at channel axis, but got {}"
.
format
(
pruned_axis
)
...
...
@@ -533,7 +532,6 @@ class depthwise_conv2d(PruneWorker):
"repeat"
:
repeat
}])
# kernel_number * groups will be pruned by reducing groups
self
.
append_pruned_vars
(
_filter
,
1
,
transforms
)
self
.
_visit_and_search
(
_filter
,
0
,
transforms
+
[{
"repeat"
:
repeat
}])
...
...
@@ -546,14 +544,13 @@ class depthwise_conv2d(PruneWorker):
}])
elif
var
==
_filter
:
assert
pruned_axis
==
0
,
"The filter of depthwise conv2d can only be pruned at axis 0."
self
.
append_pruned_vars
(
_filter
,
1
,
transforms
)
self
.
append_pruned_vars
(
_filter
,
0
,
transforms
)
self
.
_visit_and_search
(
_in_var
,
channel_axis
,
transforms
)
self
.
_visit_and_search
(
_out
,
channel_axis
,
transforms
)
elif
var
==
_out
:
assert
pruned_axis
==
channel_axis
,
"The Input of conv2d can only be pruned at channel axis, but got {}"
.
format
(
pruned_axis
)
self
.
append_pruned_vars
(
_filter
,
0
,
transforms
)
self
.
append_pruned_vars
(
_filter
,
1
,
transforms
)
self
.
_visit_and_search
(
_filter
,
0
,
transforms
)
# It will not pruning number of kernels in depthwise conv2d,
# so it is not neccesary to search succeed operators.
...
...
paddleslim/prune/pruner.py
浏览文件 @
7e3e14ae
...
...
@@ -117,7 +117,7 @@ class Pruner():
_groups
=
1
if
not
lazy
:
# update groups of conv2d
if
pruned_axis
==
1
:
if
pruned_axis
==
1
or
pruned_axis
==
0
:
for
op
in
param
.
outputs
():
if
op
.
type
()
in
[
"conv2d"
,
"conv2d_grad"
,
"depthwise_conv2d"
,
...
...
@@ -132,7 +132,7 @@ class Pruner():
f
"change groups of
{
op
.
type
()
}
(
{
param
.
name
()
}
) from
{
op
.
attr
(
'groups'
)
}
to
{
new_groups
}
;"
)
op
.
set_attr
(
"groups"
,
new_groups
)
if
_groups
==
1
:
origin_shape
=
copy
.
deepcopy
(
param
.
shape
())
if
param_shape_backup
is
not
None
:
param_shape_backup
[
param
.
name
()]
=
origin_shape
...
...
tests/test_prune_walker.py
浏览文件 @
7e3e14ae
...
...
@@ -473,9 +473,9 @@ class TestDepthwiseConv2d(TestPruneWorker):
def
set_cases
(
self
):
weight_var
=
self
.
graph
.
var
(
'conv1.w_0'
)
self
.
cases
.
append
((
self
.
in_var
,
1
,
{
'conv1.w_0'
:
[
0
,
1
]}))
self
.
cases
.
append
((
self
.
out_var
,
1
,
{
'conv1.w_0'
:
[
0
,
1
]}))
self
.
cases
.
append
((
weight_var
,
0
,
{
'conv1.w_0'
:
[
1
]}))
self
.
cases
.
append
((
self
.
in_var
,
1
,
{
'conv1.w_0'
:
[
0
]}))
self
.
cases
.
append
((
self
.
out_var
,
1
,
{
'conv1.w_0'
:
[
0
]}))
self
.
cases
.
append
((
weight_var
,
0
,
{
'conv1.w_0'
:
[
0
]}))
def
test_prune
(
self
):
self
.
check_in_out
()
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录