Fine-Tuning Attention Modules Only: Enhancing Weight Disentanglement in Task Arithmetic

## Abstract

Abstract Task arithmetic has recently emerged as a cost-effective and scalable approach to edit pre-trained models directly in weight space, by adding the fine-tuned weights of different tasks. The performance has been further improved by a linear property which is illustrated by weight disentanglement. Yet, conventional linearization methods (e.g., NTK linearization) not only double the time and training cost but also have a disadvantage on single-task performance.
We propose a simple yet effective and efficient method that only fine-tunes linear layers, which improves weight disentanglement and efficiency simultaneously.
Specifically, our study reveals that only fine-tuning the linear layers in the attention modules makes the whole model occur in a linear regime, significantly improving weight disentanglement.
To further understand how our method improves the disentanglement of task arithmetic, we present a comprehensive study of task arithmetic by differentiating the role of representation model and task-specific model. In particular, we find that the representation model plays an important role in improving weight disentanglement whereas the task-specific models such as the classification heads can degenerate the weight disentanglement performance.
Overall, our work uncovers novel insights into the fundamental mechanisms of task arithmetic and offers a more reliable and effective approach to editing pre-trained models 1 1 1 The code is available at https://github.com/kyrie-23/linear_task_arithmetic . .

## 1 Introduction

The emergence of large pre-trained models in the open-source community maximizes the potential to boost performance on downstream tasks [, , ], align with human preferences [, , , , ], and enhance robustness [, , , ]. Traditional methods involve expensive joint fine-tuning across various tasks [] and reliance on human feedback [], limiting their scalability and widespread adoption. Moreover, optimizing performance for specific downstream tasks usually compromises the model’s initial pre-training performance or zero-shot accuracy [, ].

Based on the extensive resources of open-source models, we often aim to edit the pre-trained models without requiring access to additional training data, in order to improve performance on multiple downstream tasks. *Task arithmetic* [] is a method proposed for this goal. The central to task arithmetic is a concept called the *task vector* that enables models to adapt to new tasks []. A task vector can be viewed as a set of weight adjustments specifically calibrated for a given task through fine-tuning, obtained by subtracting the task-specific weights from the original pre-trained weights. Essentially, each task vector encodes a unique representational signature tailored to a particular task. The illustration of task arithmetic is shown in Figure 1.
Recent research in this domain, regarding task vector-centric approaches [, , , , ], has demonstrated that by aggregating multiple task vectors and integrating them into a pre-trained model, it is possible to create a new model, which we refer to as a unified model, and adapt it to multi-task learning.

However, task arithmetic from non-linear fine-tuning is not without limitations. For each individual task, although the unified model shows some improvement over the pre-trained model, its performance is usually not comparable to that of a model specifically trained for that task. This is because a task vector for one particular task usually has a negative effect on the performance of the other tasks. Therefore, the first question of this paper arises:

Figure: Figure 1: Illustration of task arithmetic, that is adding $\tau_{t}$ does not modify the output of model outside $D_{t}$. This allows a model to manipulate parameters independently by adding linear combinations of $\tau_{t}$ to a pre-trained checkpoint $\theta_{0}$. $g(\cdot;\omega_{k})$ refers to $k$th task-specific model parameterized by $\omega_{k}$.
Refer to caption: x1.png

*Question 1: How can we improve the performance of task arithmetic?*

Ideally, Question 1 is supposed to be resolved by weight disentanglement, where the unifined model’s performance should not be affected by other tasks when it is applied to one specific task (illustrated in the right handside of Figure 1). However, weight disentanglement is the most challenging problem in task arithmetic. It has been found that enforcing models to be fine-tuned in the tangent space significantly improves weight disentanglement, thanks to the fact that models inherently operate in a linear regime []. Here the linear regime refers to the behavior of neural networks during the beginning of the fine-tuning phase, where the network updates occur primarily around the pre-trained parameter initialization. This phenomenon is formalized by the neural tangent kernel (NTK) theory []. While NTK linearization is effective, it requires two to three times more computational resources and doubles the memory footprint compared to its nonlinear counterpart. The additional cost of NTK linearization violates the original goal of task arithmetic we described above. As a result, Question 1 boils down to the following:

*Question 2: How to improve the disentanglement and efficiency of task arithmetic simultaneously?*

To answer Question 2, we aim to propose a novel fine-tuning method with the following two properties. For disentanglement, the fine-tuning method is supposed to operate better in the linear regime. For efficiency, the fine-tuning method should only be applied to a part of the network to reduce computational cost. Hence, we propose a simple yet efficient and effective method that is to fine-tune only linear layers to achieve both of the two goals simultaneously. Specifically, our study reveals that only fine-tuning the linear layers can make the attention modules occur in a linear regime, significantly improving both weight disentanglement and accuracy compared to both nonlinear counterparts and NTK linearization [] (see Table 1). Meanwhile, our method is much more efficient, as it fine-tunes only a small portion of layers, thereby reducing the computational burden and memory usage. Additionally, our approach mitigates the non-linear advantage where non-linear fine-tuning consistently achieves the highest accuracy, offering a balanced and efficient alternative.

To further understand how our method improves the disentanglement of task arithmetic, we present a study by differentiating the role of representation model and task-specific model, while existing literature [] formulated task arithmetic using a single model without clearly differentiating them. We conduct a comprehensive study of task arithmetic in contrastively pre-trained vision-language (ViT) models like CLIP [], providing new insights into its fundamental mechanisms and proposing novel methods to improve the performance of pre-trained models through task arithmetic.
Specifically, we illustrate that the representation model plays an important role in improving weight disentanglement whereas this has been constrained by task-specific models, such as classification heads.

Notably, we demonstrate that the attention module lies in a strong linear regime within its linear layers. Without any prior knowledge, we can achieve superior performance to the current state-of-the-art methods by simply fine-tuning all linear layers in the attention module. However, the performance can either improve or degrade depending on whether the bias parameters are fine-tuned. The best results are obtained when the settings align closely with those used in LoRA [], which fine-tunes only $Q,K,V$, and output projection weights, indicating that this aspect warrants further exploration.

In particular, our main contributions are as follows:

- •
We propose a simple yet effective and efficient method that only fine-tunes linear layers, which improves weight disentanglement and multi-task performance up to 2.38% improvement compared to the state-of-the-art methods and 8.37% over the nonlinear baseline on several vision-language benchmarks.
- •
We demonstrate that fine-tuning all linear layers within the attention module occurring in a linear regime, without selectively freezing or omitting certain layers achieves superior performance compared to current state-of-the-art methods on this benchmark task.
- •
We reformulate the architecture of task arithmetic in [] into a representation model and several task-specific models, aligning our notation with previous work. This allows us to more clearly illustrate their individual contributions.
- •
We illustrate that the representation model plays an important role in improving weight disentanglement, whereas the effectiveness of task arithmetic has been constrained by the task-specific models, such as classification heads.

Overall, our work provides new insights into the fundamental mechanisms of task arithmetic, enhancing the reliability and scalability of model editing. Our findings indicate that fine-tuning pre-trained models, particularly focusing on the orthogonality of task vectors, deserves further investigation due to its significant potential for improving model editing effectiveness. These insights can lead to the development of more efficient and accurate model editing techniques, enabling practitioners to adapt pre-trained models to a wider array of tasks.

## 2 Task arithmetic is a reflection of weight disentanglement

Existing literature [] formulated task arithmetic using a single model, which actually combines a representation model (e.g., CLIP) with several task-specific models (e.g., classification heads). This combination leads to different pre-trained parameters $\theta_{0}$ for each task due to the use of different task-specific models (e.g., different classification heads for different datasets). The implementation of task arithmetic focuses on the representation model, extracting task vectors, fine-tuning, and replacing different task-specific models.

To better understand the relationship between the representation model and the task-specific models, we separate their definitions. This allows us to more clearly illustrate their individual contributions to task arithmetic. We formulate the task arithmetic property along with weight disentanglement, providing distinct definitions for the representation and task-specific models while aligning our notation with previous work.

Let $F:\mathcal{X}\times\Theta\rightarrow\mathcal{Y}$ be a neural network taking inputs $x\in\mathcal{X}$ and parameterized by a set of weights $\vartheta\in\Theta$, which consists of a representation model $f(\cdot;\theta)$ and a task-specific model $g(\cdot;\omega)$ where $\vartheta=\{\theta,\omega\}$. We will assume $\mathcal{X}\subseteq\mathbb{R}^{d}$, $\Theta\subseteq\mathbb{R}^{m}$ and $\mathcal{Y}\subseteq\mathbb{R}^{c}$. Consider $T$ tasks, with every task $t$ consisting of a triplet $(D_{t},\mu_{t},F_{t}^{*})$, where $D_{t}\subseteq\mathcal{X}$ is a data support (e.g., ImageNet [] images), $\mu_{t}$ an input distribution such that $\text{supp}(\mu_{t})=D_{t}$, and $F_{t}^{*}:D_{t}\rightarrow\mathcal{Y}$ a target function (e.g., labels). In practice, each task is identified with a training set $\{(x_{v},F_{t}^{*}(x_{v}))\}_{v\in[n]}$ where $F_{t}^{*}(x_{v})=g(f(x_{v};\theta_{t}^{*});\omega_{t})$ with $x\sim\mu_{t}$, that is used to fine-tune the representation models starting from the pre-trained weights $\theta_{0}$ and obtain the fine-tuned weights $\theta_{t}^{*}$, while the task specified models are fixed at $\omega_{t}$.

Task arithmetic. Let the task vector of task $t$ be the difference between the fine-tuned and the pre-trained weights, i.e., $\tau_{t}=\theta_{t}^{*}-\theta_{0}$. The following property formalizes the notion of task arithmetic introduced in Ortiz-Jimenez et al. [], where the authors observed that the accuracies of pre-trained models on different datasets can be modified independently through the addition or removal of task vectors.

###### Property 1 (Task arithmetic)

Consider a set of task vectors $T=\{\tau_{t}\}_{t\in[T]}$ with associated non-intersecting task supports $D=\{D_{t}\subset\mathcal{X}\}_{t\in[T]}$, i.e., $\forall t,t^{\prime}\text{ if }t\neq t^{\prime}\text{ then }D_{t}\cap D_{t^{
\prime}}=\emptyset$. We say a network $F$ satisfies the task arithmetic property around $\vartheta_{0}$ with respect to $T$ and $D$ if

$$ $\displaystyle F\left(x;\vartheta_{0}+\sum_{t=1}^{T}\alpha_{t}\tau_{t}\right)= \begin{cases}F(x;\vartheta_{0}+\alpha_{t}\tau_{t})&\text{if }x\in D_{t},\\ F(x;\vartheta_{0})&\text{if }x\notin\bigcup_{t=1}^{T}D_{t},\end{cases}$ (1) $$

where $\vartheta_{0}=\{\theta_{0},\omega_{t}\}$ and $\vartheta_{0}+\alpha_{t}\tau_{t}=\{\theta_{0}+\alpha_{t}\tau_{t},\omega_{t}\}$ in certain task $t$,
with $(\alpha_{1},\ldots,\alpha_{T})\in\mathcal{A}\subseteq\mathbb{R}^{T}$.

In short, a model satisfies Property 1 if adding $\tau_{t}$ does not modify the output of the model outside $D_{t}$.

###### Property 2 (Weight disentanglement)

A parametric function $F:\mathcal{X}\times\Theta\rightarrow\mathcal{Y}$ is weight disentangled with respect to a set of task vectors $T=\{\tau_{t}\}_{t\in[T]}$ and the corresponding supports $D=\{D_{t}\}_{t\in[T]}$ if

$$ $\displaystyle F\left(x;\vartheta_{0}+\sum_{t=1}^{T}\alpha_{t}\tau_{t}\right)=F (x;\vartheta_{0}+\alpha_{t}\tau_{t})\mathds{1}(x\in D_{t})+F(x;\vartheta_{0}) \mathds{1}\left(x\notin\bigcup_{t\in[T]}D_{t}\right).$ $$

From Property 1 and Property 2 we can see that weight disentanglement is not necessarily linked to performance on various tasks. In other words, a model can achieve weight disentanglement relative to a group of task vectors but still underperforms on a given task. For example, if $f(\cdot;\theta_{0}+\alpha\tau)$ does not generalize well for some $\alpha$, the model may still fail to perform effectively despite being weight disentangled [].

###### Property 1 (Task arithmetic)

###### Property 2 (Weight disentanglement)

## 3 Fine-tuning linear layers only is much more efficient than NTK linearization

The objective of this work is to illustrate the relationship between the linear regime while fine-tuning ViT models (attention module) and task arithmetic performance. Existing work [] demonstrated that the linear regime is not necessary for task arithmetic, but models within the linear regime exhibit superior disentanglement performance.

We have seen that linearized models are more weight-disentangled than non-linear ones[]. However, NTK linearization often degrades single-task performance, which is demonstrated as a non-linear advantage. In this study, we show that fine-tuning only the linear layers significantly improves task arithmetic performance by reducing the single-task accuracy gap. This approach maintains the benefits of weight disentanglement while enhancing the overall effectiveness of task arithmetic across various settings.

Neural tangent kernel. Around the initialization weights $\theta_{0}$, a representation model $f(x;\theta)$ can be approximated with a first-order Taylor expansion:

$$ $\displaystyle f(x;\theta)=f(x;\theta_{0})+(\theta-\theta_{0})^{\top}\nabla_{ \theta}f(x;\theta_{0})+\text{higher order terms}.$ (2) $$

This approximation is equivalent to the neural tangent kernel (NTK) [], $k_{\text{NTK}}(x,x^{\prime})=\nabla_{\theta}f(x;\theta_{0})^{\top}\nabla_{
\theta}f(x^{\prime};\theta_{0})$, and defines a neural tangent space in which the relationship between weights and functions is linear. However, this linear approximation is often invalid at finite widths, as the evolution of parameters during training is inadequately captured by Eq. (2). In such cases, training occurs in a non-linear regime. Conversely, often during fine-tuning, parameter evolution in many pre-trained models is frequently minimal, meaning that training does not exit the tangent space and Eq. 2 closely approximates the network behavior []. In such cases, training occurs in a linear regime.

Specifically, rather than constraining models to fine-tune within the tangent space as proposed by [], we enhance the linear regime within the attention module, which naturally arises from the linear architecture. This enhancement leverages the inherent properties of linear layers to simplify the model’s adaptation process. By fine-tuning only a select number of linear layers, the model not only lies in a pronounced linear regime but also maintains computational efficiency. This approach achieves performance levels comparable to full fine-tuning while significantly reducing the complexity and resources required.

Figure: Figure 2: Three types of fine-tuning paradigms. (a) Full parameter fine-tuning where all the parameters will be updated. (b) Full-model linearization. (c) Linear layers only fine-tuning where only $W_{q}$, $W_{v}$, $W_{k}$ and $W_{o}$ will be updated. In this paper, we explore linear layers only fine-tuning.
Refer to caption: x2.png

Figure 2 illustrates three different types of fine-tuning paradigms. The first two are existing methods, while the third is our proposed partial linearization fine-tuning method. (a) The full fine-tuning paradigm where all parameters $\theta$ are updated during fine-tuning. (b) The full-model linearization paradigm where we fine-tune the model in the tangent space. It is worth noting that although the Jacobian-vector products can be computed in a single forward pass [], training and inference in this paradigm are usually twice or three times as expensive as full fine-tuning []. (c) The linear layers only fine-tuning paradigm in which only a small number of linear layers are updated, which exhibits a linear regime, which is similar to linear fine-tuning. This approach incurs only a fraction of the training and inference costs compared to NTK linearization.

Figure: Figure 3: Single-task averaged accuracies of non-linear and linear models. The diagonal dashed line indicates linear fine-tuning performance meets non-linear.
Refer to caption: x3.png

The results in Figure 3 indicate that our method reduces the gap between linear and non-linear models and has a better performance than NTK linearization respectively(^2^22Please see Appendix B.1 for performance on each task). Specifically, we fine-tune (FT) several CLIP pre-trained ViTs [] of different sizes following the same setup as Ilharco et al. [] on 8 tasks: Cars [], DTD [], SUN397 [], EuroSAT [], GTSRB [], MNIST [], SVHN [] and RESISC45 []. The round dots represent the comparison between our method and non-linear models, while the triangle dots show the comparison between NTK linearization and non-linear models. The proximity of dots to the diagonal dashed line indicates the accuracy of the linearization method. Our method, represented by round dots, consistently appears closer to the diagonal dashed line than the NTK linearization (triangle dots), suggesting superior performance.

Even though NTK linearization models exhibit a linear regime and achieve impressive disentanglement performance, they omit higher-order terms, leading to accumulated errors as the number of tasks increases. To address this, we propose leveraging linear layers to enhance disentanglement performance. Our method retains the benefits of NTK linearization while mitigating the drawbacks associated with neglected higher-order terms. By fine-tuning the linear layers within the attention module, we improve computational efficiency and robustness across multiple tasks.

Considering a completely linear representation model $f$, we can easily determine that $\nabla_{\theta}f(x;\theta_{0})=x$. This foundational insight supports our approach, as the gradient with respect to the parameters simplifies to the input data itself. Thus, by fine-tuning only the linear layers, we enhance weight disentanglement and maintain model efficiency without extensive retraining, aligning with the concept of weight disentanglement to improve performance across various tasks.

###### Proposition 1 (Orthogonality between Vectors and Data Points)

For a linear representation model $f$, the gradient with respect to the parameters is given by $\nabla_{\theta}f(x;\theta_{0})=x$. Therefore, the model can be expressed as:

$$ $\displaystyle f(x;\theta)=f(x;\theta_{0})+(\theta-\theta_{0})^{\top}x.$ (3) $$

For a specific task $t=i$, the function $f$ can be further expressed as:

$$ $\displaystyle f\left(x;\theta_{0}+\sum_{t=1}^{T}\tau_{t}\right)=f(x;\theta_{0} +\tau_{i})+\sum_{t\neq i}\tau_{t}^{\top}x.$ $$

When $\sum_{t\neq i}\tau_{t}^{\top}x\to 0$, weight disentanglement is achieved.

Proposition 1 implies that the orthogonality of data points $x$ and task vectors $\tau_{t}$ leads to perfect disentanglement. This allows for the evaluation of cosine similarity between data points and task vectors, providing a clear advantage over NTK linearization, where such perfect disentanglement is not guaranteed.

Inspired by LoRA [] which should be considered as a special form of linearization, we choose the matrix of $Q,K,V$, and the output projection.
Concentrating on attention modules, give an example of a single attention layer as applied in Vaswani et al. [], due to the linear property of the weight matrix, we can easily get a disentangle output from each attention head for a certain task $i$:

$$ head $\displaystyle=\text{Attention}(qW^{Q},kW^{K},vW^{V})$ $\displaystyle=\text{Attention}(Q_{i}+\sum_{t\neq i}q_{i}W^{Q}_{t},K_{i}+\sum_{ t\neq i}k_{i}W^{K}_{t},V_{i}+\sum_{t\neq i}v_{i}W^{V}_{t})$ $\displaystyle=\text{Attention}(Q_{i},K_{i},V_{i}),$ $$

where $q,k,v$ represent the query, key, value input, $W^{Q},W^{K},W^{V}$ represent each weight, e.g. $Q_{i}=q(W_{0}+W^{Q}_{i})$, $W^{Q}=W^{Q}_{0}+\sum_{t}W^{Q}_{t}$.

**Table 1: Task addition. Average absolute (%) and normalized accuracies (%) of different ViTs edited by adding the sum of the task vectors of 8 tasks. We report results for the non-linear and linearized models normalizing performance by their single-task accuracies.**
| Method | ViT-B-32 | ViT-B-16 | ViT-L-14 |  |  |  |
| --- | --- | --- | --- | --- | --- | --- |
| Abs.($\uparrow$) | Norm.($\uparrow$) | Abs.($\uparrow$) | Norm.($\uparrow$) | Abs.($\uparrow$) | Norm.($\uparrow$) |  |
| Pre-trained | 48.40 | - | 55.25 | - | 66.40 | - |
| Non-linear | 70.00 | 77.04 | 74.75 | 80.59 | 84.40 | 89.47 |
| Linear | 76.26 | 85.82 | 79.01 | 86.32 | 85.53 | 91.44 |
| Ours | 78.37 | 87.42 | 80.44 | 87.25 | 87.91 | 93.66 |

Remarkably, as we show in Section 4, this increase in single-task performance does not compromise weight disentanglement, instead, it’s much higher than NTK linearization. As a result, linear fine-tuning allows for improved task arithmetic compared to standard non-linear fine-tuning.
To better illustrate the multi-task performance, we employ the benchmark proposed by Ilharco et al. [] to evaluate the task arithmetic ability of a pre-trained model, which consists of the 8 tasks described before:
The sum of the task vectors $\tau=\sum_{t}\tau_{t}$ is added to a pre-trained checkpoint to produce a multi-task model. The success of this benchmark is measured in terms of the maximum average accuracy over the different tasks. Results are shown in Table 1.
In contrast to recent work [, ], our method focuses on the original task arithmetic setting, evaluating multi-task performance and further examining weight disentanglement, which does not require access to all test data and is not in a parameter-efficient setting either.

To obtain the task vectors, we use the fine-tuned weights of different ViTs from before, and use a single mixing coefficient $\alpha=\alpha_{1}=\dots=\alpha_{T}$ optimized separately for each fine-tuning paradigm to ensure a fair comparison. We provide all the details of this experiment in Appendix A.

In particular, Table 1 in its last rows shows that our method significantly outperforms its non-linear counterparts [] and achieves state-of-the-art results on the task addition benchmarks. Our model achieves higher multi-task accuracies through task addition (up to 2.38% more). Additionally, our method not only outperforms on averaged accuracy but also on normalization accuracy.

In addition to input and output projection layers, can we improve disentanglement performance by fine-tuning all linear layers in the attention module, and how would performance go when bias parameters are also fine-tuned? To dig into this question, we conduct an ablation experiment with four paradigms: (1) only fine-tuning $Q,K,V$, and output layer weights (ours), (2) fine-tuning $Q,K,V$, and output layer weights and bias, (3) fine-tuning all linear layers weights in the attention module, (4) fine-tuning all linear layers weights and bias in the attention module.

**Table 2: Single-task and multi-task performance (%) on four different settings.**
| Paradigm | Single-task | Multi-task |  |
| --- | --- | --- | --- |
| Accuracy($\uparrow$) | Abs.($\uparrow$) | Norm.($\uparrow$) |  |
| (1) | 89.55 | 78.37 | 87.42 |
| (2) | 89.48 | 77.71 | 86.79 |
| (3) | 88.95 | 76.52 | 86.11 |
| (4) | 89.43 | 77.80 | 86.93 |

Surprisingly, all four paradigms outperform NTK linearization in both performance and disentanglement, demonstrating that ViT models exhibit a strong linear regime within the linear layers of the attention module (see Table 2). However, the performance can either improve or degrade depending on whether the bias parameters are fine-tuned. The best results are achieved when the settings align closely with those used in LoRA, suggesting that this is an area deserving further exploration.

###### Proposition 1 (Orthogonality between Vectors and Data Points)

## 4 Weight disentanglement emerges from representation model

Existing works demonstrate the effectiveness of task arithmetic primarily in the context of downstream tasks. However, the reliance on downstream tasks and task-specific models may limit the generalizability and scalability of these methods. To further illustrate the power of task arithmetic and broaden its applicability, we aim to investigate whether the representation model itself can satisfy Property 3 without the need for a task-specific model.

Unlike the approach outlined in Section 2, we redefine task arithmetic and weight disentanglement within the representation model itself. Our hypothesis is that pre-trained models can exhibit task arithmetic properties independently of downstream tasks, maintaining a similar representation through task arithmetic. By focusing on the representation model alone, we seek to show that the inherent properties of the pre-trained models are sufficient to support task arithmetic, potentially simplifying the process and broadening its applicability.

Figure: Figure 4: Visualization of weight disentanglement. The heatmaps show the disentanglement error $\xi(\alpha_{1},\alpha_{2})$ of a single representation model CLIP ViT-B/32 (top) and a combination of representation model and classification model (bottom) on DTD - SUN397 task pair. Three fine-tuning paradigms are used from left to right: standard, NTK linearization, and ours. The light regions denote areas of the weight space where weight disentanglement is stronger.
Refer to caption: x4.png

###### Property 3 (Task arithmetic*)

Consider a set of task vectors $T=\{\tau_{t}\}_{t\in[T]}$ with associated non-intersecting task supports $D=\{D_{t}\subset\mathcal{X}\}_{t\in[T]}$, i.e., $\forall t,t^{\prime}\text{ if }t\neq t^{\prime}\text{ then }D_{t}\cap D_{t^{
\prime}}=\emptyset$. We say a representation model $f$ satisfies the task arithmetic property around $\theta_{0}$ with respect to $T$ and $D$ if

$$ $\displaystyle f\left(x;\theta_{0}+\sum_{t=1}^{T}\alpha_{t}\tau_{t}\right)= \begin{cases}f(x;\theta_{0}+\alpha_{t}\tau_{t})&\text{if }x\in D_{t};\\ f(x;\theta_{0})&\text{if }x\notin\bigcup_{t=1}^{T}D_{t}.\end{cases}$ $$

###### Property 4 (Weight disentanglement*)

A parametric function $f:\mathcal{X}\times\Theta\rightarrow\mathcal{Y}$ is weight disentangled with respect to a set of task vectors $T=\{\tau_{t}\}_{t\in[T]}$ and the corresponding supports $D=\{D_{t}\}_{t\in[T]}$ if

$$ $\displaystyle f\left(x;\theta_{0}+\sum_{t=1}^{T}\alpha_{t}\tau_{t}\right)=\sum _{t=1}^{T}f(x;\theta_{0}+\alpha_{t}\tau_{t})\mathds{1}(x\in D_{t})+f(x;\theta_ {0})\mathds{1}\left(x\notin\bigcup_{t\in[T]}D_{t}\right).$ (4) $$

Instead of evaluating weight disentanglement on predictors, weight disentanglement is a property of the representation models and is not related to the performance on different tasks. That is, a model could be weight disentangled with respect to a set of task vectors and still perform poorly on a task, e.g., if $f(\cdot;\theta_{0}+\alpha\tau)$ does not generalize for some $\alpha$. More generally, we can visualize the level of weight disentanglement of a model by measuring its discrepancy with Eq. (4). To do so, given two tasks, one can check the disentanglement error of a model,

$$ $\displaystyle\xi(\alpha_{1},\alpha_{2})=\sum_{t=1}^{2}\mathbb{E}_{x\sim\mu_{t} }\left[\text{dist}\left(f(x;\theta_{0}+\alpha_{t}\tau_{t}),f(x;\theta_{0}+ \alpha_{1}\tau_{1}+\alpha_{2}\tau_{2})\right)\right],$ $$

where dist denotes any distance metric between output vectors. As we are dealing with representation distributions, in what follows we use the KL divergence as the distance metric (^3^33We use prediction error for the combined model for classification task as Ortiz-Jimenez did [].). In general, the smaller the value of $\xi(\alpha_{1},\alpha_{2})$ the more weight disentangled a model is at $(\alpha_{1},\alpha_{2})$.

Figure 4 displays the disentanglement error of a CLIP ViT-B/32 model concerning several task vector pairs. We observe that the ViT model exhibits a minimal disentanglement error within a small region surrounding $\theta_{0}$, which enables task arithmetic.
Different from disentanglement error at downstream tasks, it remains relatively small even for $\alpha_{1},\alpha_{2}>1$, which indicates the power of task arithmetic has been limited by the performance of task-specific models (classification head).

Comparing the disentanglement error of our models and NTK linearization reveals an interesting finding: linearized models exhibit greater disentanglement than their non-linear counterparts. This is evident from the more extensive regions with low disentanglement errors in Figure 4 (right). This explains why the linear layers fine-tuning only models achieve higher normalized accuracies via task addition (cf. Table 1). The combination of greater disentanglement and better single-task performance comes with higher multi-task performance.

The results in Figures 5 show the cosine similarity between task vectors from ViT, which are three types of fine-tuning (cf. Figure 2) on image classification tasks. We observe that vectors from linear layers only fine-tuning are closer to orthogonal than those from both standard and NTK linearization, which indicates that models fine-tuned with full fine-tuning are more independent than others. This finding is consistent with the discussion about task addition in [, ], the experimental results from Table 1 also support our statement. The experimental details are described in Appendix.

Figure: Figure 5: Similarity heatmaps. These figures show heatmaps of the cosine similarity between task vectors from task-specific CLIP models [] fine-tuned on different tasks. Three fine-tuning paradigms from left to right: Full parameter fine-tuning (Standard), Full-model linearization (NTK linearization), and Linear layers only fine-tuning (Ours).
Refer to caption: x5.png

###### Property 3 (Task arithmetic*)

###### Property 4 (Weight disentanglement*)

## 5 Related work

Weight Interpolation and Task Arithmetic.
Recent research has explored the use of interpolations between model weights and task arithmetic to manipulate and enhance the capabilities of pre-trained models. Studies have shown that interpolating between a model’s fine-tuned weights and its pre-trained initialization can improve performance on single tasks, often surpassing the accuracies achieved through fine-tuning alone [, , , , , ]. In multi-task settings, averaging the parameters of multiple fine-tuned models has been proposed to create superior multi-task models [, , , , ], which help avoid catastrophic forgetting [, , , ] and provide better starting points for subsequent fine-tuning [, ]. These benefits also extend to models trained from scratch, provided they are properly aligned before merging [, ]. This technique has been observed to enhance downstream performance, highlighting the potential of weight interpolation and task arithmetic.

Model Fusion Techniques.
Model fusion integrates knowledge from multiple models into a single unified model. One approach focuses on fusing entire models through weight interpolation. By averaging or combining the weights of multiple models, effective model fusion can be achieved, as demonstrated in prior works [, , , , , ]. When models are not well-aligned or lie in different loss basins, feature alignment techniques are employed before fusion to match the models’ behaviors or transform them to a similar loss basin [, ]. Although fusing entire models leverages knowledge from all layers, it can be computationally expensive.

Advances in Model Merging for MTL.
Model merging has emerged as a promising solution to enhance model generalization and facilitate multi-task learning (MTL). Research in this area includes merging models trained on the same task to improve overall generalization [, ] or to perform federated learning [, ]. Another approach focuses on merging models for different tasks to enable MTL [, , , , , , ]. However, simple model averaging can significantly deteriorate performance across multiple tasks. To address this, advanced techniques have been developed. For example, Fisher Merging uses the Fisher information matrix to measure the importance of individual model parameters and guide model merging []. Although effective, computing the Fisher information matrix is computationally and memory-intensive.

## 6 Conclusion

In this work, we conducted a thorough analysis of task arithmetic in deep neural networks, delving into its fundamental mechanisms and enhancing its performance. Our findings demonstrate that attention module lies in a strong linear regime within its linear layers, which improve both disentanglement and efficiency.

Understanding the nuanced impact of fine-tuning bias on model performance and disentanglement remains an open question. Future research could provide valuable insights into optimizing these settings, potentially leading to more robust and efficient methods for adapting pre-trained models to various tasks. This could significantly enhance their applicability and effectiveness in real-world scenarios.

## Appendix A Experimental details

All our experiments were performed using the same hardware consisting of four 3090 NVIDIA GPUs with 24GB of memory each which can be reproduced in less than 150 GPU hours. The details of each experiment are the following.

Datasets.
We evaluate task arithmetic on a set of popular benchmark datasets from various domains. The dataset collection includes:

- •
SVHN []: The Street View House Numbers dataset is a real-world image dataset for developing machine learning and object recognition algorithms with minimal requirement on data preprocessing and formatting.
- •
MNIST []: A database of handwritten digits, with 60,000 training images and 10,000 testing images.
- •
EuroSAT []: A dataset based on Sentinel-2 satellite images covering 13 spectral bands, with 10 classes and a total of 27,000 labeled and geo-referenced images.
- •
RESISC45 []: The remote sensing image scene classification dataset, consisting of 31,500 images in 45 scene classes.
- •
Cars []: This dataset contains images of cars categorized into various fine-grained classes. It is widely used for fine-grained image classification tasks, providing a rich set of vehicle images for training and evaluation.
- •
DTD (Describable Textures Dataset) []: This dataset is designed for texture recognition and categorization. It consists of texture images organized into 47 categories, each labeled with attributes describing the texture patterns. It is commonly used to evaluate texture recognition algorithms.
- •
SUN397 []: The Scene UNderstanding (SUN) dataset is a large-scale dataset for scene recognition, containing 397 categories with a total of over 100,000 images. It is used to evaluate scene understanding models and to benchmark scene classification algorithms.
- •
GTSRB (German Traffic Sign Recognition Benchmark) []: This dataset comprises images of German traffic signs, classified into over 40 categories. It is used to develop and evaluate traffic sign recognition systems, particularly in the context of autonomous driving and intelligent transportation systems.

Fine-tuning.
All the fine-tuning experiments follow the same training protocol specified in Ilharco et al. [] with minor modifications to the training code to use linearized models when needed. In particular, we fine-tune all datasets starting from the same CLIP pre-trained checkpoint downloaded from the open_clip repository []. We fine-tune for 2,000 iterations with a batch size of 128, a learning rate of $10^{-5}$ and a cosine annealing learning rate schedule with 200 warm-up steps and the AdamW optimizer []. As introduced in Ilharco et al. [], during fine-tuning, we freeze the weights of the classification layer obtained by encoding a standard set of zero-shot template prompts for each dataset. Freezing this layer does not harm accuracy and ensures that no additional learnable parameters are introduced during fine-tuning []. We use this exact same protocol to fine-tune the non-linear and linearized models and do not perform any form of hyperparameter search in our experiments.

Tuning of $\alpha$ in task arithmetic benchmarks.
As in Ilharco et al. [], we use a single coefficient $\alpha$ to tune the size of the task vectors used to modify the pre-trained models. This is equivalent to setting $\alpha=\alpha_{1}=\ldots=\alpha_{T}$ in Eq. 1. In the task addition benchmarks, after fine-tuning, we evaluate different scaling coefficients $\alpha\in\{0.0,0.05,0.1,\ldots,1.0\}$ and choose the value that achieves the highest target metric on a small held-out proportion of the training set as specified in Ilharco et al. []. Namely, maximum normalized average accuracy, and minimum target accuracy on each dataset that still retains at least 95% of the accuracy of the pre-trained model on the control task. The tuning of $\alpha$ is done independently for non-linear FT, linearized FT, and post-hoc linearization.

Normalized accuracies in task addition.
Table 1 shows the normalized accuracies after editing different models by adding the sum of the task vectors on 8 tasks $\tau=\sum_{t}\tau_{t}$. Here, the normalization is performed with respect to the single-task accuracies achieved by the model fine-tuned on each task. Mathematically,

$$ $\text{Normalized accuracy}=\frac{1}{T}\sum_{t=1}^{T}\frac{\left[\text{acc} \left(f(x;\theta_{0}+\sum_{t}\tau_{t})\right)\right]}{\left[\text{acc}\left(f( x;\theta_{0}+\tau_{t})\right)\right]}.$ (5) $$

Disentanglement error.
To produce the weight disentanglement visualizations of Figure 4, we compute the value of $\xi(\alpha_{1},\alpha_{2})$ on a $15\times 15$ grid of equispaced values in $[-2,2]\times[-2,2]$. To estimate the disentanglement error, we use a random subset of 2,048 test points for each dataset.

## Appendix B Further experimental results

We now present additional experiments that expand the findings discussed in the main text.

Figure: (a) ViT-B/32
Refer to caption: x6.png

### B.1 Fine-tuning accuracies

In Figure 6, we report the single-task accuracies achieved by different CLIP models after fine-tuning with different dynamics (referred to as non-linear, NTK linearization, and our method).

### B.2 Weight disentanglement on different task pairs

In Figure 7, we illustrate weight disentanglement on different task pairs.

Figure: Figure 7: Visualization of weight disentanglement. The heatmaps show the disentanglement error $\xi(\alpha_{1},\alpha_{2})$ of a single representation model CLIP ViT-B/32 (top) and a combination of representation model and classification model (bottom) on Cars - RESISC45 task pair. Three fine-tuning paradigms are used from left to right: standard, NTK linearization, and ours. The light regions denote areas of the weight space where weight disentanglement is stronger. The red box delimits the search space used to compute the best $\alpha$ in all our experiments.
Refer to caption: x9.png

## Appendix C Impact Statement

This paper presents work whose goal is to advance the field of Machine Learning. There are many potential societal consequences of our work, none which we feel must be specifically highlighted here.

## Peer Reviews

confidence: 3
contribution: 3
initial_rating: 8
presentation: 3
questions: See the weaknesses.
soundness: 3
strengths: The paper is well-organized and clearly written. The authors thoughtfully introduce relevant prior work, providing clear definitions and context for task arithmetic, weight disentanglement, and their associated challenges. Each argument is well-supported, with compelling visualizations that reinforce the method's performance. The progression from motivation to methodology is logical and engaging.
summary: This paper presents a method that fine-tunes only the attention modules of models to enhance weight disentanglement in task arithmetic. Task arithmetic is a training-free approach that enables new tasks by linearly combining the weights of a task-specific model with those of the original model. Building on NTK studies on kernel behaviour, the proposed method introduces an approximate kernel behaviour test to verify that attention modules exhibit this characteristic. The authors validate their hypothesis by fine-tuning only the attention modules in CLIP models, showing that this approach outperforms other fine-tuning strategies as well as the original NTK-initialization method.
weaknesses: The paper has no prominent weaknesses. Here are some other open questions:
 
1. Contribution of Individual Attention Modules. 
While the method targets attention modules to achieve weight disentanglement, it remains unclear whether each module contributes equally to task performance. In large models, which may have over 100 billion parameters, understanding the relative contribution of each attention module could make the approach more efficient, possibly allowing for sparse fine-tuning of only the most impactful modules. An analysis or ablation study on the importance of individual modules could provide further insights into how weight disentanglement varies within the attention layers.

2. Generalizability to Non-Attention-Based Architectures. 
While the method demonstrates promising results on attention-based models, it would be useful to discuss the potential for generalizing this approach to non-attention architectures, such as convolutional or Mamba-based models. Would the same strategy apply effectively, or would alternative fine-tuning techniques be required for architectures without attention mechanisms? Providing an outlook on this point could help extend the paper's relevance across a wider variety of model architectures.

---

confidence: 4
contribution: 1
initial_rating: 3
presentation: 3
questions: Refer to the weaknesses section.
soundness: 2
strengths: 1. The paper is easy to follow and provides clear explanations of essential concepts, making it easier to understand both the proposed approach and the fundamentals of task arithmetic.
summary: The paper addresses task interference issues in task arithmetic, which arise when combining weights from multiple tasks into a single unified model. To tackle this issue, it uses Neural Tangent Kernel (NTK) linearization and trains only the attention layers in the transformer to reduce training costs. Through several experiments, the paper demonstrates the efficiency of the proposed approach and explains task arithmetic by distinguishing the roles of the representation module and the task-specific module.
weaknesses: 1. The paper appears to be a naive combination of prior work, specifically [1] and [2], with modifications focused on training parameter selection (e.g., training only the attention layers in transformers), which limits its novelty.

[1] Multitask prompted training enables zero-shot task generalization (ICLR 2023)
[2] Task arithmetic in the tangent space: Improved editing of pre-trained models (NeurlPS 2024)

2. The main contribution claimed by the authors—asserting that weight disentanglement primarily arises from the representation module while the effectiveness of task arithmetic is constrained by task-specific components—is not well-supported. Additional ablation studies, analysis, or theoretical support are needed to substantiate this claim. Depending on interpretation, the proposed contribution may be a trivial insight already known in the fields of task arithmetic or multi-task learning.

3. The experiments are quite limited, as many related works cited by the authors are missing from the experimental results, particularly in Tables 2 and 3. This omission reduces the validity of the proposed method.

4. The paper's theoretical contributions rely heavily on [2], which limits its originality and overall contribution.

---

confidence: 3
contribution: 3
initial_rating: 6
presentation: 4
questions: While the paper mentions some related work, the relationship to existing methods could be discussed in more detail, especially the latest advances in model fusion and weight interpolation.
soundness: 3
strengths: Innovation: The proposed method of fine-tuning only the attention module is innovative in the field of task arithmetic and can effectively solve the weight decoupling problem.
Experimental design: The experimental part covers multiple data sets and tasks, enabling a comprehensive evaluation of the effectiveness of the proposed method.
The results are remarkable: the method proposed in the paper achieves better performance than existing techniques on multiple benchmarks.
summary: This paper proposes a new method to enhance weight decoupling in task arithmetic by fine-tuning only the attention module in the Transformer model. This method improves the weight decoupling ability of the unified model while maintaining the performance of individual models, thereby improving the performance of task arithmetic.
weaknesses: Parameter sensitivity analysis: The paper mentions the effect of the choice of α coefficient on performance, but does not provide a detailed sensitivity analysis. It is recommended to add experiments on the effect of the choice of α coefficient on model performance.
Computational resource consumption: The paper mentions the efficiency advantage of the proposed method, but does not provide a direct comparison with existing methods in terms of computational resource consumption. It is recommended to add analysis in this regard, especially memory and time consumption in actual deployment.

---

confidence: 5
contribution: 3
initial_rating: 6
presentation: 2
questions: 1. The differences between Definition 2 in the manuscript and the original definition in Ortiz-Jimenez et al. (2024) remain unclear. Could the authors elaborate further on these differences?
soundness: 3
strengths: 1. The motivation of this study is clear. The authors seek to identify a subset of parameters that can undergo non-linear fine-tuning while retaining linear characteristics, such as those observed in NTK linearization. Consequently, the attention modules, particularly the linear layers within them, are selected for this purpose.
2. The experimental results presented in Figure 3 demonstrate the validity of the proposed method.
3. Models of varying sizes (ViT-B-32, B-16 and L-14) are employed for experimental evaluation.
4. The authors conduct experiments on both the vision domain and NLP tasks.
summary: The authors propose to improve the performance of weight-interpolation-based model merging methods such as Task Arithmetic by finding a sub-module within the deep neural networks. I strongly agree with this idea because, for existing work based on NTK linearization, the model's performance on individual downstream tasks has been compromised in order to achieve better performance in multi-task model merging. This trade-off is usually unacceptable in practical applications, where ensuring performance on downstream tasks is paramount for fine-tuning. However, there are some typos and minor mistakes in this manuscript, which need to be addressed to improve the overall clarity and professionalism of the document.

Therefore, I would like to assign this manuscript an overall score of 6, indicating that it requires minor revisions. However, **I am open to raising the score if the authors address the specific concerns and suggestions outlined in my detailed review.**
weaknesses: 1. The task arithmetic presented in Definition 1 (lines 167-175) deviates from standard practice. In the original paper [1], task arithmetic is defined as $\theta_{unified} = \theta_0 + \lambda \sum_{i=1}^T \tau_i$, employing only a single scaling factor. Otherwise, it should be explicitly stated as task-wise AdaMerging [2].
2. Missing scaling factor of task vectors in lines 52-53 and lines 353-357.
3. Is the summation symbol missing on the right-hand side of Eq.(1) (lines 196-199)? 
$$ RHS = \sum_{t=1}^T \dots $$
4. In lines 400-401, the "disentanglement error" was first proposed by Ortiz-Jimenez et al. (2024).
5. Recent work on deep model fusion is missing from the related literature section. The authors may refer to these surveys [3,4,5] for additional information.
6. A minor suggestion: The results for NLP tasks (Table 4) should be included in the main text.
7. The ablation study in Appendix B.4 is not mentioned in the main text. Consider including it in the main text.

[1] Ilharco et al. Editing models with task arithmetic. In International Conference on Learning Representations. ICLR 2023. 
[2] Yang et al. AdaMerging: Adaptive Model Merging for Multi-Task Learning. ICLR 2024.
[3] Tang et al. FusionBench: A Comprehensive Benchmark of Deep Model Fusion. 
[4] Yadav et al. A Survey on Model MoErging: Recycling and Routing Among Specialized Experts for Collaborative Learning.
[5] Yang et al. Model Merging in LLMs, MLLMs, and Beyond: Methods, Theories, Applications and Opportunities.

Meta-review: Summary
The paper studies task disentanglement in neural networks whereby new tasks can be solved by linearly combining weights of task-specific models. The authors build upon NTK and show that finetuning only the attention modules of a model is amenable to task disentanglement. The method is verified on CLIP models and outperforms finetuning strategies.

Strengths
1. The authors study task disentanglement and show that attention modules can be finetuned but still retain a linear entanglement property.
2. The experimental setup in this work studies different sized models on image classification and NLP tasks.
3. The paper is presented and written well

Weaknesses
1. The approach requires tuning a hyperparameter \alpha and is sensitive to its value as the author rebuttal also shows. An automatic tuning approach for this would make the work more impactful.
2. The approach is only applicable to models with an attention layer. 

Justification
The paper received a majority of positive reviews. The author rebuttal answered the concerns from the reviewers. The paper is technically solid and presents an interesting approach for task disentanglement.

Decision: Accept (Poster)