Task Arithmetic in the Tangent Space: Improved Editing of Pre-Trained Models

Guillermo Ortiz-Jimenez, Alessandro Favero, Pascal Frossard

TL;DR

Task arithmetic—editing models by simply adding or subtracting fine-tuned weights—is a powerful but poorly understood trick for model editing. This paper reveals that its success hinges on weight disentanglement, an emergent property of pre-training where specific weight directions influence localized regions of the input space. By fine-tuning models in their linearized "tangent space," the authors significantly amplify this disentanglement, achieving state-of-the-art results in multi-task model merging and targeted forgetting.

What Problem Does This Paper Address?

Modern AI relies on massive pre-trained models, but adapting them to new tasks or fixing specific behaviors (like removing biased data) is notoriously difficult. Traditional fine-tuning often leads to "catastrophic forgetting," where a model loses its original capabilities.

"Task arithmetic" recently emerged as a "hack" to solve this: if you have a pre-trained model $\theta_0$ and fine-tune it on Task A to get $\theta_A$, the difference $\tau_A = \theta_A - \theta_0$ is a "task vector." Surprisingly, adding these vectors ($\theta_0 + \tau_A + \tau_B$) often creates a model that can do both tasks. However, nobody really knew why this worked or how to make it more reliable. This paper sets out to uncover the fundamental mechanisms behind this phenomenon.

Methods

The authors move beyond the standard non-linear training regime and explore the Neural Tangent Space. They compare three approaches:

  1. Non-linear Fine-Tuning (FT): Standard training of the original model.
  2. Post-hoc Linearization: Taking a non-linearly fine-tuned model and approximating it with a first-order Taylor expansion around its starting point.
  3. Linearized Fine-Tuning (Linear FT): Explicitly training the linearized version of the model ($f_{lin}$) from the start.

By using the Neural Tangent Kernel (NTK) framework, they formalize the concept of weight disentanglement. This property occurs when a model can be decomposed into spatially localized components that don't interfere with each other.

Figure 1: Illustration of weight disentanglement, where distinct directions in the weight space, τt, are associated with localized areas of the input space, Dt. This allows a model, f, to manipulate these areas independently by adding linear combinations of τt’s to a pre-trained checkpoint θ0.

Datasets

The study primarily uses CLIP (Vision-Language) models across eight diverse image classification benchmarks:

  • Tasks: Cars, DTD (textures), SUN397 (scenes), EuroSAT (satellite), GTSRB (traffic signs), MNIST (digits), SVHN (house numbers), and RESISC45 (remote sensing).
  • Models: Vision Transformers (ViT-B/32, ViT-B/16, ViT-L/14).
  • Extensions: The authors also validate their findings on ConvNeXt (CNN architecture) and T5 (NLP transformer).

Key Insights and Ideas

  • Disentanglement is the Secret Sauce: Task arithmetic works because pre-trained models naturally develop "weight disentanglement." Different tasks occupy different "directions" in weight space that map to disjoint regions in the function space.
  • Linearization is a Force Multiplier: While non-linear models show some disentanglement, explicitly training in the tangent space (Linear FT) amplifies this property. This makes task vectors much more "additive" and less prone to interference.
  • Pre-training is Essential: Disentanglement is not a general property of neural networks; it is an emergent property of pre-training. Models initialized randomly show almost zero disentanglement and fail at task arithmetic entirely.
  • The NTK Connection: The authors link disentanglement to the spatial localization of the NTK's eigenfunctions. In pre-trained models, these eigenfunctions are "concentrated" on specific task domains, explaining why editing one task doesn't break another.
Figure 6: Eigenfunction localization. Estimated support of the eigenfunctions of the NTK of a ViT- B/32 CLIP model trained on RESISC45. The plot shows the sum of the local energy of the eigenfunc- tions over a random subset of the training and con- trol supports (RESISC45 and Cars, respectively).

Key Results

The authors evaluated their approach on two main benchmarks: Task Addition (merging 8 tasks into one model) and Task Negation (forgetting a specific task).

  • Task Addition: Linearized FT outperformed standard non-linear FT by up to 5.8 percentage points in absolute accuracy.
  • Task Negation: Linearized models were much more effective at "forgetting" target tasks, reducing target accuracy by an additional 13.1 points compared to non-linear counterparts while maintaining performance on control tasks.
  • Scaling: As models get larger (e.g., moving from ViT-B to ViT-L), they naturally behave more linearly. Consequently, the "gap" between non-linear and linearized models closes, but the linearized approach remains superior.
Figure 5: Comparison of single-task accuracies. Linearized fine-tuning significantly reduces the "non-linear advantage," making the linearized models nearly as performant as their non-linear versions.

Limitations and Future Work

  • Computational Cost: Training and running linearized models currently requires Jacobian-vector products, which are roughly 2x more expensive in terms of memory and compute compared to standard forward/backward passes.
  • Single-Task Gap: While Linear FT closes the gap significantly, non-linear models still hold a slight edge in single-task accuracy for smaller architectures.
  • Pre-training Dynamics: The paper identifies that disentanglement emerges during pre-training but doesn't yet explain how the pre-training process (e.g., contrastive learning in CLIP) encourages this specific weight structure. Investigating these dynamics is a key direction for future research.

Summary updated

BibTeX
@inproceedings{ortizjimenez2023task,
  author = {Guillermo Ortiz-Jimenez and Alessandro Favero and Pascal Frossard},
  title = {{Task Arithmetic in the Tangent Space: Improved Editing of Pre-Trained Models}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2023},
  url = {https://openreview.net/forum?id=0A9f2jZDGW},
}
Figure