Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleSlim
提交
18ed3324
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看板
未验证
提交
18ed3324
编写于
7月 05, 2022
作者:
C
ceci3
提交者:
GitHub
7月 05, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[cherry pick] fix smac output_dir (#1248)
上级
75f477ff
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
11 addition
and
5 deletion
+11
-5
example/auto_compression/README.md
example/auto_compression/README.md
+2
-2
paddleslim/quant/post_quant_hpo.py
paddleslim/quant/post_quant_hpo.py
+9
-3
未找到文件。
example/auto_compression/README.md
浏览文件 @
18ed3324
...
...
@@ -33,7 +33,7 @@ import paddle
from
PIL
import
Image
from
paddle.vision.datasets
import
DatasetFolder
from
paddle.vision.transforms
import
transforms
from
paddleslim.auto_compression
import
AutoCompression
,
Quantization
,
HyperParameterOptimization
from
paddleslim.auto_compression
import
AutoCompression
paddle
.
enable_static
()
# 定义DataSet
class
ImageNetDataset
(
DatasetFolder
):
...
...
@@ -65,7 +65,7 @@ ac = AutoCompression(
model_filename
=
"inference.pdmodel"
,
params_filename
=
"inference.pdiparams"
,
save_dir
=
"output"
,
config
=
{
'Quantization'
:
Quantization
(),
"HyperParameterOptimization"
:
HyperParameterOptimization
(
max_quant_count
=
5
)
},
config
=
{
'Quantization'
:
{},
"HyperParameterOptimization"
:
{
'max_quant_count'
:
5
}
},
train_dataloader
=
train_loader
,
eval_dataloader
=
train_loader
)
# eval_function to verify accuracy
ac
.
compress
()
...
...
paddleslim/quant/post_quant_hpo.py
浏览文件 @
18ed3324
...
...
@@ -17,6 +17,7 @@ import os
import
sys
import
math
import
time
from
time
import
gmtime
,
strftime
import
numpy
as
np
import
shutil
import
paddle
...
...
@@ -40,7 +41,7 @@ from paddleslim.quant import quant_post
_logger
=
get_logger
(
__name__
,
level
=
logging
.
INFO
)
SMAC_TMP_FILE_PATTERN
=
"smac3-output
*
"
SMAC_TMP_FILE_PATTERN
=
"smac3-output
_
"
def
remove
(
path
):
...
...
@@ -496,6 +497,9 @@ def quant_post_hpo(
cs
.
add_hyperparameters
(
hyper_params
)
s_datetime
=
strftime
(
"%Y-%m-%d-%H:%M:%S"
,
gmtime
())
smac_output_dir
=
SMAC_TMP_FILE_PATTERN
+
s_datetime
scenario
=
Scenario
({
"run_obj"
:
"quality"
,
# we optimize quality (alternative runtime)
"runcount-limit"
:
...
...
@@ -503,7 +507,9 @@ def quant_post_hpo(
"cs"
:
cs
,
# configuration space
"deterministic"
:
"True"
,
"limit_resources"
:
"False"
,
"memory_limit"
:
4096
# adapt this to reasonable value for your hardware
"memory_limit"
:
4096
,
# adapt this to reasonable value for your hardware
"output_dir"
:
smac_output_dir
# output_dir
})
# To optimize, we pass the function to the SMAC-object
smac
=
SMAC4HPO
(
...
...
@@ -523,5 +529,5 @@ def quant_post_hpo(
inc_value
=
smac
.
get_tae_runner
().
run
(
incumbent
,
1
)[
1
]
_logger
.
info
(
"Optimized Value: %.8f"
%
inc_value
)
shutil
.
rmtree
(
g_quant_model_cache_path
)
remove
(
SMAC_TMP_FILE_PATTERN
)
remove
(
smac_output_dir
)
_logger
.
info
(
"Quantization completed."
)
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录