SAM-Lightening:一种采用扩张闪光注意力实现30倍加速的轻量级分割一切模型
SAM-Lightening: A Lightweight Segment Anything Model with Dilated Flash Attention to Achieve 30 times Acceleration
AI总结:
针对SAM推理慢、内存高的问题,提出SAM-Lightening,采用扩张闪光注意力机制和渐进式蒸馏,实现30.1倍加速和3.5%内存占用,在COCO和LVIS上精度与效率均超越现有方法。
摘要:
分割一切模型(SAM)因其零样本泛化能力在分割任务中引起了广泛关注。然而,SAM在现实世界实践中的更广泛应用受到其低推理速度和高计算内存需求的限制,这主要源于注意力机制。现有工作集中于优化编码器,但尚未充分解决注意力机制本身的低效问题,即使将其蒸馏到更小的模型也是如此,这为进一步改进留下了空间。为此,我们引入了SAM-Lightening,一种SAM的变体,其特点是重新设计的注意力机制,称为扩张闪光注意力(Dilated Flash Attention)。它不仅促进了更高的并行性,提高了处理效率,而且保持了与现有FlashAttention的兼容性。相应地,我们提出了一种渐进式蒸馏方法,以实现从原始SAM的高效知识迁移,而无需昂贵的从头训练。在COCO和LVIS上的实验表明,SAM-Lightening在运行效率和分割精度方面均显著优于最先进的方法。具体而言,对于尺寸为1024*1024像素的图像,它可以实现每张图像7毫秒(ms)的推理速度,比原始SAM快30.1倍,比最先进的方法快2.1倍。此外,它仅占用244MB内存,是原始SAM的3.5%。代码和权重可在https://anonymous.4open.science/r/SAM-LIGHTENING-BC25/获取。
英文摘要:
Segment Anything Model (SAM) has garnered significant attention in segmentation tasks due to their zero-shot generalization ability. However, a broader application of SAMs to real-world practice has been restricted by their low inference speed and high computational memory demands, which mainly stem from the attention mechanism. Existing work concentrated on optimizing the encoder, yet has not adequately addressed the inefficiency of the attention mechanism itself, even when distilled to a smaller model, which thus leaves space for further improvement. In response, we introduce SAM-Lightening, a variant of SAM, that features a re-engineered attention mechanism, termed Dilated Flash Attention. It not only facilitates higher parallelism, enhancing processing efficiency but also retains compatibility with the existing FlashAttention. Correspondingly, we propose a progressive distillation to enable an efficient knowledge transfer from the vanilla SAM without costly training from scratch. Experiments on COCO and LVIS reveal that SAM-Lightening significantly outperforms the state-of-the-art methods in both run-time efficiency and segmentation accuracy. Specifically, it can achieve an inference speed of 7 milliseconds (ms) per image, for images of size 1024*1024 pixels, which is 30.1 times faster than the vanilla SAM and 2.1 times than the state-of-the-art. Moreover, it takes only 244MB memory, which is 3.5\% of the vanilla SAM. The code and weights are available at https://anonymous.4open.science/r/SAM-LIGHTENING-BC25/.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。