zhangjun / zhangjun.github.io

https://zhangjun.github.io
2 stars 0 forks source link

量化 #24

Open zhangjun opened 2 years ago

zhangjun commented 2 years ago

PaddleSlim量化

image

PaddleSlim主要包含三种量化方法:量化训练(Quant Aware Training, QAT)、动态离线量化(Post Training Quantization Dynamic, PTQ Dynamic)、静态离线量化(Post Training Quantization Static, PTQ Static)。

image

综合对比了模型量化方法的使用条件、易用性、精度损失和预期收益。

image

量化方法 API接口 功能 经典适用场景
在线量化 (QAT) 动态图:paddleslim.QAT; 静态图:paddleslim.quant.quant_aware 通过finetune训练将模型量化误差降到最小 对量化敏感的场景、模型,例如目标检测、分割, OCR
静态离线量化 (PTQ Static) paddleslim.quant.quant_post_static 通过少量校准数据得到量化模型 对量化不敏感的场景,例如图像分类任务
动态离线量化 (PTQ Dynamic) paddleslim.quant.quant_post_dynamic 仅量化模型的可学习权重 模型体积大、访存开销大的模型,例如BERT模型
Embedding量化(Quant Embedding) paddleslim.quant.quant_embedding 仅量化模型的Embedding参数 任何包含Embedding层的模型

静态离线量化(Post Training Quantization Static, PTQ Static)

静态离线量化中,有两种计算量化因子的方法,非饱和量化方法和饱和量化方法。非饱和量化方法计算整个Tensor的绝对值最大值abs_max,将其映射为127。饱和量化方法使用KL散度计算一个合适的阈值T (0<T<mab_max),将其映射为127。一般而言,待量化Op的权重采用非饱和量化方法,待量化Op的激活(输入和输出)采用饱和量化方法 。

zhangjun commented 2 years ago

PaddleSlim离线量化原理

zhangjun commented 2 years ago

量化基础

zhangjun commented 2 years ago

low precision

zhangjun commented 1 year ago

高通量化 https://www.csdn.net/article/2022-03-22/123659736

zhangjun commented 1 year ago

TensorRT int8量化

tensorrt量化

zhangjun commented 1 year ago

TODO

https://zhuanlan.zhihu.com/p/92153268 https://zhuanlan.zhihu.com/p/349678095 https://zhuanlan.zhihu.com/p/362033017 https://zhuanlan.zhihu.com/p/415690699 https://zhuanlan.zhihu.com/p/336682366 https://zhuanlan.zhihu.com/p/199710646

zhangjun commented 1 year ago

Sparse

Efficient GPU Kernels for N:M-Sparse Weights in Deep Learning Apex N:M sparse Sparse GPU Kernels for Deep Learning Efficient Tensor Core-Based GPU Kernels for Structured Sparsity under Reduced Precision N:M Fine-grained Structured Sparse Neural Networks