Compress Any Segment Anything Model (SAM)

Juntong Fan, Zhiwei Hao, Jianqiang Shen, Shang-Ling Jui, Yi Zhang, Jing-Xiao Liao, Feng-Lei FanarXiv 2025 · DOI

Abstract

The Segment Anything Model (SAM) has set new standards for zero-shot image segmentation but faces significant deployment challenges due to its massive parameter count. We present Birkhoff, a data-free compression framework that utilizes "Hyper-Compression"—mapping high-dimensional weight vectors to low-dimensional scalars via dense trajectories. Birkhoff achieves over 5x compression with less than 1% performance loss across various SAM versions without requiring retraining or access to original datasets.

Introduction

The Segment Anything Model (SAM) and its successors (SAM2, MedSAM) have revolutionized computer vision. However, their large storage requirements—up to 2.4 GB for SAM-H—limit their use on edge devices like smartphones and autonomous systems. Traditional compression methods like quantization, pruning, and distillation often require expensive retraining or access to private training data. Birkhoff addresses these limitations by providing a versatile, data-free, and compact solution.

The Birkhoff Framework

The core of this approach is the Birkhoff algorithm, which leverages ergodic theory to perform hyper-compression.

Hyper-Compression via Dense Trajectories

Hyper-compression posits that a one-dimensional trajectory can effectively "fill" a high-dimensional space. Instead of storing high-precision weights individually, the algorithm identifies a scalar value $k$ that represents a point along a dense trajectory approximating the target parameter vector. This approach allows for significantly higher information density per stored bit compared to standard rounding-based quantization.

Conceptual illustration of a dense trajectory $T^k(x_0)$ approximating a point $x$ in high-dimensional space.

System Architecture

The Birkhoff framework consists of three main stages: Compression, Storage, and Decompression. During compression, weight matrices from linear and other layers are partitioned and mapped to low-dimensional scalars ($\theta^*$). The storage phase holds these scalars along with minimal auxiliary parameters. Finally, the decompression phase uses a custom operator to reconstruct weights for inference.

The end-to-end Birkhoff workflow, illustrating the compression of model layers into reduced parameters and their subsequent decompression via the HyperLinear operator.

Implementation: The HyperLinear Operator

To overcome the latency typically associated with decompression, the authors introduced the HyperLinear operator. This custom CUDA kernel fuses decompression and matrix multiplication. By processing weights in blocks, it optimizes L2 cache usage and allows the GPU to perform decompression and computation simultaneously, maintaining high inference speeds. This integration bypasses the memory bottlenecks that often hinder compressed model performance.

Experimental Results

Birkhoff was evaluated on 18 SAM variants using benchmarks like COCO, LVIS, and SA-1B.

  • Compression Efficiency: The framework achieved a 5.17× compression ratio on SAM2-B and consistently exceeded 4× for most models, outperforming the theoretical limits of standard INT8 quantization.
  • Performance Retention: Accuracy drops were minimal, typically under 1%. For instance, SAM-L maintained its COCO score with only a 0.33% decrease.
  • Agility: Compression is remarkably fast, taking less than 60 seconds for any model. Smaller models like EfficientSAM-Ti were compressed in just 5.33 seconds.
  • Inference Speed: The HyperLinear operator ensures that inference remains real-time. For SAM-H, the overhead was only ~5ms (a 3.9% increase).

Conclusion

Birkhoff provides a powerful, data-free path for deploying large-scale models like SAM on resource-constrained hardware. By reimagining weight storage as coordinates on a trajectory and fusing decompression with computation, it achieves high compression ratios with negligible performance loss. Future work will focus on further increasing compression ratios to surpass low-bit quantization standards while maintaining accuracy.

Summary updated

BibTeX
@misc{fan2025compress,
  author = {Juntong Fan and Zhiwei Hao and Jianqiang Shen and Shang-Ling Jui and Yi Zhang and Jing-Xiao Liao and Feng-Lei Fan},
  title = {{Compress Any Segment Anything Model (SAM)}},
  year = {2025},
  eprint = {2507.08765},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2507.08765},
}
Figure