Open zhangjun opened 2 years ago
PaddleSlim主要包含三种量化方法:量化训练(Quant Aware Training, QAT)、动态离线量化(Post Training Quantization Dynamic, PTQ Dynamic)、静态离线量化(Post Training Quantization Static, PTQ Static)。
综合对比了模型量化方法的使用条件、易用性、精度损失和预期收益。
静态离线量化中,有两种计算量化因子的方法,非饱和量化方法和饱和量化方法。非饱和量化方法计算整个Tensor的绝对值最大值abs_max,将其映射为127。饱和量化方法使用KL散度计算一个合适的阈值T (0<T<mab_max),将其映射为127。一般而言,待量化Op的权重采用非饱和量化方法,待量化Op的激活(输入和输出)采用饱和量化方法 。
PaddleSlim离线量化原理
batch_norm、softmax、pooling 为防止溢出,需要使用fp32
高通量化 https://www.csdn.net/article/2022-03-22/123659736
tensorrt量化
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
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
PaddleSlim量化
PaddleSlim主要包含三种量化方法:量化训练(Quant Aware Training, QAT)、动态离线量化(Post Training Quantization Dynamic, PTQ Dynamic)、静态离线量化(Post Training Quantization Static, PTQ Static)。
综合对比了模型量化方法的使用条件、易用性、精度损失和预期收益。
静态离线量化(Post Training Quantization Static, PTQ Static)
静态离线量化中,有两种计算量化因子的方法,非饱和量化方法和饱和量化方法。非饱和量化方法计算整个Tensor的绝对值最大值abs_max,将其映射为127。饱和量化方法使用KL散度计算一个合适的阈值T (0<T<mab_max),将其映射为127。一般而言,待量化Op的权重采用非饱和量化方法,待量化Op的激活(输入和输出)采用饱和量化方法 。