TL;DR
SAEgis is a lightweight, plug-and-play firewall that detects adversarial attacks on Vision-Language Models (VLMs) without requiring any expensive adversarial training. By embedding Sparse Autoencoders (SAEs) into a pretrained VLM, the framework exploits the sparse latent space to naturally isolate and flag attack-relevant signals. It demonstrates exceptional generalization across unseen image domains and novel attack methods, providing a highly practical safeguard for real-world VLM deployments.
What Problem Does This Paper Address?
Vision-Language Models (VLMs) are rapidly expanding into real-world applications like autonomous agents and embodied AI. However, their visual inputs introduce severe security vulnerabilities. Attackers can craft adversarial images—adding imperceptible pixel perturbations—that completely hijack the VLM's behavior, forcing it to ignore actual visual semantics and output malicious or nonsensical text.
While several adversarial detection methods exist, they suffer from two major flaws: they are rarely tested against the latest, strongest attacks, and they fail to generalize. A defense trained to detect attacks on natural images often completely falls apart when deployed on a new domain (like medical imagery) or when faced with a novel attack algorithm. SAEgis addresses this gap by providing a detection mechanism that generalizes robustly without requiring a massive dataset of attacks to train on.
Methods
The core intuition behind SAEgis is that an SAE trained purely on clean data learns to efficiently represent normal visual features. When an adversarial image is processed, it deviates from these clean patterns and abnormally activates a specific subset of sparse latent features, which the authors term attack-relevant features.
The SAEgis pipeline operates in three main phases:
- SAE Insertion & Training: A standard SAE is inserted into a pretrained VLM (such as the vision encoder or the projection layer) and trained using a basic reconstruction objective on clean images.
- Feature Selection: Using a very small set of adversarial images, the framework calculates an "attack score" for each latent feature based on its peak activation strength and spatial frequency. The top-$K$ features with the highest scores are selected as the attack-relevant feature set.
- Adversarial Detection: At inference time, the model counts how many of these top-$K$ features fire. If the activation count exceeds a specific threshold $\tau$—calibrated on a clean development set to maintain a strict false positive rate (e.g., $\alpha = 0.02$)—the input is flagged as adversarial.
To maximize robustness, the authors introduce Multi-Layer SAE Ensembling. By averaging the activation counts from SAEs placed at different depths (e.g., early vision blocks and the projection layer), the firewall can catch both low-level pixel noise and high-level semantic manipulations.
Datasets
The authors evaluated their approach using three distinct image datasets to rigorously test cross-domain generalization:
- NIPS17: A standard benchmark dataset of natural images used for non-targeted adversarial attacks.
- LLaVA-Instruct-150K (LLaVA): A widely used dataset featuring diverse natural images paired with instructions.
- Medical Multimodal Evaluation Data (Medical): A specialized dataset containing medical imagery, utilized specifically as a challenging out-of-domain evaluation target.
Key Insights and Ideas
- Anomalies Stand Out in Sparse Spaces: Unlike dense hidden states where adversarial perturbations blend into high-dimensional vectors, the sparse latent features of an SAE act like discrete semantic switches. Attacks light up specific "alarm" features that rarely fire during clean inference.
- Local vs. Global Complementarity: Early layers in the vision encoder are highly sensitive to local, high-frequency texture modifications (typical of pixel-space attacks). Deeper layers, like the projection layer, capture global semantic shifts. Ensembling them eliminates structural blind spots.
- Inherent Feature Transferability: Venn diagram analyses revealed a massive overlap in the specific attack-relevant features activated across entirely different datasets and attack types. This explains why a firewall profiled on natural images remains highly effective when processing medical scans.
Key Results
SAEgis was evaluated against state-of-the-art attacks like M-Attack and FOA-Attack, outperforming both dense representation baselines and prior attention-based detection methods (like PIP):
- In-Domain Perfection: In standard settings where training and testing occurred on the same dataset, the SAEgis Ensemble achieved near-perfect detection, hitting a 100% F1-score on NIPS17 against SSA-CWA attacks.
- Superior Cross-Domain Generalization: When transferring from LLaVA to the Medical dataset under the FOA-Attack, the dense baseline's precision plummeted to 76%. Meanwhile, the SAEgis Ensemble maintained an exceptional 97.8% precision and 95.3% F1-score.
- Data Efficiency: The framework is remarkably practical; using as few as 10 adversarial samples during the feature selection phase is enough to achieve an 80% F1-score in cross-domain detection.
Limitations and Future Work
Despite its strengths, the authors note a few limitations stemming from its clean-only calibration strategy:
- Clean Distribution Shifts: Because the detection threshold $\tau$ is calibrated strictly on a clean development set, if the clean data at deployment shifts drastically from the calibration data, it can skew the threshold—leading to higher false positives or lower recall.
- Cross-Attack Distribution Mixing: In rare cross-attack scenarios, the global feature shifts induced by a novel attack can cause the clean and adversarial feature activation distributions to overlap significantly, making clean separation difficult.
Future work will likely focus on developing adaptive thresholding techniques to dynamically adjust to clean distribution shifts in production environments.
Summary updated