未验证 提交 b84cceb5 编写于 作者: C ceci3 提交者: GitHub

[Cherry pick] ac readme and seg readme (#1280)

* optimize segmentic readme (#1273)

* optimize act readme (#1265)

* optimize readme

* update

* add eval.yaml
上级 1fcbadb5
......@@ -280,7 +280,7 @@ python setup.py install
答:这是因为量化后保存的参数是虽然是int8范围,但是类型是float。这是因为Paddle训练前向默认的Kernel不支持INT8 Kernel实现,只有Paddle Inference TensorRT的推理才支持量化推理加速。为了方便量化后验证量化精度,使用Paddle训练前向能加载此模型,默认保存的Float32类型权重,体积没有发生变换。
#### 2. macOS + Python3.9环境下, 安装出错, "command 'swig' failed"
#### 2. macOS + Python3.9环境或者Windows环境下, 安装出错, "command 'swig' failed"
答: 请参考https://github.com/PaddlePaddle/PaddleSlim/issues/1258
......
......@@ -35,7 +35,7 @@ wget https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/inference/MobileN
tar -xf MobileNetV1_infer.tar
# 下载ImageNet小型数据集
wget https://sys-p0.bj.bcebos.com/slim_ci/ILSVRC2012_data_demo.tar.gz
tar xf ILSVRC2012_data_demo.tar.gz
tar -xf ILSVRC2012_data_demo.tar.gz
```
- 2.运行
......@@ -77,17 +77,66 @@ ac = AutoCompression(
model_dir="./MobileNetV1_infer",
model_filename="inference.pdmodel",
params_filename="inference.pdiparams",
save_dir="output",
config={'Quantization': {}, "HyperParameterOptimization": {'max_quant_count': 5}},
save_dir="MobileNetV1_quant",
config={'Quantization': {}, "HyperParameterOptimization": {'ptq_algo': ['avg'], 'max_quant_count': 3}},
train_dataloader=train_loader,
eval_dataloader=train_loader) # eval_function to verify accuracy
eval_dataloader=train_loader)
ac.compress()
```
- 3.测试精度
测试压缩前模型的精度:
```shell
CUDA_VISIBLE_DEVICES=0 python ./image_classification/eval.py
### Eval Top1: 0.7171724759615384
```
测试量化模型的精度:
```shell
CUDA_VISIBLE_DEVICES=0 python ./image_classification/eval.py --model_dir='MobileNetV1_quant'
### Eval Top1: 0.7166466346153846
```
量化后模型的精度相比量化前的模型几乎精度无损,由于是使用的超参搜索的方法来选择的量化参数,所以每次运行得到的量化模型精度会有些许波动。
- 4.推理速度测试
量化模型速度的测试依赖推理库的支持,所以确保安装的是带有TensorRT的PaddlePaddle。以下示例和展示的测试结果是基于Tesla V100、CUDA 10.2、python3.7得到的。
使用以下指令查看本地cuda版本,并且在[下载链接](https://paddleinference.paddlepaddle.org.cn/master/user_guides/download_lib.html#python)中下载对应cuda版本和对应python版本的paddlepaddle安装包。
```shell
cat /usr/local/cuda/version.txt ### CUDA Version 10.2.89
### 10.2.89 为cuda版本号,可以根据这个版本号选择需要安装的带有TensorRT的PaddlePaddle安装包。
```
安装下载的whl包:
```
### 这里通过wget下载到的是python3.7、cuda10.2的PaddlePaddle安装包,若您的环境和示例环境不同,请依赖您自己机器的环境下载对应的安装包,否则运行示例代码会报错。
wget https://paddle-inference-lib.bj.bcebos.com/2.3.0/python/Linux/GPU/x86-64_gcc8.2_avx_mkl_cuda10.2_cudnn8.1.1_trt7.2.3.4/paddlepaddle_gpu-2.3.0-cp37-cp37m-linux_x86_64.whl
pip install paddlepaddle_gpu-2.3.0-cp37-cp37m-linux_x86_64.whl --force-reinstall
```
测试FP32模型的速度
```
python ./image_classification/infer.py
### using tensorrt FP32 batch size: 1 time(ms): 0.6140608787536621
```
测试FP16模型的速度
```
python ./image_classification/infer.py --use_fp16=True
### using tensorrt FP16 batch size: 1 time(ms): 0.5795984268188477
```
测试INT8模型的速度
```
python ./image_classification/infer.py --model_dir=./MobileNetV1_quant/ --use_int8=True
### using tensorrt INT8 batch size: 1 time(ms): 0.5213963985443115
```
**提示:**
- DataLoader传入的数据集是待压缩模型所用的数据集,DataLoader继承自`paddle.io.DataLoader`
- 如无需验证自动化压缩过程中模型的精度,`eval_callback`可不传入function,程序会自动根据损失来选择最优模型。
- 自动化压缩Config中定义量化、蒸馏、剪枝等压缩算法会合并执行,压缩策略有:量化+蒸馏,剪枝+蒸馏等等。
- DataLoader传入的数据集是待压缩模型所用的数据集,DataLoader继承自`paddle.io.DataLoader`。可以直接使用模型套件中的DataLoader,或者根据[paddle.io.DataLoader](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/io/DataLoader_cn.html#dataloader)自定义所需要的DataLoader。
- 自动化压缩Config中定义量化、蒸馏、剪枝等压缩算法会合并执行,压缩策略有:量化+蒸馏,剪枝+蒸馏等等。示例中选择的配置为离线量化超参搜索。
- 如果要压缩的模型参数是存储在各自分离的文件中,需要先通过[convert.py](./convert.py) 脚本将其保存成一个单独的二进制文件。
## 应用示例
......
......@@ -122,9 +122,9 @@ python infer.py --config_path="configs/infer.yaml"
```
在配置文件```configs/infer.yaml```中有以下字段用于配置预测参数:
- ```inference_model_dir```:inference 模型文件所在目录,该目录下需要有文件 .pdmodel 和 .pdiparams 两个文件
- ```model_filename```inference_model_dir文件夹下的模型文件名称
- ```params_filename```inference_model_dir文件夹下的参数文件名称
- ```model_dir```:inference 模型文件所在目录,该目录下需要有文件 .pdmodel 和 .pdiparams 两个文件
- ```model_filename```:model_dir文件夹下的模型文件名称
- ```params_filename```:model_dir文件夹下的参数文件名称
- ```batch_size```:预测一个batch的大小
- ```image_size```:输入图像的大小
- ```use_tensorrt```:是否使用 TesorRT 预测引擎
......
model_dir: './MobileNetV1_infer'
model_filename: 'inference.pdmodel'
params_filename: "inference.pdiparams"
batch_size: 128
data_dir: './ILSVRC2012_data_demo/ILSVRC2012/'
img_size: 224
resize_size: 256
inference_model_dir: "./MobileNetV1_infer"
model_dir: "./MobileNetV1_infer"
model_filename: "inference.pdmodel"
params_filename: "inference.pdiparams"
batch_size: 1
......
......@@ -31,9 +31,13 @@ def argsparser():
parser.add_argument(
'--config_path',
type=str,
default=None,
help="path of compression strategy config.",
required=True)
default='./image_classification/configs/eval.yaml',
help="path of compression strategy config.")
parser.add_argument(
'--model_dir',
type=str,
default='./MobileNetV1_infer',
help='model directory')
return parser
......@@ -92,19 +96,20 @@ def eval():
return result[0]
def main():
def main(args):
global global_config
all_config = load_slim_config(args.config_path)
assert "Global" in all_config, f"Key 'Global' not found in config file. \n{all_config}"
global_config = all_config["Global"]
global_config = load_slim_config(args.config_path)
global data_dir
data_dir = global_config['data_dir']
if args.model_dir != global_config['model_dir']:
global_config['model_dir'] = args.model_dir
global img_size, resize_size
img_size = global_config['img_size'] if 'img_size' in global_config else 224
resize_size = global_config[
'resize_size'] if 'resize_size' in global_config else 256
img_size = int(global_config[
'img_size']) if 'img_size' in global_config else 224
resize_size = int(global_config[
'resize_size']) if 'resize_size' in global_config else 256
result = eval()
print('Eval Top1:', result)
......@@ -114,4 +119,4 @@ if __name__ == '__main__':
paddle.enable_static()
parser = argsparser()
args = parser.parse_args()
main()
main(args)
......@@ -30,8 +30,17 @@ def argsparser():
parser.add_argument(
'--config_path',
type=str,
default='configs/infer.yaml',
default='./image_classification/configs/infer.yaml',
help='config file path')
parser.add_argument(
'--model_dir',
type=str,
default='./MobileNetV1_infer',
help='model directory')
parser.add_argument(
'--use_fp16', type=bool, default=False, help='Whether to use fp16')
parser.add_argument(
'--use_int8', type=bool, default=False, help='Whether to use int8')
return parser
......@@ -53,7 +62,7 @@ class Predictor(object):
output_names[0])
def create_paddle_predictor(self):
inference_model_dir = self.config['inference_model_dir']
inference_model_dir = self.config['model_dir']
model_file = os.path.join(inference_model_dir,
self.config['model_filename'])
params_file = os.path.join(inference_model_dir,
......@@ -110,6 +119,7 @@ class Predictor(object):
time.sleep(0.01) # sleep for T4 GPU
fp_message = "FP16" if config['use_fp16'] else "FP32"
fp_message = "INT8" if config['use_int8'] else fp_message
trt_msg = "using tensorrt" if config[
'use_tensorrt'] else "not using tensorrt"
print("{0}\t{1}\tbatch size: {2}\ttime(ms): {3}".format(
......@@ -121,5 +131,11 @@ if __name__ == "__main__":
parser = argsparser()
args = parser.parse_args()
config = load_config(args.config_path)
if args.model_dir != config['model_dir']:
config['model_dir'] = args.model_dir
if args.use_fp16 != config['use_fp16']:
config['use_fp16'] = args.use_fp16
if args.use_int8 != config['use_int8']:
config['use_int8'] = args.use_int8
predictor = Predictor(config)
predictor.predict()
......@@ -42,16 +42,6 @@
- 软件:CUDA 11.0, cuDNN 8.0, TensorRT 8.0
- 测试配置:batch_size: 40, max_seq_len: 128
- PP-HumanSeg-Lite数据集
- 数据集:AISegment + PP-HumanSeg14K + 内部自建数据集。其中 AISegment 是开源数据集,可从[链接](https://github.com/aisegmentcn/matting_human_datasets)处获取;PP-HumanSeg14K 是 PaddleSeg 自建数据集,可从[官方渠道](https://github.com/PaddlePaddle/PaddleSeg/blob/release/2.5/contrib/PP-HumanSeg/paper.md#pp-humanseg14k-a-large-scale-teleconferencing-video-dataset)获取;内部数据集不对外公开。
- 示例数据集: 用于快速跑通人像分割的压缩和推理流程, 不能用该数据集复现 benckmark 表中的压缩效果。 [下载链接](https://paddleseg.bj.bcebos.com/humanseg/data/mini_supervisely.zip)
- PP-Liteseg,HRNet,UNet,Deeplabv3-ResNet50数据集
- cityscapes: 请从[cityscapes官网](https://www.cityscapes-dataset.com/login/)下载完整数据
- 示例数据集: cityscapes数据集的一个子集,用于快速跑通压缩和推理流程,不能用该数据集复现 benchmark 表中的压缩效果。[下载链接](https://bj.bcebos.com/v1/paddle-slim-models/data/mini_cityscapes/mini_cityscapes.tar)
下面将以开源数据集为例介绍如何对PP-HumanSeg-Lite进行自动压缩。
## 3. 自动压缩流程
......@@ -87,14 +77,25 @@ pip install paddleseg
开发者可下载开源数据集 (如[AISegment](https://github.com/aisegmentcn/matting_human_datasets)) 或自定义语义分割数据集。请参考[PaddleSeg数据准备文档](https://github.com/PaddlePaddle/PaddleSeg/blob/release/2.5/docs/data/marker/marker_cn.md)来检查、对齐数据格式即可。
可以通过以下命令下载人像分割示例数据:
本示例使用示例开源数据集 AISegment 数据集为例介绍如何对PP-HumanSeg-Lite进行自动压缩。示例中的数据集仅用于快速跑通自动压缩流程,并不能复现出 benckmark 表中的压缩效果。
可以通过以下命令下载人像分割示例数据:
```shell
cd ./data
python download_data.py mini_humanseg
python ./data/download_data.py mini_humanseg
### 下载后的数据位置为 ./data/humanseg/
```
** 提示: **
- PP-HumanSeg-Lite压缩过程使用的数据集
- 数据集:AISegment + PP-HumanSeg14K + 内部自建数据集。其中 AISegment 是开源数据集,可从[链接](https://github.com/aisegmentcn/matting_human_datasets)处获取;PP-HumanSeg14K 是 PaddleSeg 自建数据集,可从[官方渠道](https://github.com/PaddlePaddle/PaddleSeg/blob/release/2.5/contrib/PP-HumanSeg/paper.md#pp-humanseg14k-a-large-scale-teleconferencing-video-dataset)获取;内部数据集不对外公开。
- 示例数据集: 用于快速跑通人像分割的压缩和推理流程, 不能用该数据集复现 benckmark 表中的压缩效果。 [下载链接](https://paddleseg.bj.bcebos.com/humanseg/data/mini_supervisely.zip)
- PP-Liteseg,HRNet,UNet,Deeplabv3-ResNet50数据集
- cityscapes: 请从[cityscapes官网](https://www.cityscapes-dataset.com/login/)下载完整数据
- 示例数据集: cityscapes数据集的一个子集,用于快速跑通压缩和推理流程,不能用该数据集复现 benchmark 表中的压缩效果。[下载链接](https://bj.bcebos.com/v1/paddle-slim-models/data/mini_cityscapes/mini_cityscapes.tar)
#### 3.3 准备预测模型
预测模型的格式为:`model.pdmodel``model.pdiparams`两个,带`pdmodel`的是模型文件,带`pdiparams`后缀的是权重文件。
......@@ -112,77 +113,40 @@ tar -xzf ppseg_lite_portrait_398x224_with_softmax.tar.gz
#### 3.4 自动压缩并产出模型
自动压缩示例通过run.py脚本启动,会使用接口```paddleslim.auto_compression.AutoCompression```对模型进行自动压缩。首先要配置config文件中模型路径、数据集路径、蒸馏、量化、稀疏化和训练等部分的参数,配置完成后便可对模型进行非结构化稀疏、蒸馏和量化、蒸馏。
自动压缩示例通过run.py脚本启动,会使用接口 ```paddleslim.auto_compression.AutoCompression``` 对模型进行自动压缩。首先要配置config文件中模型路径、数据集路径、蒸馏、量化、稀疏化和训练等部分的参数,配置完成后便可对模型进行非结构化稀疏、蒸馏和量化、蒸馏。
当只设置训练参数,并传入``deploy_hardware``字段时,将自动搜索压缩策略进行压缩。以骁龙710(SD710)为部署硬件,进行自动压缩的运行命令如下:
当只设置训练参数,并在config文件中 ```Global``` 配置中传入 ```deploy_hardware``` 字段时,将自动搜索压缩策略进行压缩。以骁龙710(SD710)为部署硬件,进行自动压缩的运行命令如下:
```shell
# 单卡启动
export CUDA_VISIBLE_DEVICES=0
python run.py \
--model_dir='./ppseg_lite_portrait_398x224_with_softmax' \
--model_filename='model.pdmodel' \
--params_filename='model.pdiparams' \
--save_dir='./save_model' \
--strategy_config='configs/pp_humanseg/pp_humanseg_auto.yaml' \
--dataset_config='configs/dataset/humanseg_dataset.yaml' \
--deploy_hardware='SD710'
python run.py --config_path='./configs/pp_humanseg/pp_humanseg_auto.yaml' --save_dir='./save_compressed_model'
# 多卡启动
export CUDA_VISIBLE_DEVICES=0,1
python -m paddle.distributed.launch run.py \
--model_dir='./ppseg_lite_portrait_398x224_with_softmax' \
--model_filename='model.pdmodel' \
--params_filename='model.pdiparams' \
--save_dir='./save_model' \
--strategy_config='configs/pp_humanseg/pp_humanseg_auto.yaml' \
--dataset_config='configs/dataset/humanseg_dataset.yaml' \
--deploy_hardware='SD710'
python -m paddle.distributed.launch run.py --config_path='./configs/pp_humanseg/pp_humanseg_auto.yaml' --save_dir='./save_compressed_model'
```
- 自行配置稀疏参数进行非结构化稀疏和蒸馏训练,配置参数含义详见[自动压缩超参文档](https://github.com/PaddlePaddle/PaddleSlim/blob/27dafe1c722476f1b16879f7045e9215b6f37559/demo/auto_compression/hyperparameter_tutorial.md)。具体命令如下所示:
```shell
# 单卡启动
export CUDA_VISIBLE_DEVICES=0
python run.py \
--model_dir='./ppseg_lite_portrait_398x224_with_softmax' \
--model_filename='model.pdmodel' \
--params_filename='model.pdiparams' \
--save_dir='./save_model' \
--strategy_config='configs/pp_humanseg/pp_humanseg_sparse.yaml' \
--dataset_config='configs/dataset/humanseg_dataset.yaml'
python run.py --config_path='./configs/pp_humanseg/pp_humanseg_sparse.yaml' --save_dir='./save_sparse_model'
# 多卡启动
export CUDA_VISIBLE_DEVICES=0,1
python -m paddle.distributed.launch run.py \
--model_dir='./ppseg_lite_portrait_398x224_with_softmax' \
--model_filename='model.pdmodel' \
--params_filename='model.pdiparams' \
--save_dir='./save_model' \
--strategy_config='configs/pp_humanseg/pp_humanseg_sparse.yaml' \
--dataset_config='configs/dataset/humanseg_dataset.yaml'
python -m paddle.distributed.launch run.py --config_path='./configs/pp_humanseg/pp_humanseg_sparse.yaml' --save_dir='./save_sparse_model'
```
- 自行配置量化参数进行量化和蒸馏训练,配置参数含义详见[自动压缩超参文档](https://github.com/PaddlePaddle/PaddleSlim/blob/27dafe1c722476f1b16879f7045e9215b6f37559/demo/auto_compression/hyperparameter_tutorial.md)。具体命令如下所示:
```shell
# 单卡启动
export CUDA_VISIBLE_DEVICES=0
python run.py \
--model_dir='./ppseg_lite_portrait_398x224_with_softmax' \
--model_filename='model.pdmodel' \
--params_filename='model.pdiparams' \
--save_dir='./save_model' \
--strategy_config='configs/pp_humanseg/pp_humanseg_qat.yaml' \
--dataset_config='configs/dataset/humanseg_dataset.yaml'
python run.py --config_path='./configs/pp_humanseg/pp_humanseg_qat.yaml' --save_dir='./save_quant_model'
# 多卡启动
export CUDA_VISIBLE_DEVICES=0,1
python -m paddle.distributed.launch run.py \
--model_dir='./ppseg_lite_portrait_398x224_with_softmax' \
--model_filename='model.pdmodel' \
--params_filename='model.pdiparams' \
--save_dir='./save_model' \
--strategy_config='configs/pp_humanseg/pp_humanseg_qat.yaml' \
--dataset_config='configs/dataset/humanseg_dataset.yaml'
python -m paddle.distributed.launch run.py --config_path='./configs/pp_humanseg/pp_humanseg_qat.yaml' --save_dir='./save_quant_model'
```
压缩完成后会在`save_dir`中产出压缩好的预测模型,可直接预测部署。
......
Global:
reader_config: configs/dataset/cityscapes_1024x512_scale1.0.yml
model_dir: ./RES-paddle2-Deeplabv3-ResNet50
model_filename: model
params_filename: params
Distillation:
alpha: 1.0
......
Global:
reader_config: configs/dataset/cityscapes_1024x512_scale1.0.yml
model_dir: ./RES-paddle2-HRNetW18-Seg
model_filename: model
params_filename: params
Distillation:
alpha: 1.0
......
Global:
reader_config: configs/dataset/cityscapes_1024x512_scale1.0.yml
model_dir: ./RES-paddle2-HRNetW18-Seg
model_filename: model
params_filename: params
Distillation:
alpha: 1.0
......
Global:
reader_config: configs/dataset/humanseg_dataset.yaml
model_dir: ./ppseg_lite_portrait_398x224_with_softmax
model_filename: model.pdmodel
params_filename: model.pdiparams
deploy_hardware: SD710
TrainConfig:
epochs: 14
eval_iter: 400
......
Global:
reader_config: configs/dataset/humanseg_dataset.yaml
model_dir: ./ppseg_lite_portrait_398x224_with_softmax
model_filename: model.pdmodel
params_filename: model.pdiparams
Distillation:
alpha: 1.0
loss: l2
......
Global:
reader_config: configs/dataset/humanseg_dataset.yaml
model_dir: ./ppseg_lite_portrait_398x224_with_softmax
model_filename: model.pdmodel
params_filename: model.pdiparams
Distillation:
alpha: 1.0
loss: l2
......
Global:
reader_config: configs/dataset/cityscapes_1024x512_scale1.0.yml
model_dir: ./RES-paddle2-PPLIteSegSTDC1
model_filename: model
params_filename: params
TrainConfig:
epochs: 14
eval_iter: 90
......
Global:
reader_config: configs/dataset/cityscapes_1024x512_scale1.0.yml
model_dir: ./RES-paddle2-PPLIteSegSTDC1
model_filename: model
params_filename: params
Distillation:
alpha: 1.0
loss: l2
......
Global:
reader_config: configs/dataset/cityscapes_1024x512_scale1.0.yml
model_dir: ./RES-paddle2-PPLIteSegSTDC1
model_filename: model
params_filename: params
Distillation:
alpha: 1.0
loss: l2
......
Global:
reader_config: configs/dataset/cityscapes_1024x512_scale1.0.yml
model_dir: ./RES-paddle2-UNet
model_filename: model
params_filename: params
Distillation:
alpha: 1.0
......
Global:
reader_config: configs/dataset/cityscapes_1024x512_scale1.0.yml
model_dir: ./RES-paddle2-UNet
model_filename: model
params_filename: params
Distillation:
alpha: 1.0
......
......@@ -21,48 +21,24 @@ from paddleseg.cvlibs import Config as PaddleSegDataConfig
from paddleseg.utils import worker_init_fn
from paddleslim.auto_compression import AutoCompression
from paddleslim.auto_compression.config_helpers import load_config as load_slim_config
from paddleseg.core.infer import reverse_transform
from paddleseg.utils import metrics
def parse_args():
parser = argparse.ArgumentParser(description='Model training')
def argsparser():
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument(
'--model_dir',
'--config_path',
type=str,
default=None,
help="inference model directory.")
parser.add_argument(
'--model_filename',
type=str,
default=None,
help="inference model filename.")
parser.add_argument(
'--params_filename',
type=str,
default=None,
help="inference params filename.")
help="path of compression strategy config.")
parser.add_argument(
'--save_dir',
type=str,
default=None,
help="directory to save compressed model.")
parser.add_argument(
'--strategy_config',
type=str,
default=None,
help="path of compression strategy config.")
parser.add_argument(
'--dataset_config',
type=str,
default=None,
help="path of dataset config.")
parser.add_argument(
'--deploy_hardware',
type=str,
default=None,
help="The hardware you want to deploy.")
return parser.parse_args()
return parser
def eval_function(exe, compiled_test_program, test_feed_names, test_fetch_list):
......@@ -141,13 +117,15 @@ def reader_wrapper(reader):
return gen
if __name__ == '__main__':
def main(args):
all_config = load_slim_config(args.config_path)
assert "Global" in all_config, f"Key 'Global' not found in config file. \n{all_config}"
config = all_config["Global"]
rank_id = paddle.distributed.get_rank()
place = paddle.CUDAPlace(rank_id)
args = parse_args()
paddle.enable_static()
# step1: load dataset config and create dataloader
data_cfg = PaddleSegDataConfig(args.dataset_config)
data_cfg = PaddleSegDataConfig(config['reader_config'])
train_dataset = data_cfg.train_dataset
eval_dataset = data_cfg.val_dataset
batch_sampler = paddle.io.DistributedBatchSampler(
......@@ -166,19 +144,24 @@ if __name__ == '__main__':
nranks = paddle.distributed.get_world_size()
rank_id = paddle.distributed.get_rank()
if nranks > 1 and rank_id != 0:
eval_function = None
# step2: create and instance of AutoCompression
ac = AutoCompression(
model_dir=args.model_dir,
model_filename=args.model_filename,
params_filename=args.params_filename,
model_dir=config['model_dir'],
model_filename=config['model_filename'],
params_filename=config['params_filename'],
save_dir=args.save_dir,
config=args.strategy_config,
config=all_config,
train_dataloader=train_dataloader,
eval_callback=eval_function,
deploy_hardware=args.deploy_hardware)
eval_callback=eval_function if nranks > 1 and rank_id != 0 else None,
deploy_hardware=config.get('deploy_hardware') or None)
# step3: start the compression job
ac.compress()
if __name__ == '__main__':
paddle.enable_static()
parser = argsparser()
args = parser.parse_args()
main(args)
......@@ -151,8 +151,9 @@ class AutoCompression:
self.train_dataloader = wrap_dataloader(train_dataloader,
self.feed_vars)
self.eval_dataloader = wrap_dataloader(eval_dataloader, self.feed_vars)
if eval_dataloader is None:
eval_dataloader = self._get_eval_dataloader(self.train_dataloader)
if self.eval_dataloader is None:
self.eval_dataloader = self._get_eval_dataloader(
self.train_dataloader)
self.target_speedup = target_speedup
self.eval_function = eval_callback
......@@ -465,10 +466,10 @@ class AutoCompression:
'train_config must has `epochs` or `train_iter` field.')
config_dict['gmp_config'] = {
'stable_iterations': 0,
'pruning_iterations': 0.45 * total_iters,
'tunning_iterations': 0.45 * total_iters,
'pruning_iterations': max(0.45 * total_iters, 30),
'tunning_iterations': max(0.45 * total_iters, 30),
'resume_iteration': -1,
'pruning_steps': 100,
'pruning_steps': 100 if (0.45 * total_iters) > 1000 else 1,
'initial_ratio': 0.15,
}
### add prune program
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册