Learning Where to Edit Vision Transformers

Yunqiao Yang, Long-Kai Huang, Shengzhuang Chen, Kede Ma, Ying Wei · DOI

Even the most advanced Vision Transformers (ViTs) are susceptible to errors when encountering "subpopulation shifts." These shifts occur when a model encounters data that differs slightly from its training distribution—for instance, a volleyball player misclassified as a basketball player due to an unusual camera angle, or a common object rendered in an AI-generated oil painting style. While retraining from scratch is computationally prohibitive, this research, presented at NeurIPS 2024, introduces a "locate-then-edit" framework designed to surgically correct these specific errors without compromising the rest of the model's knowledge.

The Locate-then-Edit Framework

The proposed method addresses model editing by decoupling the problem into two distinct phases: identifying where to edit and determining how to edit.

Where to Edit: The Hypernetwork

Instead of manually selecting layers for modification, the authors utilize a meta-trained hypernetwork. This component processes the features of a "failure" image and generates a sparse binary mask. This mask serves as a surgical guide, pinpointing a tiny subset of parameters within the ViT's Feed-Forward Networks (FFNs) that are primarily responsible for the specific error.

How to Edit: Sparse Fine-tuning

Once the hypernetwork identifies the critical parameters via the mask, the correction is achieved through a few steps of gradient descent applied exclusively to those parameters. This targeted approach ensures that the model's behavior on unrelated data remains unchanged.

System diagram of the proposed model editing method. The hypernetwork generates a mask to select editable parameters in the FFNs of the base ViT.

Training with Pseudo-samples

A significant challenge in model editing is the scarcity of high-quality failure data. To overcome this, the authors employ CutMix to generate synthetic failures. By overlaying patches from one image onto another, they simulate distribution shifts (such as background changes). This forces the hypernetwork to learn which parameters are sensitive to these perturbations, effectively training it to recognize the "guilty" parameters in real-world failure cases.

Benchmarking and Datasets

The authors established a new benchmark specifically for ViT editing, focusing on various subpopulation shifts:

  • Natural Image Subset: 2,354 real-world images where standard ViTs fail but stronger models (like CLIP-pretrained versions) succeed.
  • AI-generated Image Subset: 1,952 images featuring art style shifts (e.g., oil paintings) and lighting shifts (e.g., stage lighting) created via Stable Diffusion.
  • Locality Set: 2,071 "hard" images from ImageNet near the model's decision boundaries, used to ensure edits do not degrade general performance.

Key Insights: FFN Sensitivity and Pareto Optimality

Research into the model's internal sensitivity revealed that not all layers are equal for editing. Through a greedy search, the authors found that editing the FFNs in layers 8–10 of a ViT-B/16 provides the optimal trade-off between fixing errors (generalization) and preserving unrelated knowledge (locality).

Greedy search results showing that editing FFNs in layers 8-10 achieves the optimal Pareto front between generalization and locality.

Furthermore, the hypernetwork demonstrates high "mask specificity." Images with similar failure causes result in highly overlapping masks, whereas unrelated failures trigger different masks. This specificity is the cornerstone of the method's ability to fix one error without affecting others.

Results and Future Directions

The proposed method achieved a nearly 100% success rate in correcting targeted errors and demonstrated a superior Pareto front compared to existing methods like T-Patcher, MEND, and ROME. By adjusting a threshold for the binary mask at test time, users can tune the model to prioritize either broader generalization or stricter locality.

While highly effective for single-example editing, future work will explore "batch-editing" to fix multiple errors simultaneously and adapt the framework for other architectures like CNNs or Swin Transformers.

Summary updated

BibTeX
@inproceedings{yang2024learning,
  author = {Yunqiao Yang and Long-Kai Huang and Shengzhuang Chen and Kede Ma and Ying Wei},
  title = {{Learning Where to Edit Vision Transformers}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2024},
  url = {https://openreview.net/forum?id=VIlyDguGEz},
}
Figure