Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleSlim
提交
2b780c77
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看板
未验证
提交
2b780c77
编写于
3年前
作者:
W
whs
提交者:
GitHub
3年前
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Move pruning and quant API from paddleslim.dygraph to paddleslim (#633) (#642)
上级
a86edf5a
变更
15
隐藏空白更改
内联
并排
Showing
15 changed file
with
75 addition
and
40 deletion
+75
-40
paddleslim/__init__.py
paddleslim/__init__.py
+5
-0
paddleslim/analysis/flops.py
paddleslim/analysis/flops.py
+28
-1
paddleslim/dygraph/__init__.py
paddleslim/dygraph/__init__.py
+2
-21
paddleslim/dygraph/prune/__init__.py
paddleslim/dygraph/prune/__init__.py
+21
-0
paddleslim/dygraph/prune/filter_pruner.py
paddleslim/dygraph/prune/filter_pruner.py
+2
-2
paddleslim/dygraph/prune/fpgm_pruner.py
paddleslim/dygraph/prune/fpgm_pruner.py
+1
-1
paddleslim/dygraph/prune/l1norm_pruner.py
paddleslim/dygraph/prune/l1norm_pruner.py
+1
-1
paddleslim/dygraph/prune/l2norm_pruner.py
paddleslim/dygraph/prune/l2norm_pruner.py
+1
-1
paddleslim/dygraph/prune/pruner.py
paddleslim/dygraph/prune/pruner.py
+1
-1
paddleslim/dygraph/prune/pruning_plan.py
paddleslim/dygraph/prune/pruning_plan.py
+1
-1
paddleslim/dygraph/prune/var_group.py
paddleslim/dygraph/prune/var_group.py
+3
-3
tests/dygraph/test_flops.py
tests/dygraph/test_flops.py
+6
-5
tests/dygraph/test_prune.py
tests/dygraph/test_prune.py
+1
-1
tests/test_dygraph_pruning_plan.py
tests/test_dygraph_pruning_plan.py
+1
-1
tests/test_flops.py
tests/test_flops.py
+1
-1
未找到文件。
paddleslim/__init__.py
浏览文件 @
2b780c77
...
...
@@ -24,3 +24,8 @@ from paddleslim import dygraph
__all__
=
[
'models'
,
'prune'
,
'nas'
,
'analysis'
,
'dist'
,
'quant'
,
'pantheon'
,
'dygraph'
]
from
paddleslim.dygraph
import
*
__all__
+=
dygraph
.
__all__
from
paddleslim.analysis
import
*
__all__
+=
analysis
.
__all__
This diff is collapsed.
Click to expand it.
paddleslim/analysis/flops.py
浏览文件 @
2b780c77
...
...
@@ -18,7 +18,34 @@ from ..core import GraphWrapper, dygraph2program
__all__
=
[
"flops"
,
"dygraph_flops"
]
def
flops
(
program
,
only_conv
=
True
,
detail
=
False
):
def
flops
(
model
,
inputs
=
None
,
dtypes
=
None
,
only_conv
=
True
,
detail
=
False
):
"""
Compute the FLOPs of nn.Layer of paddle.Program.
Args:
model(paddle.nn.Layer|paddle.static.Program): The target model.
inputs(list): It is only used when model is instance of 'paddle.nn.Layer'. The dummy inputs used for 'model.forward'. It can be:
1. list<int>|tuple<int>: means 'model.forward' accepts
only one variable as argument and the shape of
variable is 'inputs'.
2. list<list<list>>: means 'model.forward' accepts multiple
variables as arguments and the shapes of variables is 'inputs'.
3. others: 'inputs' will be used as argument list by calling
'model.forward(*inputs)'.
dtypes(str|list<str>): It only used when 'inputs' is shape or shapes that means
data type of each input. None means all the inputs is 'float32'.
Default: None.
only_conv(bool): Just return number of mul-adds in convolution and FC layer if `only_conv` is true.
default: True.
detail(bool): Whether to return detail of each convolution layer.
"""
if
isinstance
(
model
,
paddle
.
static
.
Program
):
return
_static_flops
(
model
,
only_conv
=
only_conv
,
detail
=
detail
)
elif
isinstance
(
model
,
paddle
.
nn
.
Layer
):
return
dygraph_flops
(
model
,
inputs
,
dtypes
=
dtypes
,
only_conv
=
only_conv
,
detail
=
detail
)
def
_static_flops
(
program
,
only_conv
=
True
,
detail
=
False
):
"""Get FLOPs of target graph.
Args:
...
...
This diff is collapsed.
Click to expand it.
paddleslim/dygraph/__init__.py
浏览文件 @
2b780c77
from
.
import
var_group
from
.var_group
import
*
from
.
import
l1norm_pruner
from
.l1norm_pruner
import
*
from
.
import
pruner
from
.pruner
import
*
from
.
import
filter_pruner
from
.filter_pruner
import
*
from
.
import
l2norm_pruner
from
.l2norm_pruner
import
*
from
.
import
fpgm_pruner
from
.fpgm_pruner
import
*
__all__
=
[]
__all__
+=
var_group
.
__all__
__all__
+=
l1norm_pruner
.
__all__
__all__
+=
l2norm_pruner
.
__all__
__all__
+=
fpgm_pruner
.
__all__
__all__
+=
pruner
.
__all__
__all__
+=
filter_pruner
.
__all__
from
.quant
import
*
__all__
+=
quant
.
__all__
from
.prune
import
*
__all__
+=
prune
.
__all__
This diff is collapsed.
Click to expand it.
paddleslim/dygraph/prune/__init__.py
0 → 100644
浏览文件 @
2b780c77
from
.
import
var_group
from
.var_group
import
*
from
.
import
l1norm_pruner
from
.l1norm_pruner
import
*
from
.
import
pruner
from
.pruner
import
*
from
.
import
filter_pruner
from
.filter_pruner
import
*
from
.
import
l2norm_pruner
from
.l2norm_pruner
import
*
from
.
import
fpgm_pruner
from
.fpgm_pruner
import
*
__all__
=
[]
__all__
+=
var_group
.
__all__
__all__
+=
l1norm_pruner
.
__all__
__all__
+=
l2norm_pruner
.
__all__
__all__
+=
fpgm_pruner
.
__all__
__all__
+=
pruner
.
__all__
__all__
+=
filter_pruner
.
__all__
This diff is collapsed.
Click to expand it.
paddleslim/dygraph/filter_pruner.py
→
paddleslim/dygraph/
prune/
filter_pruner.py
浏览文件 @
2b780c77
...
...
@@ -4,11 +4,11 @@ import numpy as np
import
pickle
import
copy
import
paddle
from
.
.common
import
get_logger
from
paddleslim
.common
import
get_logger
from
.var_group
import
*
from
.pruning_plan
import
*
from
.pruner
import
Pruner
from
.
.analysis
import
dygraph_flops
as
flops
from
paddleslim
.analysis
import
dygraph_flops
as
flops
from
.var_group
import
VarGroup
__all__
=
[
'Status'
,
'FilterPruner'
]
...
...
This diff is collapsed.
Click to expand it.
paddleslim/dygraph/fpgm_pruner.py
→
paddleslim/dygraph/
prune/
fpgm_pruner.py
浏览文件 @
2b780c77
import
logging
import
numpy
as
np
import
paddle
from
.
.common
import
get_logger
from
paddleslim
.common
import
get_logger
from
.var_group
import
*
from
.pruning_plan
import
*
from
.filter_pruner
import
FilterPruner
...
...
This diff is collapsed.
Click to expand it.
paddleslim/dygraph/l1norm_pruner.py
→
paddleslim/dygraph/
prune/
l1norm_pruner.py
浏览文件 @
2b780c77
import
logging
import
numpy
as
np
import
paddle
from
.
.common
import
get_logger
from
paddleslim
.common
import
get_logger
from
.var_group
import
*
from
.pruning_plan
import
*
from
.filter_pruner
import
FilterPruner
...
...
This diff is collapsed.
Click to expand it.
paddleslim/dygraph/l2norm_pruner.py
→
paddleslim/dygraph/
prune/
l2norm_pruner.py
浏览文件 @
2b780c77
import
logging
import
numpy
as
np
import
paddle
from
.
.common
import
get_logger
from
paddleslim
.common
import
get_logger
from
.var_group
import
*
from
.pruning_plan
import
*
from
.filter_pruner
import
FilterPruner
...
...
This diff is collapsed.
Click to expand it.
paddleslim/dygraph/pruner.py
→
paddleslim/dygraph/prune
/prune
r.py
浏览文件 @
2b780c77
...
...
@@ -3,7 +3,7 @@ import pickle
import
numpy
as
np
import
logging
from
.pruning_plan
import
PruningPlan
from
.
.common
import
get_logger
from
paddleslim
.common
import
get_logger
__all__
=
[
"Pruner"
]
...
...
This diff is collapsed.
Click to expand it.
paddleslim/dygraph/pruning_plan.py
→
paddleslim/dygraph/prun
e/prun
ing_plan.py
浏览文件 @
2b780c77
...
...
@@ -2,7 +2,7 @@ import paddle
import
collections
import
numpy
as
np
import
logging
from
.
.common
import
get_logger
from
paddleslim
.common
import
get_logger
from
paddle.fluid
import
core
_logger
=
get_logger
(
__name__
,
level
=
logging
.
INFO
)
...
...
This diff is collapsed.
Click to expand it.
paddleslim/dygraph/var_group.py
→
paddleslim/dygraph/
prune/
var_group.py
浏览文件 @
2b780c77
...
...
@@ -2,9 +2,9 @@ import numpy as np
import
logging
import
paddle
from
paddle.fluid.dygraph
import
TracedLayer
from
.
.core
import
GraphWrapper
,
dygraph2program
from
.
.prune
import
collect_convs
from
.
.common
import
get_logger
from
paddleslim
.core
import
GraphWrapper
,
dygraph2program
from
paddleslim
.prune
import
collect_convs
from
paddleslim
.common
import
get_logger
__all__
=
[
"VarGroup"
]
...
...
This diff is collapsed.
Click to expand it.
tests/dygraph/test_flops.py
浏览文件 @
2b780c77
...
...
@@ -3,7 +3,7 @@ sys.path.append("../../")
import
unittest
import
numpy
as
np
import
paddle
from
paddleslim
.analysis
import
dygraph_flops
as
flops
from
paddleslim
import
flops
from
paddle.vision.models
import
mobilenet_v1
,
resnet50
from
paddle.nn
import
Conv2D
,
Layer
...
...
@@ -16,7 +16,7 @@ class TestFlops(unittest.TestCase):
def
runTest
(
self
):
net
=
self
.
_net
(
pretrained
=
False
)
FLOPs
=
flops
(
net
,
(
1
,
3
,
32
,
32
))
FLOPs
=
flops
(
net
,
(
1
,
3
,
32
,
32
)
,
only_conv
=
False
)
self
.
assertTrue
(
FLOPs
==
self
.
_gt
)
...
...
@@ -54,7 +54,7 @@ class TestFLOPsCase1(unittest.TestCase):
"y"
:
paddle
.
to_tensor
(
y
),
"z"
:
"test"
}
FLOPs
=
flops
(
net
,
[
inputs
])
FLOPs
=
flops
(
net
,
[
inputs
]
,
only_conv
=
False
)
self
.
assertTrue
(
FLOPs
==
59184
)
...
...
@@ -67,9 +67,10 @@ class TestFLOPsCase2(unittest.TestCase):
y
=
np
.
random
.
uniform
(
-
1
,
1
,
y_shape
).
astype
(
'float32'
)
inputs
=
[
paddle
.
to_tensor
(
x
),
paddle
.
to_tensor
(
y
)]
FLOPs1
=
flops
(
net
,
inputs
)
FLOPs1
=
flops
(
net
,
inputs
,
only_conv
=
False
)
shapes
=
[
x_shape
,
y_shape
]
FLOPs2
=
flops
(
net
,
shapes
,
dtypes
=
[
"float32"
,
"float32"
])
FLOPs2
=
flops
(
net
,
shapes
,
dtypes
=
[
"float32"
,
"float32"
],
only_conv
=
False
)
self
.
assertTrue
(
FLOPs1
==
FLOPs2
)
...
...
This diff is collapsed.
Click to expand it.
tests/dygraph/test_prune.py
浏览文件 @
2b780c77
...
...
@@ -16,7 +16,7 @@ sys.path.append("../../")
import
unittest
import
paddle
import
paddle.fluid
as
fluid
from
paddleslim
.dygraph
import
L1NormFilterPruner
from
paddleslim
import
L1NormFilterPruner
from
paddle.vision.models
import
mobilenet_v1
,
resnet50
from
paddleslim.prune
import
Pruner
...
...
This diff is collapsed.
Click to expand it.
tests/test_dygraph_pruning_plan.py
浏览文件 @
2b780c77
...
...
@@ -2,7 +2,7 @@ import sys
sys
.
path
.
append
(
"../"
)
import
unittest
import
numpy
as
np
from
paddleslim.dygraph.pruning_plan
import
PruningPlan
,
PruningMask
from
paddleslim.dygraph.prun
e.prun
ing_plan
import
PruningPlan
,
PruningMask
class
TestPruningPlan
(
unittest
.
TestCase
):
...
...
This diff is collapsed.
Click to expand it.
tests/test_flops.py
浏览文件 @
2b780c77
...
...
@@ -15,7 +15,7 @@ import sys
sys
.
path
.
append
(
"../"
)
import
unittest
import
paddle.fluid
as
fluid
from
paddleslim
.analysis
import
flops
from
paddleslim
import
flops
from
layers
import
conv_bn_layer
from
static_case
import
StaticCase
...
...
This diff is collapsed.
Click to expand it.
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录
新手
引导
客服
返回
顶部