Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleSlim
提交
2952d4ce
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看板
未验证
提交
2952d4ce
编写于
6月 07, 2022
作者:
W
whs
提交者:
GitHub
6月 07, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Skip auto tuning when shape of model's input is variable (#1155)
上级
418ef571
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
36 addition
and
2 deletion
+36
-2
.pre-commit-config.yaml
.pre-commit-config.yaml
+1
-0
paddleslim/analysis/extract_features.py
paddleslim/analysis/extract_features.py
+0
-1
paddleslim/auto_compression/auto_strategy.py
paddleslim/auto_compression/auto_strategy.py
+11
-1
paddleslim/auto_compression/utils/predict.py
paddleslim/auto_compression/utils/predict.py
+24
-0
未找到文件。
.pre-commit-config.yaml
浏览文件 @
2952d4ce
...
...
@@ -12,6 +12,7 @@ repos:
sha
:
0d79c0c469bab64f7229c9aca2b1186ef47f0e37
hooks
:
-
id
:
yapf
language_version
:
python3.9
files
:
(.*\.(py|bzl)|BUILD|.*\.BUILD|WORKSPACE)$
-
repo
:
https://github.com/pre-commit/pre-commit-hooks
sha
:
5bf6c09bfa1297d3692cadd621ef95f1284e33c0
...
...
paddleslim/analysis/extract_features.py
浏览文件 @
2952d4ce
...
...
@@ -50,7 +50,6 @@ def get_features_from_paramkey(param_key, op_type, data_type):
"""Get op's parameters according to the key of latency table
"""
features
=
None
if
'conv2d'
in
op_type
:
if
data_type
==
'fp16'
:
quant_bits
=
'bit_length=16'
...
...
paddleslim/auto_compression/auto_strategy.py
浏览文件 @
2952d4ce
...
...
@@ -16,7 +16,7 @@ import os
import
logging
import
platform
from
..common
import
get_logger
from
.utils.predict
import
predict_compressed_model
from
.utils.predict
import
predict_compressed_model
,
with_variable_shape
from
.strategy_config
import
*
_logger
=
get_logger
(
__name__
,
level
=
logging
.
INFO
)
...
...
@@ -151,6 +151,16 @@ def prepare_strategy(executor,
""" prepare compression config automatically """
final_strategy
=
None
if
with_variable_shape
(
model_dir
,
model_filename
=
model_filename
,
params_filename
=
params_filename
):
deploy_hardware
=
None
_logger
.
warning
(
"The model's inputs have variable shape. "
"And the latency predictor doesn't support variable shape. "
"So auto tuning will be skipped and a default strategy will be chosen."
)
### use hardware latency tabel if support
if
deploy_hardware
is
not
None
:
compressed_time_dict
=
predict_compressed_model
(
...
...
paddleslim/auto_compression/utils/predict.py
浏览文件 @
2952d4ce
...
...
@@ -6,6 +6,30 @@ from .prune_model import get_sparse_model, get_prune_model
from
.fake_ptq
import
post_quant_fake
def
with_variable_shape
(
model_dir
,
model_filename
=
None
,
params_filename
=
None
):
"""
Whether the shape of model's input is variable.
Args:
path_prefix(str | None): Directory path to save model + model name without suffix.
model_filename(str): specify model_filename if you don't want to use default name. Default : 'None'.
params_filename(str): specify params_filename if you don't want to use default name. Default : 'None'.
Returns:
bool: Whether the shape of model's input is variable.
"""
paddle
.
enable_static
()
exe
=
paddle
.
static
.
Executor
(
paddle
.
CPUPlace
())
[
inference_program
,
feed_target_names
,
fetch_targets
]
=
(
paddle
.
static
.
load_inference_model
(
model_dir
,
exe
,
model_filename
=
model_filename
,
params_filename
=
params_filename
))
for
var_
in
inference_program
.
list_vars
():
if
var_
.
name
in
feed_target_names
:
if
var_
.
shape
.
count
(
-
1
)
>
1
:
return
True
def
predict_compressed_model
(
executor
,
places
,
model_dir
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录