Skip to main content
QUICK REVIEW

[Paper Review] SAM-Lightening: A Lightweight Segment Anything Model with Dilated Flash Attention to Achieve 30 times Acceleration

Yanfei Songa, Bangzheng Pua|arXiv (Cornell University)|Mar 14, 2024
Data Visualization and AnalyticsComputer Science5 citations
TL;DR

SAM-Lightening re-engineers SAM's encoder with a Dilated Flash Attention and dynamic layer-wise distillation to deliver ~30× faster inference and dramatically lower memory while preserving segmentation quality.

ABSTRACT

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/.

Motivation & Objective

  • Address the computational bottlenecks of the Segment Anything Model (SAM) in real-world deployments.
  • Introduce an efficient image encoder using Dilated Flash Attention to speed up inference and reduce memory.
  • Propose Dynamic Layer-Wise Distillation (DLD) to transfer knowledge from vanilla SAM without training from scratch.
  • Demonstrate that SAM-Lightening maintains competitive segmentation performance on COCO and LVIS while being significantly more efficient.

Proposed method

  • Design a Dilated Flash Attention mechanism to replace vanilla self-attention with higher parallelism and sparsified segments.
  • Apply dynamic layer-wise distillation (DLD) to progressively transfer knowledge from SAM to the lightweight encoder.
  • Use decoupled feature distillation focusing on deeper layers near the output to align representations with the teacher.
  • Fine-tune the decoder to align with the lightweight encoder for prompt-based segmentation tasks.
  • Train with 1% SA-1B data, saving SAM encoder outputs to accelerate distillation, and evaluate on standard benchmarks.

Experimental results

Research questions

  • RQ1Can a re-engineered attention mechanism (Dilated Flash Attention) accelerate SAM’s encoder without sacrificing accuracy?
  • RQ2Does dynamic layer-wise distillation effectively transfer knowledge from SAM to a lightweight encoder?
  • RQ3What is the trade-off between speed, memory, and segmentation performance on COCO and LVIS for SAM-Lightening?
  • RQ4How does SAM-Lightening compare with state-of-the-art SAM variants under various prompts (Box, 1P, 3P) and in Anything mode?

Key findings

  • SAM-Lightening achieves 7 ms per image on 1024×1024 inputs, i.e., 30.1× faster than vanilla SAM and 2.1× faster than the state-of-the-art.
  • Memory usage is reduced to 224 MB, about 3.5% of the vanilla SAM.
  • Inference latency and memory efficiency surpass competing lightweight SAM variants across prompts and datasets.
  • SAM-Lightening maintains segmentation performance comparable to vanilla SAM on COCO and LVIS under Box and Point prompts.
  • Dynamic Layer-Wise Distillation enables efficient knowledge transfer with staged layer-wise weighting and focus on deeper feature layers near the output.
  • Decoder fine-tuning with point/box prompts aligns the lightweight encoder with the frozen decoder.

Read this paper

Open the full text in the Nubint reader and ask about any passage as you read.

Read this paper on Nubint

This review was generated by AI from the original paper. Please check the paper before citing it.