Variational Task Vector Composition

Boyuan Zhang, Yingjun Du, Xiantong Zhen, Ling Shao

Abstract

We present a novel Bayesian framework for task vector composition that addresses the limitations of traditional task-level scaling and structural redundancy. By casting composition as a variational inference problem, our method dynamically adjusts task vector weights for individual input samples. We employ a "Spike-and-Slab" prior to enforce sparsity and a gated sampling mechanism to manage uncertainty. Experimental results across diverse image classification datasets and Vision Transformer scales demonstrate that our approach consistently outperforms deterministic baselines, achieving state-of-the-art accuracy while significantly reducing active parameter counts during inference.

Introduction

In large-scale machine learning, pre-trained models like CLIP are often fine-tuned for specialized tasks. Task Arithmetic has emerged as a powerful technique to combine these specialized models by subtracting pre-trained weights from fine-tuned ones to create "task vectors," which are then summed to create a multi-task model.

However, traditional methods suffer from two primary drawbacks. First, they typically apply uniform, task-level scaling to every input, failing to account for sample-specific nuances. Second, task vectors are structurally redundant; empirical analysis shows that over 95% of their variance can often be explained by a tiny fraction of principal components. Existing deterministic methods ignore this redundancy, leading to task interference and sub-optimal generalization.

Methods: A Variational Approach

To address these issues, we recast task vector composition as a variational inference problem. Instead of fixed, deterministic coefficients, we treat composition weights as latent variables ($z$) to be estimated per sample.

The proposed Variational Task Vector Composition framework, illustrating the interaction between input samples, latent variables, and the gated sampling mechanism.

Our framework incorporates three key components:

  1. Amortized Inference: A small auxiliary neural network predicts the mean and variance of composition coefficients directly from the input image, making sample-specific adjustments computationally efficient.
  2. Spike-and-Slab Prior: We utilize a classic Bayesian sparsity tool to tackle redundancy. The "Spike" (a point mass at zero) forces unimportant components to zero, while the "Slab" (a Gaussian distribution) allows significant components to retain their values. This encourages the model to select only the most informative task vector elements.
  3. Gated Sampling: To stabilize high-dimensional stochastic sampling, we developed a deterministic gated mechanism. It calculates uncertainty scores based on gradient sensitivity and distributional deviation, shutting out coefficients that are either too uncertain or unimportant.

Experimental Setup

The framework was evaluated using Vision Transformer (ViT) architectures (ViT-B/32, ViT-B/16, and ViT-L/14) pre-trained with CLIP. We tested the model across eight diverse image classification datasets, ranging from natural images (Cars, MNIST, SVHN) to specialized domains like textures (DTD), satellite imagery (EuroSAT), and remote sensing (RESISC45).

Key Results and Insights

Our sample-specific probabilistic method consistently outperformed task-level baselines. On average, the proposed method achieved an accuracy of 84.32% (using ViT-B/32), a significant jump from the 77.60% achieved by standard task-level arithmetic.

Radar charts comparing performance across datasets for different model scales. The Spike-and-Slab prior consistently improves accuracy while maintaining a sparse 'Gated Ratio' of active parameters.

Key findings include:

  • Sample-Level Granularity: The ability to decide on-the-fly which task knowledge is relevant is a major performance driver, particularly for datasets like SVHN that deviate significantly from standard pre-training data.
  • Sparsity as a Regularizer: By "silencing" redundant parts of task vectors via the Spike-and-Slab prior, the model avoids the interference common in simple task arithmetic. For example, on the DTD dataset, accuracy improved from 88.66% to 93.31% with the addition of the gated mechanism.
  • Scalability: The benefits of this gated, variational approach become more pronounced as model size increases. Larger models (ViT-L) effectively leverage more complex combinations of task knowledge when provided with the appropriate filtering mechanism.

Conclusion and Future Work

Variational Task Vector Composition offers a robust, efficient, and interpretable way to merge specialized model knowledge. While the current work focuses on task addition within Vision Transformers, future research will explore its application to other operations like task subtraction (forgetting) and its scalability to Large Language Models (LLMs). Addressing the computational overhead of managing many task vectors simultaneously remains a key area for optimization.

Summary updated

BibTeX
@inproceedings{zhang2025variational,
  author = {Boyuan Zhang and Yingjun Du and Xiantong Zhen and Ling Shao},
  title = {{Variational Task Vector Composition}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2025},
  url = {https://openreview.net/forum?id=yzv6kysYbw},
}
Figure