LLM Surgery: Efficient Knowledge Unlearning and Editing in Large Language Models

Akshaj Kumar Veldanda, Shi-Xiong Zhang, Anirban Das, Supriyo Chakraborty, Stephen Rawls, Sambit Sahu, Milind R. NaphadearXiv 2024 · OpenReview

Abstract

Large language models (LLMs) have revolutionized various domains, yet their utility comes with significant challenges related to outdated or problematic knowledge embedded during pretraining. This paper addresses the challenge of modifying LLMs to unlearn problematic and outdated information while efficiently integrating new knowledge without retraining from scratch. Here, we propose LLM Surgery, a framework to efficiently modify LLM behaviour by optimizing a three component objective function that: (1) Performs reverse gradient on unlearning dataset (problematic and outdated information), (2) Performs gradient descent on the update dataset (new and updated information), and (3) Minimizes the KL divergence on the retain dataset (small subset of unchanged text), ensuring alignment between pretrained and modified model outputs. Due to the lack of publicly available datasets specifically tailored for our novel task, we compiled a new dataset and an evaluation benchmark. Using Llama2-7B, we demonstrate that LLM Surgery can achieve significant forgetting on the unlearn set, a 20% increase in accuracy on the update set, and maintain performance on the retain set.

Introduction

Large Language Models (LLMs) are trained on vast datasets, inevitably capturing copyrighted material, private information, or facts that eventually become obsolete. When updates are required—such as correcting a factual error or complying with "right to be forgotten" requests—developers typically face two suboptimal choices: prohibitively expensive full retraining or standard fine-tuning, which often leads to "catastrophic forgetting" of general reasoning capabilities.

Methodology: The LLM Surgery Framework

The proposed "LLM Surgery" framework operates in a continual-pretraining regime, allowing for targeted modifications without human-annotated instruction data. The core innovation is a three-part objective function:

  1. Unlearning via Reverse Gradient: To erase specific data, the model performs gradient ascent on the "unlearn" dataset, actively pushing the model away from its original learned patterns for that subset.
  2. Updating via Gradient Descent: Standard training is applied to an "update" dataset containing fresh or corrected information.
  3. Retention via KL Divergence: To preserve general knowledge and reasoning, the model minimizes the Kullback–Leibler (KL) divergence between the original and modified model outputs on a small subset of general data.

Experimental Setup

As no standard benchmark existed for simultaneous unlearning and updating, a new dataset was curated comprising an Unlearn Set (238 biographies), an Update Set (119 fictitious biographies to replace outdated ones), and a Retain Set (general knowledge tokens). Evaluation was conducted using a suite of 24,800 Multiple Choice Questions (MCQA) to measure the precision of the "surgery."

Results and Analysis

The framework was evaluated using Llama2-7B. Quantitative results demonstrate that LLM Surgery effectively balances the three objectives.

Table 1: Performance metrics for LLM Surgery compared to baselines and ablation studies.

As shown in Table 1, the surgery model ($θ^{surgery}$) achieves a significant reduction in accuracy on the unlearn set (indicating successful forgetting) while simultaneously increasing accuracy on the update set by approximately 20%. Crucially, performance on the Retain and Arc Easy sets remains stable, confirming that the model's general utility is preserved. This process was found to be 35x faster in terms of GPU hours compared to naive retraining.

Visualizing Internal Representations

To understand the impact of the surgery, the authors analyzed activation patterns across the model's hidden dimensions.

Figure 1: Heatmaps of activation patterns across layers and hidden dimensions for the Unlearn, Update, and Retain sets.

The visualization in Figure 1 confirms that the surgery specifically targets the internal logic associated with the unlearn and update sets, leaving the general knowledge representations (Retain set) virtually untouched.

Conclusion

LLM Surgery provides a scalable, efficient method for editing model memories. By combining gradient ascent for unlearning with KL divergence for retention, the framework allows for surgical precision in model updates without the catastrophic forgetting typically associated with fine-tuning.

Summary updated

BibTeX
@misc{veldanda2024llm,
  author = {Akshaj Kumar Veldanda and Shi-Xiong Zhang and Anirban Das and Supriyo Chakraborty and Stephen Rawls and Sambit Sahu and Milind R. Naphade},
  title = {{LLM Surgery: Efficient Knowledge Unlearning and Editing in Large Language Models}},
  year = {2024},
  eprint = {2409.13054},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2409.13054},
}
Figure