Skip to content

Editing Models with Task Arithmetic

optionalextendedfundamentalpaperrubric 8/122022 · ICLR 2023 · ~35 min

Gabriel Ilharco, Marco Tulio Ribeiro, Mitchell Wortsman, …, Ali Farhadi

Status

TL;DR. Fine-tune a model on a task and subtract the pre-trained weights: the difference τ=θft−θpre\tau = \theta_\text{ft} - \theta_\text{pre} is a task vector. Adding scaled task vectors gives multi-task models, negating one removes a behaviour, and analogies between tasks can produce a model for a task with no training data.

Task vectors are applied element-wise to any model with the same architecture: θnew=θ+λτ\theta_\text{new} = \theta + \lambda\tau (§2). Negation uses −τ-\tau; addition uses ∑iτi\sum_i \tau_i; analogies use τC+(τB−τA)\tau_C + (\tau_B - \tau_A). The scale λ\lambda is chosen on held-out validation data.

Results. Negating a task vector from GPT-2 Large fine-tuned on toxic data reduces toxic generations by 6× with comparable WikiText-103 perplexity (§3.2, Table 2). Adding task vectors from eight CLIP image tasks reaches 91.2% average normalised accuracy, where 100% is the accuracy of using a separate fine-tuned model per task (§4.1).

  • Activation addition does the same arithmetic on activations instead of weights.
  • ROME edits weights with a targeted rank-one update rather than a whole fine-tuning delta.
  • Weight-space programming has an LLM read and write weight edits directly.
  • LoRA produces low-rank task updates that are natural task vectors.

Questions to think through

These questions have no single right answer. Write or say your answer before you open the hints. Mark a question once you could defend your answer in a reading group.

  1. Derive / compute

    With τ_A = θ_A − θ_pre and τ_B = θ_B − θ_pre, write the merged model for adding both tasks with scale λ, the model that forgets task A, and the analogy model for "A is to B as C is to D". What does each assume about how the task updates interact?

    What a strong answer covers
    • Addition: θ_new = θ_pre + λ(τ_A + τ_B).
    • Negation: θ_new = θ_pre − λτ_A, which extrapolates past the pre-trained model away from the fine-tuned one.
    • Analogy: τ_D ≈ τ_C + (τ_B − τ_A), so θ_new = θ_pre + λ(τ_C + τ_B − τ_A), using no data from task D.
    • All assume updates combine approximately linearly near θ_pre, i.e. that task vectors interfere little; λ is tuned on held-out data to control this.
  2. Mechanism

    Negating a toxicity task vector on GPT-2 Large cut toxic generations about 6× with similar WikiText-103 perplexity. Explain why moving away from a fine-tuned model can remove a behaviour without destroying general ability.

    What a strong answer covers
    • Fine-tuning on toxic text moves weights mainly along directions that increase toxic continuations; the rest of the change is small.
    • Subtracting that delta from the pre-trained model pushes those same directions the other way, reducing the behaviour.
    • Because the delta is concentrated on the task, control-task performance (perplexity on WikiText-103) changes little at a tuned λ.
    • If the task vector also encoded general language skills, negation would hurt perplexity; the control task is the check for this.
  3. Design

    You have one embedding model fine-tuned for biomedical retrieval and one for legal retrieval, both from the same base. Plan how to use task arithmetic to build a single model, and what to measure.

    What a strong answer covers
    • Compute τ_bio and τ_legal against the shared base, then add with λ tuned on a held-out mix of both domains.
    • Measure nDCG@10 on each domain relative to the specialist models (normalised accuracy as in the paper) and on a general benchmark as a control.
    • Check interference: if adding hurts one domain, try per-layer λ or merging only part of the network.
    • Also test negation to remove an unwanted bias (for example a length preference) learned by one fine-tune.

Done with this page?

Status