arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2405.03144cs.CVcs.LG
收藏

PTQ4SAM:面向 Segment Anything 的训练后量化

PTQ4SAM: Post-Training Quantization for Segment Anything

Beihang University(北京航空航天大学);Zhongguancun Laboratory(中关村实验室);Hefei Comprehensive National Science Center(合肥综合性国家科学中心)

Chengtao Lv, Hong Chen, Jinyang Guo, Yifu Ding, Xianglong Liu

AI总结:

本文提出 PTQ4SAM 训练后量化框架,通过 Bimodal Integration 策略和自适应粒度 Softmax 量化解决 SAM 量化瓶颈,在多种视觉任务上实现接近无损的低比特压缩与加速。

摘要:

Segment Anything Model(SAM)在许多计算机视觉任务中取得了令人瞩目的性能。然而,作为一个大规模模型,其巨大的内存和计算成本阻碍了实际部署。本文提出了一个面向 Segment Anything Model 的训练后量化(PTQ)框架,即 PTQ4SAM。首先,我们研究了 SAM 量化中由 Key-Linear 后激活的双峰分布所导致的内在瓶颈。我们从逐张量和逐通道两个角度分析了其特征,并提出了一种 Bimodal Integration 策略,该策略利用数学上等价的符号操作,在离线阶段将双峰分布转换为相对容易量化的正态分布。其次,SAM 包含多种注意力机制(即自注意力和双向交叉注意力),导致 Softmax 后分布存在显著差异。因此,我们通过搜索硬件友好的最优 2 的幂底数,为 Softmax 引入了一种 Adaptive Granularity Quantization。在多种视觉任务(实例分割、语义分割和目标检测)、数据集和模型变体上的大量实验结果表明了 PTQ4SAM 的优越性。例如,将 SAM-L 量化为 6 位时,我们在实例分割上实现了无损精度,理论加速 3.9 倍,精度下降约 0.5%。代码可在 https://github.com/chengtao-lv/PTQ4SAM 获取。

英文摘要:

Segment Anything Model (SAM) has achieved impressive performance in many computer vision tasks. However, as a large-scale model, the immense memory and computation costs hinder its practical deployment. In this paper, we propose a post-training quantization (PTQ) framework for Segment Anything Model, namely PTQ4SAM. First, we investigate the inherent bottleneck of SAM quantization attributed to the bimodal distribution in post-Key-Linear activations. We analyze its characteristics from both per-tensor and per-channel perspectives, and propose a Bimodal Integration strategy, which utilizes a mathematically equivalent sign operation to transform the bimodal distribution into a relatively easy-quantized normal distribution offline. Second, SAM encompasses diverse attention mechanisms (i.e., self-attention and two-way cross-attention), resulting in substantial variations in the post-Softmax distributions. Therefore, we introduce an Adaptive Granularity Quantization for Softmax through searching the optimal power-of-two base, which is hardware-friendly. Extensive experimental results across various vision tasks (instance segmentation, semantic segmentation and object detection), datasets and model variants show the superiority of PTQ4SAM. For example, when quantizing SAM-L to 6-bit, we achieve lossless accuracy for instance segmentation, about 0.5\% drop with theoretical 3.9$\times$ acceleration. The code is available at \url{https://github.com/chengtao-lv/PTQ4SAM}.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑