TL;DR
SlimSAM is a novel, data-efficient compression framework that slims down the massive Segment Anything Model (SAM) to just 1.4% of its original parameters using only 0.1% of the original training data. By alternating between pruning decoupled sub-structures and using a novel "disturbed Taylor pruning" objective, it achieves state-of-the-art performance on resource-constrained devices without the need for massive retraining.
What Problem Does This Paper Address?
The Segment Anything Model (SAM) has revolutionized computer vision with its zero-shot segmentation capabilities. However, its massive size (641M parameters for SAM-H) and high computational demands make it nearly impossible to deploy on edge devices like smartphones or embedded systems.
Existing attempts to compress SAM generally fall into two camps:
- Training from scratch: Methods like MobileSAM or FastSAM replace the heavy ViT encoder with a lightweight one and train it using knowledge distillation. This requires massive amounts of data and compute.
- Standard Pruning: Traditional pruning removes redundant weights but often leads to a "performance cliff" when pruning ratios are high and training data is scarce.
The authors of SlimSAM identify a critical trade-off: you either need a mountain of data to train a new small model, or you suffer significant performance loss by pruning the big one. SlimSAM aims to break this trade-off, achieving high compression with minimal data.
Methods
SlimSAM introduces two pioneering contributions to the model compression toolkit:
1. Alternate Slimming Framework
Instead of pruning the entire model in one aggressive step, SlimSAM decomposes the ViT encoder into two decoupled sub-structures: embedding dimensions (the width of features between blocks) and bottleneck dimensions (intermediate features within blocks).
The framework alternates between pruning one and using the other to "align" features via knowledge distillation. This progressive approach prevents the steep performance degradation seen in single-step pruning. As shown in Figure 1, this alternating process allows for smoother knowledge inheritance.
2. Disturbed Taylor Pruning
Standard Taylor pruning relies on "hard labels" (ground truth) to estimate parameter importance. However, in distillation-based compression, we use "soft labels" (the teacher model's output). The authors found a misalignment here: the pruning objective didn't match the training target.
Furthermore, if you try to calculate gradients based on the difference between a student and a teacher that are currently identical, the gradients are zero. To solve this, they introduced Disturbed Taylor Importance. By adding a tiny amount of Gaussian noise to the teacher's embeddings, they create a non-zero gradient that allows for accurate, label-free importance estimation that is perfectly aligned with the subsequent distillation process.
Datasets
The authors utilized the SA-1B dataset, which contains 11 million images. However, the "magic" of SlimSAM is that it only requires 10,000 unlabeled images (0.1% of the total) to achieve its results. For evaluation, they used the standard SA-1B validation sets, focusing on challenging single-point prompts.
Key Insights and Ideas
- Decoupling is Key: By partitioning the model into embedding and bottleneck sub-structures, the authors could maintain "dimensionality consistency." This allows the student model to directly compare its intermediate hidden states to the teacher's, providing a much richer supervision signal than just looking at the final output.
- Alignment Matters: The "Disturbed Taylor" approach highlights that how you choose what to prune must be consistent with how you plan to fine-tune the model afterward.
- Prior Knowledge is a Goldmine: Rather than training a new lightweight architecture from scratch, SlimSAM proves that inheriting weights from a pre-trained giant like SAM-H is far more efficient, provided you have a surgical way to remove the "fat."
Key Results
SlimSAM achieves remarkable efficiency gains while staying competitive with the original SAM-H:
- Extreme Compression: SlimSAM-77 reduces parameter counts to just 1.4% (9.1M) and MACs (computational cost) to 0.8% (23G) of the original SAM-H.
- Data Efficiency: It requires 10x less data than EdgeSAM or MobileSAM, and over 1,000x less data than EfficientSAM.
- Performance: Despite the tiny footprint, SlimSAM-77 maintains an MIoU of 67.40% on SA-1B, while the 50% pruned version (SlimSAM-50) reaches 72.33%, approaching the performance of the original SAM-B (73.37%).
- Inference Speed: The model achieves up to an 8.6x speedup on an NVIDIA Titan RTX GPU compared to SAM-H.
Limitations and Future Work
The authors acknowledge a few key constraints:
- Performance Ceiling: Because the method relies on inheriting and pruning weights from the original SAM, the performance of the original model acts as a hard ceiling. SlimSAM is unlikely to surpass the teacher model.
- Hardware Constraints: While the training is data-efficient, the authors noted that their current experiments were limited by available hardware, suggesting that even better results might be possible with more comprehensive training.
- Future Directions: A promising area for future research is exploring how to break the "teacher ceiling" and achieve lossless compression or even performance improvements in a similarly data-efficient manner.
Summary updated