[论文解读] RepQ-ViT: Scale Reparameterization for Post-Training Quantization of Vision Transformers
RepQ-ViT 提出了一种针对视觉变换器(Vision Transformers)的新型后训练量化框架,通过缩放重参数化技术,将量化精度与硬件效率解耦。该方法在校准阶段首先应用复杂的量化器——对 LayerNorm 后的激活使用逐通道量化,对 Softmax 后的激活使用 log√2 量化;随后将这些量化器的缩放参数重参数化为硬件友好的逐层量化和 log2 量化形式,从而在无需重建或超参数调优的情况下,实现了 4-bit 量化下的最先进精度(例如,在 DeiT-S 上达到 69.03% 的 top-1 准确率)。
Post-training quantization (PTQ), which only requires a tiny dataset for calibration without end-to-end retraining, is a light and practical model compression technique. Recently, several PTQ schemes for vision transformers (ViTs) have been presented; unfortunately, they typically suffer from non-trivial accuracy degradation, especially in low-bit cases. In this paper, we propose RepQ-ViT, a novel PTQ framework for ViTs based on quantization scale reparameterization, to address the above issues. RepQ-ViT decouples the quantization and inference processes, where the former employs complex quantizers and the latter employs scale-reparameterized simplified quantizers. This ensures both accurate quantization and efficient inference, which distinguishes it from existing approaches that sacrifice quantization performance to meet the target hardware. More specifically, we focus on two components with extreme distributions: post-LayerNorm activations with severe inter-channel variation and post-Softmax activations with power-law features, and initially apply channel-wise quantization and log$\sqrt{2}$ quantization, respectively. Then, we reparameterize the scales to hardware-friendly layer-wise quantization and log2 quantization for inference, with only slight accuracy or computational costs. Extensive experiments are conducted on multiple vision tasks with different model variants, proving that RepQ-ViT, without hyperparameters and expensive reconstruction procedures, can outperform existing strong baselines and encouragingly improve the accuracy of 4-bit PTQ of ViTs to a usable level. Code is available at https://github.com/zkkli/RepQ-ViT.
研究动机与目标
- 为解决视觉变换器在低比特后训练量化中,尤其是 4-bit 设置下出现的显著精度下降问题。
- 克服现有 ViT 后训练量化方法中量化精度与硬件效率之间的权衡。
- 通过缩放重参数化,将量化过程(用于精度)与推理过程(用于效率)解耦。
- 通过显式缩放变换,实现硬件友好的推理,同时不牺牲模型性能。
- 在仅使用极少校准数据且无需微调的情况下,实现视觉变换器 4-bit 后训练量化中的最先进结果。
提出的方法
- RepQ-ViT 通过在校准阶段使用复杂量化器、在推理阶段使用简化且硬件友好的量化器,实现量化与推理的解耦。
- 对于具有高通道间差异的 LayerNorm 后激活,首先应用逐通道量化,随后通过调整 LayerNorm 的仿射参数及后续层权重,将之重参数化为逐层量化。
- 对于具有幂律分布的 Softmax 后激活,首先使用 log√2 量化以更好地捕捉极端值,随后重参数化为 log2 量化,以实现高效的位移运算推理。
- 通过保持精度的等价变换实现缩放重参数化,同时支持高效的硬件计算。
- 该方法仅需 32 个校准样本,避免了昂贵的重建或超参数调优。
- 该框架具有坚实的理论基础,并仅带来轻微的精度或计算开销,表现出高度鲁棒性。
实验结果
研究问题
- RQ1是否可以在视觉变换器的后训练量化中实现量化精度与硬件效率的解耦?
- RQ2是否能将复杂量化器有效重参数化为硬件友好的形式,且不造成显著精度损失?
- RQ3与现有方法相比,缩放重参数化是否能提升视觉变换器在 4-bit 后训练量化中的性能?
- RQ4与 log2 量化相比,log√2 量化是否能更好地表示幂律分布的注意力分数?
- RQ5所提出的方法是否能在仅使用极少校准数据且无需微调的情况下实现最先进性能?
主要发现
- 在 DeiT-S 上,RepQ-ViT 实现了 69.03% 的 top-1 准确率(4-bit 权重与激活),显著优于先前方法如 FQ-ViT(0.10%)和 PTQ4ViT(34.08%)。
- 在 Swin-S 上,RepQ-ViT 在 4-bit 后训练量化中达到 79.45% 的 top-1 准确率,超越强基线方法 PTQ4ViT(76.09%)。
- 该方法仅需 32 个校准样本,相比 PTQ4ViT(32 个样本)和 FQ-ViT(1000 个样本)显著降低了数据需求,同时实现了更高精度。
- 通过重参数化为 log2 量化,推理效率得以保持,支持仅带来轻微计算开销的位移操作。
- 与逐通道量化相比,缩放重参数化过程仅造成 1.25% 的精度下降,但实现了硬件友好的逐层量化。
- 该方法具有强鲁棒性与泛化能力,在多种 ViT 变体和视觉任务上均表现出一致的性能提升,且无需超参数调优或重建。
更好的研究,从现在开始
从阅读论文到最终审阅,大幅缩短您的研究时间。
无需绑定信用卡
本解读由 AI 生成,并经人工编辑审核。