Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BMN模型和AttentionLSTM模型量化压缩和蒸馏方案 #1876

Open
AvaMins opened this issue May 23, 2024 · 2 comments
Open

BMN模型和AttentionLSTM模型量化压缩和蒸馏方案 #1876

AvaMins opened this issue May 23, 2024 · 2 comments
Assignees

Comments

@AvaMins
Copy link

AvaMins commented May 23, 2024

1、BMN模型和AttentionLSTM模型是否有量化压缩和蒸馏的方案?训练完成的AttentionLSTM模型的模型参数和计算量如何计算?
2、模型使用自动压缩,参数文件大小没有变化,如何处理这种情况?

@wanghaoshuang
Copy link
Collaborator

wanghaoshuang commented May 24, 2024

BMN模型和AttentionLSTM模型是否有量化压缩和蒸馏的方案?

飞桨没有提供这两个模型的量化压缩何蒸馏方案,可以参考其它模型来做,基础原理是一样的。

训练完成的AttentionLSTM模型的模型参数和计算量如何计算?

可以使用飞桨接口 paddle.flops 计算flops(计算量);
paddle.nn.Layer 提供 parameters function,用于获取模型的所有参数。相关文档:https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/nn/Layer_cn.html#parameters-include-sublayers-true

模型使用自动压缩,参数文件大小没有变化,如何处理这种情况?

辛苦上传下日志,我们确认下具体触发了什么压缩算法?

@AvaMins
Copy link
Author

AvaMins commented May 29, 2024

BMN模型和AttentionLSTM模型是否有量化压缩和蒸馏的方案?

飞桨没有提供这两个模型的量化压缩何蒸馏方案,可以参考其它模型来做,基础原理是一样的。

训练完成的AttentionLSTM模型的模型参数和计算量如何计算?

可以使用飞桨接口 paddle.flops 计算flops(计算量); paddle.nn.Layer 提供 parameters function,用于获取模型的所有参数。相关文档:https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/nn/Layer_cn.html#parameters-include-sublayers-true

模型使用自动压缩,参数文件大小没有变化,如何处理这种情况?

辛苦上传下日志,我们确认下具体触发了什么压缩算法?


压缩脚本使用的是:PaddleVideo/deploy/slim/quant_post_static.py


压缩配置文件内容如下:
DATASET:
batch_size: 1
batch_nums: 10
num_workers: 0
quant:
format: "FrameDataset_Sport"
data_prefix: ""
file_path: "/home/jetion/Action/apps/cpr/datasets/CPR/input_for_pptsm/val.list"
suffix: 'img_{:05}.jpg'

PIPELINE:
quant:
decode:
name: "FrameDecoder"
sample:
name: "SamplerPkl"
num_seg: 8
seg_len: 1
valid_mode: True
transform:
- Scale:
short_size: 256
- CenterCrop:
target_size: 224
- Image2Array:
- Normalization:
mean: [0.537, 0.541, 0.543]
std: [0.230, 0.221, 0.225]

inference_model_dir: "/home/jetion/Action/apps/cpr/export_models/ppTSM_server"
quant_output_dir: "/home/jetion/PaddleVideo2.2/deploy/slim/quant_cpu_models/ppTSM"

model_name: "ppTSM"
log_level: "INFO" # Optional, the logger level. default: "INFO"


静态离线量化日志如下:
[05-29 17:25:06 MainThread @logger.py:242] Argv: quant_post_static.py -c ./pptsm_frames_uniform_quantization.yaml --use_gpu=True
/home/jetion/anaconda3/envs/pdslim/lib/python3.8/site-packages/setuptools/sandbox.py:13: DeprecationWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html
import pkg_resources
/home/jetion/anaconda3/envs/pdslim/lib/python3.8/site-packages/pkg_resources/init.py:2871: DeprecationWarning: Deprecated call to pkg_resources.declare_namespace('mpl_toolkits').
Implementing implicit namespace packages (as specified in PEP 420) is preferred to pkg_resources.declare_namespace. See https://setuptools.pypa.io/en/latest/references/keywords.html#keyword-namespace-packages
declare_namespace(pkg)
/home/jetion/anaconda3/envs/pdslim/lib/python3.8/site-packages/pkg_resources/init.py:2871: DeprecationWarning: Deprecated call to pkg_resources.declare_namespace('google').
Implementing implicit namespace packages (as specified in PEP 420) is preferred to pkg_resources.declare_namespace. See https://setuptools.pypa.io/en/latest/references/keywords.html#keyword-namespace-packages
declare_namespace(pkg)
WARNING:root:cannot import name 'layers' from 'parl' (/home/jetion/anaconda3/envs/pdslim/lib/python3.8/site-packages/parl/init.py)
No module named 'av', [av] package and it's dependencies is required for TimeSformer and other models.
No module named 'skimage', [scikit-image] package and it's dependencies is required for ADDS.
No module named 'paddlenlp', [paddlenlp] package and it's dependencies is required for ActBERT.
No module named 'SimpleITK', [SimpleITK] package and it's dependencies is required for PP-Care.
No module named 'SimpleITK', [SimpleITK] package and it's dependencies is required for PP-Care.
No module named 'lmdb', [lmdb] package and it's dependencies is required for ActBERT.
No module named 'paddlenlp', [paddlenlp] package and it's dependencies is required for ActBERT.
No module named 'lmdb', [lmdb] package and it's dependencies is required for ActBERT.
No module named 'paddlenlp', [paddlenlp] package and it's dependencies is required for ActBERT.
[05/29 17:25:06] DATASET :
[05/29 17:25:06] batch_nums : 10
[05/29 17:25:06] batch_size : 1
[05/29 17:25:06] num_workers : 0
[05/29 17:25:06] quant :
[05/29 17:25:06] data_prefix :
[05/29 17:25:06] file_path : /home/jetion/Action/apps/cpr/datasets/CPR/input_for_pptsm/val.list
[05/29 17:25:06] format : FrameDataset_Sport
[05/29 17:25:06] suffix : img_{:05}.jpg
[05/29 17:25:06] ------------------------------------------------------------
[05/29 17:25:06] PIPELINE :
[05/29 17:25:06] quant :
[05/29 17:25:06] decode :
[05/29 17:25:06] name : FrameDecoder
[05/29 17:25:06] sample :
[05/29 17:25:06] name : SamplerPkl
[05/29 17:25:06] num_seg : 8
[05/29 17:25:06] seg_len : 1
[05/29 17:25:06] valid_mode : True
[05/29 17:25:06] transform :
[05/29 17:25:06] Scale :
[05/29 17:25:06] short_size : 256
[05/29 17:25:06] CenterCrop :
[05/29 17:25:06] target_size : 224
[05/29 17:25:06] Image2Array : None
[05/29 17:25:06] Normalization :
[05/29 17:25:06] mean : [0.537, 0.541, 0.543]
[05/29 17:25:06] std : [0.23, 0.221, 0.225]
[05/29 17:25:06] ------------------------------------------------------------
[05/29 17:25:06] inference_model_dir : /home/jetion/Action/apps/cpr/export_models/ppTSM_server
[05/29 17:25:06] log_level : INFO
[05/29 17:25:06] model_name : ppTSM
[05/29 17:25:06] quant_output_dir : /home/jetion/PaddleVideo2.2/deploy/slim/quant_cpu_models/ppTSM
inference_file_name: ppTSM
[05/29 17:25:06] Build slim_loader finished
[05/29 17:25:06] Staring Post-Training Quantization...
/home/jetion/anaconda3/envs/pdslim/lib/python3.8/site-packages/_distutils_hack/init.py:33: UserWarning: Setuptools is replacing distutils.
warnings.warn("Setuptools is replacing distutils.")
Wed May 29 17:25:06-INFO: Load model and set data loader ...
W0529 17:25:07.024253 16356 gpu_resources.cc:61] Please NOTE: device: 0, GPU Compute Capability: 8.6, Driver API Version: 12.1, Runtime API Version: 11.2
W0529 17:25:07.026293 16356 gpu_resources.cc:91] device: 0, cuDNN Version: 8.2.
Wed May 29 17:25:07-INFO: Collect quantized variable names ...

Preparation stage, Run batch:| | 0/10
Preparation stage, Run batch:|████▍ | 1/10
Preparation stage, Run batch:|████████▊ | 2/10
Preparation stage, Run batch:|█████████████▏ | 3/10
Preparation stage, Run batch:|█████████████████▌ | 4/10
Preparation stage, Run batch:|██████████████████████ | 5/10
Preparation stage, Run batch:|██████████████████████████▍ | 6/10
Preparation stage, Run batch:|██████████████████████████████▊ | 7/10
Preparation stage, Run batch:|███████████████████████████████████▏ | 8/10
Preparation stage, Run batch:|███████████████████████████████████████▌ | 9/10
Preparation stage, Run batch:|███████████████████████████████████████████| 10/10
Preparation stage, Run batch:|███████████████████████████████████████████| 10/10

Sampling stage, Run batch:| | 0/10
Sampling stage, Run batch:|████▋ | 1/10
Sampling stage, Run batch:|█████████▍ | 2/10
Sampling stage, Run batch:|██████████████ | 3/10
Sampling stage, Run batch:|██████████████████▊ | 4/10
Sampling stage, Run batch:|███████████████████████▌ | 5/10
Sampling stage, Run batch:|████████████████████████████▏ | 6/10
Sampling stage, Run batch:|████████████████████████████████▉ | 7/10
Sampling stage, Run batch:|█████████████████████████████████████▌ | 8/10
Sampling stage, Run batch:|██████████████████████████████████████████▎ | 9/10
Sampling stage, Run batch:|██████████████████████████████████████████████| 10/10
Sampling stage, Run batch:|██████████████████████████████████████████████| 10/10
Wed May 29 17:28:20-INFO: Calculate KL threshold ...
Wed May 29 17:29:31-INFO: Update the program ...

Adding quant op with weight:| | 0/202
Adding quant op with weight:|█████████▎ | 44/202
Adding quant op with weight:|██████████████████▋ | 88/202
Adding quant op with weight:|███████████████████████████ | 130/202
Adding quant op with weight:|██████████████████████████████████████▉ | 187/202
Adding quant op with weight:|██████████████████████████████████████████| 202/202

Adding quant activation op:| | 0/422
Adding quant activation op:| | 1/422
Wed May 29 17:29:32-INFO: The quantized model is saved in /home/jetion/PaddleVideo2.2/deploy/slim/quant_cpu_models/ppTSM
[05/29 17:29:32] Post-Training Quantization finished...

模型压缩后,参数文件大小如下:
97E90292-39A1-454c-9249-22225F97C820
第一个文件是静态量化压缩前的模型参数文件,第二个是压缩后的文件。可以看到,压缩后文件大小没有变小,反而增大了。

麻烦帮忙看一下是什么问题,谢谢!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants