SAQ-SAM: Semantically-Aligned Quantization for Segment Anything Model

Jing Zhang, Zhikai Li, Qingyi GuarXiv 2025 · DOI

TL;DR

The Segment Anything Model (SAM) is a breakthrough in computer vision, but its massive size makes edge deployment nearly impossible. SAQ-SAM introduces a novel post-training quantization (PTQ) framework that achieves near-lossless 4-bit compression by prioritizing "semantic alignment" over simple data distribution matching, specifically tackling the extreme outliers and prompt-interaction challenges unique to SAM.

What Problem Does This Paper Address?

While SAM offers incredible zero-shot segmentation, its computational demands are prohibitive. Post-training quantization (PTQ)—the process of converting 32-bit floating-point weights to lower-bit integers—is the standard solution for model compression. However, standard PTQ methods fail on SAM for two primary reasons:

  1. Extreme Outliers: The mask decoder’s attention mechanism produces activation values with extreme outliers—sometimes 180 times the normal range. Traditional clipping methods (like MSE) try to accommodate these outliers, resulting in a "diluted" quantization range that destroys the model's precision.
  2. Semantic Misalignment: SAM is "promptable." Existing quantization methods focus on making the output values of a layer look like the original. They ignore the interaction between image features and user prompts, leading to a model that might have low numerical error but fails to follow the user's intent.
Analysis of extreme activation distributions and the impact of clipping on SAM performance.

Methods

The authors propose two primary innovations to bridge the gap between numerical accuracy and semantic performance:

  • Perceptual-Consistency Clipping (PCC): Instead of using statistical metrics like Mean Squared Error (MSE), PCC uses an Attention Focus Overlap metric. The authors discovered that SAM is surprisingly resilient to aggressive clipping as long as the "attention focus"—the regions the model deems most important—remains consistent. PCC optimizes clipping boundaries to maximize the overlap between the original and quantized attention masks.
  • Prompt-Aware Reconstruction (PAR): Standard reconstruction methods optimize layers in isolation. PAR brings the prompt into the loop, utilizing the mask decoder’s cross-attention module to supervise the learning of quantization parameters. This ensures that quantized image features still "interact" correctly with prompt tokens.
  • Layer-Skipping Strategy: To keep the reconstruction process efficient, image tokens skip subsequent layers and go directly to the interaction stage during optimization. This reduces computational overhead while maintaining high performance.

Datasets

The researchers evaluated SAQ-SAM across three major computer vision tasks using standard benchmarks:

  • Instance Segmentation: MS-COCO (using various detectors like Faster R-CNN, YOLOX, and DINO to provide prompts).
  • Oriented Object Detection: DOTA dataset (using FCOS for horizontal box prompts).
  • Semantic Segmentation: ADE20K (using SegFormer as the semantic branch).

Key Results

SAQ-SAM consistently outperforms existing state-of-the-art PTQ methods, especially in low-bit scenarios:

  • Instance Segmentation: When quantizing SAM-B to 4-bit, SAQ-SAM achieved an 11.7% to 14% higher mAP than the baseline.
  • Near-Lossless 4-bit: For larger models like SAM-L and SAM-H, the performance drop was almost negligible compared to the full-precision (FP) model.
  • Efficiency: The method provides a 3.5x to 5x acceleration in inference speed and an 8x reduction in storage requirements for 4-bit models, making them viable for resource-constrained edge devices.
Inference time breakdown for SAM variants, showing the significant computational weight of the mask decoder.

Key Insights and Ideas

  • Outliers are Distractions: In SAM's mask decoder, extreme outliers in the attention mechanism don't carry critical information for the final mask. Aggressively clipping them improves performance by increasing the resolution for the values that do matter.
  • Distribution != Meaning: A quantized model can have a similar data distribution to the original but still fail because the relationship between image and prompt is broken. SAQ-SAM shifts the focus to "matching behavior."
  • Immature Tokens are Enough: The layer-skipping strategy proves that even intermediate, "immature" features from the encoder contain enough semantic information to calibrate the interaction between images and prompts.

Limitations and Future Work

SAQ-SAM requires a small set of unlabeled calibration data (32 images). While it generalizes well across segmentation tasks, its reliance on prompt-image interaction means it is specifically tailored for models with similar interactive architectures. Future work may extend this "semantic alignment" philosophy to other foundation models like LLMs or multi-modal models where attention outliers and instruction-following are critical challenges.

Summary updated

BibTeX
@misc{zhang2025saq,
  author = {Jing Zhang and Zhikai Li and Qingyi Gu},
  title = {{SAQ-SAM: Semantically-Aligned Quantization for Segment Anything Model}},
  year = {2025},
  eprint = {2503.06515},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2503.06515},
}
Figure