Machine Unlearning of Pre-trained Large Language Models (2024)

Abstract: This study investigates the concept of the ‘right to be forgotten’ within the context of large language models (LLMs). We explore machine unlearning as a pivotal solution, with a focus on pre-trained models–a notably under-researched area. Our research delineates a comprehensive framework for machine unlearning in pretrained LLMs, encompassing a critical analysis of seven diverse unlearning methods. Through rigorous evaluation using curated datasets from arXiv, books, and GitHub, we establish a robust benchmark for unlearning performance, demonstrating that these methods are over 10 times more computationally efficient than retraining. Our results show that integrating gradient ascent with gradient descent on in-distribution data improves hyperparameter robustness. We also provide detailed guidelines for efficient hyperparameter tuning in the unlearning process. Our findings advance the discourse on ethical AI practices, offering substantive insights into the mechanics of machine unlearning for pretrained LLMs and underscoring the potential for responsible AI development.1

heading: 1 Introduction
text: Large language models (LLMs) have seen remarkable advancements, attributable to training on extensive and diverse datasets (Ouyang et al., 2022; Wei et al., 2022; Touvron et al., 2023b; Wu et al., 2023; Liang et al., 2022). Yet, the reliance on massive data pools has raised significant ethical concerns, particularly when such data include sensitive, private, or copyrighted material (Li et al., 2021; Shi et al., 2023; Li et al., 2024; Yang et al., 2023).
A prominent example of these issues is the recent lawsuit filed by The New York Times2 against
∗Work partially done when at CUHK †Corresponding author
1Our dataset and code is available at https://github. com/yaojin17/Unlearning_LLM
2https://nytco-assets.nytimes.com/2023/12/NYT_ Complaint_Dec2023.pdf
OpenAI. The lawsuit, responding to the alleged use of millions of articles from The Times in training LLMs like ChatGPT, highlights the critical issue of copyright infringement in LLMs’ development.
In response to these ethical challenges, the concept of machine unlearning has emerged as a potential remedy. It entails systematically removing specific data from a model’s training, ensuring its operation as though the data had never been included (Bourtoule et al., 2021). This approach mitigates the ethical issues stemming from the pretrained data in LLMs, aligning the technology with evolving legal and ethical standards.
Despite its potential, current research on machine unlearning in the realm of LLMs has been predominantly confined to the fine-tuned model (Kumar et al., 2022; Chen and Yang, 2023; Maini et al., 2024). While fine-tuning datasets typically contain token numbers on the magnitude of 106 or less, pre-training corpora are on the magnitude of 1012. Consequently, retraining on the retained set of a fine-tuning dataset based on a pre-trained model is often feasible, whereas retraining the pre-trained model from scratch is impractical. Therefore, this focus on unlearning fine-tuned models has limitations and is less critical. The real challenge, and our focus in this paper, is the unlearning of pre-trained LLMs. This challenge is compounded by several factors: 1) the need to adapt existing unlearning methods from other fields to pre-trained LLMs, 2) the general lack of public availability of pre-trained data used to develop LLMs, and 3) the absence of directly comparable baselines due to the exorbitant costs of retraining pre-trained LLMs.
Our paper addresses them through several key contributions. We first define the problem of machine unlearning for pre-trained LLMs and propose a unified formulation consolidating prior arts under a single unlearning objective. We then investigate seven different unlearning methods in the context
8403
of LLMs. To benchmark the unlearning performance, we compile three datasets from sources, including arXiv, books, and GitHub code. Recognizing the impracticality of retraining pre-trained models, we propose an approximate retraining method using an in-distribution, unseen dataset to simulate the performance of a retraining baseline.
Besides, previous studies on machine unlearning in LLMs have been limited to small-scale experiments, unlearning at most 128 samples, single corpus sources, or short context lengths (Jang et al., 2023; Eldan and Russinovich, 2023; Yao et al., 2023). In contrast, our work unlearns thousands of chunks, each 4096 tokens in length, from a diverse range of sources across three domains, presenting a more realistic and challenging scenario. Fig. 1 illustrates a process overview for unlearning pre-trained LLMs to address user removal requests. Our main contributions and findings are summarized below.
• We structure a unified unlearning framework for LLMs, from which seven unlearning methodologies are derived and adapted to LLMs.
• We introduce an approximate retraining evaluation baseline to bypass the impracticality of retraining LLMs. Experiments on three domains demonstrate the efficacy of our methods.
• We open-source our dataset, including samples from a real pre-training dataset, which is typically a private and closed-source asset.
• Gradient ascent combined with gradient descent on in-distribution data shows greater hyperparameter robustness. We offer guidelines to efficiently fine-tune hyperparameters for other methods to streamline and make unlearning more feasible.
We aim to offer a comprehensive solution to unlearning in pre-trained LLMs, contributing to developing more ethical and responsible AI systems.

heading: 2 Problem Formulations
text: Let D = {xi}Ni=1 be a training corpus containing N sequences, where xi∈[N ] is a sequence of ti tokens wi1, w i 2, ..., w i ti . With a slight abuse of notation, we use M to denote both the model itself and its weights. This work focuses on generative LLMs M that are typically trained using the next-token prediction, characterizing the conditional probability given prompts: PM (wt+1|w1, w2, ..., wt). We denote A as a randomly initialized training algorithm M ← A(D), where the training objective is to minimize the negative log-likelihood:
L(PM ;D) = − ∑
xi∈D
ti∑
t=1
logPM (w i t+1|wi1, ..., wit).
We call the model designated for unlearning the vanilla model. We denote a forget set of sequences to be unlearned as U ⊂ D. To remove the effect of U , we consider an unlearning algorithm Â that applies to A(D) and outputs an unlearned model M ′.
Motivated by differential privacy (Dwork et al., 2006), Ginart et al. (2019) formulated the probabilistic notion of unlearning using (ϵ, δ)-closeness of distributions (Guo et al., 2020; Sekhari et al., 2021). Informally, it requires that the output distributions of Â and A run over (D \ U) to be similar. We call it exact unlearning if the distributions are identical (i.e., ϵ = δ = 0); approximate unlearning, otherwise. A naïve solution for exact unlearning is just retraining on D \ U for each U from scratch. However, it is prohibitively expensive for LLMs, in-
curring gigantic computation costs and carbon footprints (Luccioni et al., 2022; Zhang et al., 2023a).
Deriving theoretical guarantees for LLMs is also non-trivial, as the underlying transformer architecture is not convex or Lipschitz (Kim et al., 2021). Pragmatically, an active line of research (Golatkar et al., 2020; Chen and Yang, 2023; Kurmanji et al., 2023; Jia et al., 2023) only requires the empirical performance (e.g., classification accuracy) of retrained and unlearned models to be similar. In our context, we can resort to perplexity and ensure
EPM⋆ ≈ EPM ′ with M⋆ ← A(D \ U),
where M⋆ represents the model trained on D \ U . Besides, we require that the validation performance of M ′ onD\U and U is similar to that of the vanilla model on D \ U and unseen data, respectively.

heading: 3 Unlearning Methods

heading: 3.1 Overview
text: As discussed in Section 2, the objective of LLM unlearning is to ensure that the model effectively forgets designated token sequences while still preserving its performance on the retain set. To achieve this goal, we propose an approximate unlearning framework for LLMs using next-token prediction. To unlearn sequences in U , we update the current model M using the gradient derived from
∑
w∈U
T∑
t=1
Eqt∼Qwt logPM (qt|w1, w2, ..., wt−1)
+ ∑
z∈R
T∑
t=1
logPM (zt|z1, z2, ..., zt−1), (1)
whereR ⊆ D\U , w and z denote entire sequences from sets U andR respectively, and Qwt is a set of distributions over token universeW depending on wt, which we call reference distributions. While Eq. (1) appears complicated, we demonstrate that several iconic unlearning methods are its instances in Section 3.2.
Most existing unlearning approaches (Golatkar et al., 2020; Chen and Yang, 2023; Kurmanji et al., 2023; Jia et al., 2023) target at (image) classification scenarios. Nevertheless, some of them can be adapted to unlearning token sequences used to train (generative) LLMs with slight modifications.
Below, we focus on those first-order approximate unlearning methods that only exploit gradient information and are often more efficient than exact
unlearning and second-order designs 3. Their general formulation is given in Eq. (1), which can be extended for new unlearning methods. We will discuss how to specialize it to each method revisited below and the corresponding pros and cons.
Notably, some methods either consider forgetting an entire class (Tarun et al., 2021) or need to store all intermediate model/gradient information during training (Bourtoule et al., 2021). However, the former is not directly applicable to LLMs, and the latter is too expensive regarding memory. We exclude them from our discussion.

heading: 3.2 Approximate Unlearning Methods

heading: 3.2.1 Gradient Ascent (or Negative Gradient)
text: Derived from the general framework outlined in Eq. (1), if we ignore the second term, set Qwt = δwt , and multiply −1 to the gradient, we arrive at the unlearning strategy known as gradient ascent or negative gradient (Golatkar et al., 2020; Jia et al., 2023; Jang et al., 2023). Here, δwt is the delta function at wt such that qt ∼ Qwt means qt = wt with probability 1. The intuition is that M has been trained with U , while the retrained model MUr never sees U . Thus, the loss of M on U is lower than that of MUr , but the loss should be similar if |U| is limited. Unfortunately, it is known from the literature that if we perform gradient ascent for too many epochs, the model M will also potentially forget the information about D \ U , thus leading to poor utility. In practice, researchers often only apply gradient ascent in a few epochs.

heading: 3.2.2 Fine-tuning with Random Labels
text: Alternatively, if we ignore the second term of Eq. (1), and set Qwt to be a uniform distribution over all possible token sets W , we arrive at the strategy known as fine-tuning with random labels, as proposed by Golatkar et al. (2020) for classification problems. The intuition for this strategy is that a model not seeing U should act as random guessing. While it may seem reasonable at first glance, we argue that uniform distribution for Qwt is not universally appropriate. For instance, consider the case of two duplicated sequences: one to be unlearned and the other to be retained. Apparently, the retrained model should not act as random guessing on this sequence. In practice, convergence on random labels often leads to a marked decrease in both utility and performance, limiting this method
3We present a detailed review on exact unlearning and second-order unlearning methods in Appendix B
to a brief period of weight adjustment, akin to the earlier mentioned gradient ascent method.
Chundawat et al. (2023); Zhang et al. (2023b) propose to set Qwt = PMrand(wt|w1, ..., wt−1), where Mrand is a randomly initialized model (known as incompetent teacher). Their intuition is similar to fine-tuning with random labels, where Mrand does not contain information about U . Essentially, these two methods are equivalent, but fine-tuning with random labels is more direct and efficient, so we only adapt it to LLMs.

heading: 3.2.3 Unlearning with Adversarial Samples
text: This approach is originally proposed for classification tasks (Cha et al., 2023). We adapt it to our context below. For simplicity, let us assume only one sequence w1, . . . , wT to be unlearned. We generate adversarial samples {at} for each t such that they are close to wt but can confuse M the most
at = argmax a̸=wt
PM (a|w1, w2, . . . , wt−1). (2)
Originally, Cha et al. (2023) proposes choosing adversarial samples a within a small radius to wt in some metric space for classification tasks. Yet, it is non-trivial to adapt this strategy to LLMs. We thus choose a most likely token a other than wt.
To unlearn all training sequences in U , we finetune M using Eq. (1) while ignoring the second term in Eq. (1) and choosing Qwt = δat and at = argmaxa̸=wt PM (a|w1, w2, . . . , wt−1). The raw approach (Cha et al., 2023) uses K − 1 adversarial samples for each training sample to be unlearned in K-class classification problems. Directly using it is not suitable, as generating |W| − 1 adversarial samples for unlearning one token is impractical in our setting. Hence, we simplify it via Qwt = δat and at = argmaxa̸=wt PM (a|w1, w2, . . . , wt−1). Other choices in the same spirit, such as replacing argmaxa̸=wt with top-ka̸=wt , are also feasible.

heading: 3.2.4 Gradient Ascent + Descent or KL Divergence on Retained Set
text: On the other hand, disregarding the first term in Eq.(1) leads to a strategy known as fine-tuning on the retained set. By updating M with this strategy on D \ U until convergence, we can achieve the effect of retraining from scratch. For efficiency, researchers typically fine-tune M on a small subset R ⊆ D \ U over a few epochs. However, this becomes impractical for LLMs due to the large
volume of pre-training data relative to the data designated for unlearning. While not utilized independently here, this method is integrated with gradient ascent techniques, forming a hybrid approach that optimizes both terms in Eq.(1) to balance unlearning effectiveness with utility. To optimize the second term, we adopt both direct gradient ascent and KL-divergence constraint methods, outlined in the prior work (Yao et al., 2023). Moreover, we assess the impact of different data types for the second term, including general pre-training data and domain-specific data matching the unlearning set, termed in-distribution data.

heading: 4 Experiments

heading: 4.1 Background
text: Here, we select removing copyrighted data from the pre-trained model as a representative scenario. LLMs have the potential to internalize and reproduce copyrighted content unintentionally. It poses legal challenges and ethical dilemmas, especially when the model’s outputs mimic or rephrase the protected material. When it comes to light that copyrighted data has been assimilated into an LLM’s training set, machine unlearning techniques can be mobilized to facilitate the model’s “forgetfulness” regarding this specific content. Hence, the model’s subsequent outputs are safeguarded against undue influences of the copyrighted material, fostering a more compliant and ethical use of data.

heading: 4.2 Evaluation Metrics
text: We focus on evaluating the unlearned models from 1) Performance on the Forget Set: The model should not be able to predict correctly on the forget set, or its performance should degrade to the same level as the test set. 2) Performance on the Retain Set: Ideally, the model’s performance on this set should not degrade significantly, indicating that the unlearning process did not adversely affect the data it should remember. The performance assessment is conducted by measuring the model’s accuracy and perplexity on both the forget and retain sets. 3) Performance on General Downstream Tasks: We can evaluate the performance on some general downstream tasks, which can provide insights into the model’s overall capability post-unlearning. The model’s performance on these tasks is expected not to downgrade too much compared with the model before unlearning. The downstream
tasks considered include Massive Multitask Language Understanding (MMLU) (Hendrycks et al., 2021), the ARC Challenge (Clark et al., 2018), HumanEval (Chen et al., 2021), and Grade School Math (GSM8K) (Cobbe et al., 2021).
Approximate Retraining. To attain ideal unlearning outcomes, one can retrain from scratch
to exclude the specified sequences U . This exact unlearning approach is considered as the “gold standard” for evaluating approximate unlearning efficacy, as highlighted in the prior work (Liu et al., 2024). However, retraining LLMs on the entire retained datasetD\U is impractical due to substantial computational resource requirements.
To circumvent this, we introduce a surrogate
evaluation approach called approximate retraining, which is inspired by membership inference attacks (Shokri et al., 2017; Carlini et al., 2022) that identify performance gaps between the training and unseen data. We thus hypothesize that the retrained model will exhibit consistent performance on unseen domain-specific data, albeit inferior to its performance on trained data. Given the significant imbalance between pre-training and unlearning data volumes, we expect the retrained model’s performance on unseen data within unlearned data distributions to closely align with the original (vanilla) model’s performance. Consequently, by collecting new data from the same domain as the forget set to create an "approximate set," we estimate the retrained model’s performance on the forget set by the vanilla model’s performance on this approximate set. This estimation can further guide the extent of approximate unlearning, including factors such as the learning rate or optimization steps. This approximate set can be easily obtained from the test set of the LLM for its developer or from the open-source community4 for all researchers across several domains.
Membership Inference Attack. The complexity of LLMs precludes straightforward interpretable verification of the complete exclusion of specific sequences from the vanilla model. To address this, we employ Membership Inference Attack (MIA) to ascertain whether particular sequences are erased from the LLM’s training dataset. This evaluation employs the Min-K% Prob method (Shi et al., 2023), which operates on the premise that non-member examples are more prone to containing outlier words with notably high negative loglikelihood values, in contrast to member examples. An important variable affecting the efficacy of MIA is the percentage of tokens with minimal prediction probability; thus, we conduct experiments across various percentages, selecting the one yielding the highest detection performance for each model. The sequence length is set to be 4096 tokens for both member (chunked from the forget set) and nonmember (equivalent number of chunks from the approximate set) datasets. The effectiveness of MIA was quantitatively assessed using the Area Under Curve (AUC) metric. Notably, a higher AUC indicates that the targeted sequence is still identifiable within the training set, whereas a score approaching 0.5, indicative of random guess result, suggests
4https://huggingface.co/RealTimeData
superior unlearning effectiveness.

heading: 4.3 Model and Datasets
text: We conduct experiments using the open-sourced Yi6B (Young et al., 2024) LLM. To rigorously assess the effectiveness of unlearning methods, we perform tests in three distinct settings: arXiv papers, GitHub code repositories, and books. Despite their public availability, these sources may still entail copyright concerns. For instance, although arXiv provides open access to preprints, in many cases, the copyright of each individual preprint remains with its authors or the rights holders. Imagine a case where the paper’s authors would like to erase their preprints from the pre-trained LLMs (“the right to be forgotten”).
The forget set is randomly sampled from the Yi6B’s pre-training data 5, encompassing domains such as arXiv papers, GitHub code repositories, and books. Due to the impracticality of evaluating the model’s performance across the entirety of the retained set, we randomly select a sample of 1k sequences from the retained set to create a general set. For arXiv papers, the approximate data comprises 6.1k publications from August 2023. The GitHub code repositories’ approximate data are 15.8k files from GitHub repositories uploaded in November 2023 with permissive licenses (RealTimeData, 2024). The approximate data of Books are 50 books published after 2023, which are from the unseen data of BookMIA (Shi et al., 2023). We employ the model’s maximum input sequence length of 4096 as the chunk length, segmenting the sequences into multiple chunks. All the approximate dataset is preprocessed in the same manner as TogetherComputer (2023), an open-source pretraining data collection to reproduce Llama. The dataset statistics are shown in Table 4.
5We contacted companies with open-sourced LLMs for pre-training data access. Only the Yi model’s developers responded, granting us sampled data and permission for its use and open-sourcing.

heading: 4.4 Results
text: We report and analyze the results for unlearning arXiv papers, GitHub code repositories, and books. Given that approximate retraining serves as an optimal target for unlearning, we adjust the learning rate of each experiment to align the results with those achieved through approximate retraining. The number of unlearning epochs is 1. All the experiments are conducted using 8 A800 GPUs.
Unlearning academic papers from arXiv. We task the pre-trained Yi-6B to unlearn 500 academic papers randomly selected from its training data within the arXiv domain. This procedure simulates scenarios in which authors wish to safeguard their proprietary knowledge or unique writing styles. The unlearning performance is shown in Table 1.
The vanilla model exhibits close performance on both the forget set and unseen approximate data, with perplexity values of 3.65 and 3.69, respectively, demonstrating the model has good generalization capabilities within the arXiv domain. Compared with the vanilla model, unlearned models exhibit a slight decline in next token prediction accuracy (e.g., from 69.02% to 68.79% after gra-
dient ascent), signifying increased difficulty in token extraction given preceding tokens as prompts. Notably, only the model subjected to unlearning through a combination of gradient ascent and gradient descent exhibited reduced perplexity on the retain set. This outcome can be attributed to the model learning on a general dataset sampled from the same distribution as the retain set while unlearning the forget set. Furthermore, gradient ascent emerges as the sole method to enhance average accuracy across downstream tasks post-unlearning, underscoring its superiority in maintaining the model’s overall utility.
Both the MIA AUC scores before and after unlearning are close to 0.5. This result aligns with a recent study (Duan et al., 2024), which indicates that current MIA methods struggle to differentiate between member and non-member data in LLMs. Despite this general difficulty, our results demonstrate a decrease in MIA AUC scores after unlearning. This indicates that it becomes more challenging to differentiate between the forget set and unseen data, suggesting that our unlearning methods are effective in reducing privacy leakage related to membership inference.
Unlearning programming code from GitHub repositories. We request the pre-trained Yi-6B to unlearn 2000 GitHub code files randomly selected from its training data. This simulates scenarios where developers or organizations seek to remove specific coding patterns, algorithms, or proprietary code from the model’s knowledge base, ensuring that their intellectual property remains protected. The unlearning results are displayed in Table 2.
The vanilla model exhibits a more pronounced disparity in performance between the forget set and the unseen approximate set for GitHub code, indicating inferior generalization capabilities compared to the arXiv domain. A notable decline in the HumanEval pass@1 score is observed for models unlearned through fine-tuning with random labels, unlearning with adversarial samples, and gradient ascent combined with gradient descent on indistribution data. Given that HumanEval is a metric specifically designed to assess the code-generating proficiency of LLMs (Chen et al., 2021), this substantial decrease underscores the detrimental impact of these three methods on the model’s taskspecific utility. Furthermore, a performance reduction of at least 1.83% on the HumanEval pass@1 score is recorded for other methods, suggesting that unlearning GitHub codes from the LLM’s pretraining dataset while maintaining coding capabilities presents a challenging task.
Unlearning copyrighted books. We instruct the pre-trained Yi-6B to unlearn 500 books randomly selected from its training data. This process simulates scenarios in which authors or publishers aim to withdraw their literary works, thereby protecting the uniqueness of their content or preventing the model from generating derivative works. The unlearning results are detailed in Table 3.
Similar to the GitHub code domain, the vanilla model’s perplexities of 7.62 for the forget set and 10.11 for the approximate set suggest weaker generalization compared to the arXiv domain. Moreover, when fine-tuning to reach perplexity levels similar to approximate retraining, models unlearned via fine-tuning with random labels, adversarial sample unlearning, and the combination of gradient ascent with gradient descent on in-distribution data result in lower accuracy on the forget set than other methods. This indicates that these strategies more effectively obfuscate the model to predict accurately for the forget set, thus better protecting against potential information extraction from the model.

heading: 4.5 Computational efficiency analysis
text: Machine unlearning is to make the model efficiently forget specific training data without the need for retraining from scratch. Therefore, efficiency is a crucial factor in evaluating unlearning methods. Following Brown et al. (2020), we estimate the total training floating point operations (FLOPs) as 6 × Total Training Tokens × Parameter Size, and the total forward FLOPs as 2 × Total Forward Tokens × Parameter Size. For the Yi-6B model, pre-trained on 3 trillion tokens, we calculate the computational costs for retraining and all the unlearning methods applied to forget a dataset comprising 2,000 sequences, each 4,096 tokens long. The results, shown in Table 5, indicate that unlearning is approximately 105 times more efficient than retraining in terms of computational resources.

heading: 4.6 Ablation studies
text: Taking the task of unlearning GitHub code as a case study, a series of experiments are conducted to investigate the influence of learning rate and optimization steps on the unlearning outcomes, with results shown in Figure 2. For Figures 2a to 2c, we keep optimization steps fixed at 4 and vary the learning rate between 5× 10−6 and 1× 10−4. In Figures 2d to 2f, the learning rate is constant at 2×10−5, with optimization steps ranging from 1 to 32. We evaluated the unlearned model’s perplexity on both the forget and general sets, along with average performance on downstream tasks, presenting results across seven different unlearning methods for each hyperparameter configuration. The discussion of the effect of batch size and forget set size on the unlearning results is deferred to Appendix A.
Figure 2 shows that the method combining gradient ascent and descent on in-distribution data is notably tolerant to changes in learning rate and number of optimization steps, indicating high sta-
bility. In contrast, other methods exhibit a marked increase in perplexity for both the forget and general sets with higher learning rates or more optimization steps, underscoring their sensitivity to hyperparameter adjustments.
Moreover, since approximate unlearning may either be non-convergent or compromise utility until convergence, it is crucial to conduct a thorough search for the appropriate hyperparameters to ensure optimal unlearning performance. However, the vast search space and lack of definitive reference targets render this task impractical. To address these challenges, we analyze and summarize the following detailed guidelines to streamline the hyperparameter adjustment process:
Figure 2d indicates that a high number of optimization steps reduces the stability of the unlearning process, whereas too few steps can average out detailed information over large batches, thereby degrading unlearning quality. Based on these observations, we set the optimization step size to four for optimal balance.
Figure 2a shows that the unlearned model’s perplexity on the forget set rises with the learning rate. To find the optimal learning rate aligned with the approximate retraining baseline for unlearning, we recommend starting with a broad granularity search (10−5) within 5× 10−6 to 5× 10−5. This step narrows the search range. A subsequent finer granularity search within this refined interval will identify the learning rate that best achieves the desired unlearning outcomes.

heading: 5 Related Work
text: We provide an overview of current research on machine unlearning, memorization, and forgetting. A more detailed version is deferred to Appendix B.
Machine Unlearning. The concept of machine unlearning is first introduced in Cao and Yang (2015). Bourtoule et al. (2021) further formalizes exact unlearning by introducing a general framework: sharded, isolated, sliced, aggregated (SISA). Exact unlearning requires the unlearned model the same as the retrained model. Approximate unlearning, which relaxes the requirement, is also explored by bounding the distance (Chourasia and Shah, 2023) or indistinguishability (Sekhari et al., 2021) between the two model’s distributions.
Machine unlearning has been extensively researched within the broader field of machine learning (Xu et al., 2024), yet its exploration in gen-
erative language models remains limited. Kumar et al. (2022) propose SISA-FC and SISA-A, two computationally efficient extensions of SISA for classification LMs, e.g., BERT. To unlearn knowledge in generative models, Jang et al. (2023) simply perform gradient ascent on target sequences. Eldan and Russinovich (2023) consider a special case of unlearning the Harry Potter books from Llama27b. Yao et al. (2023) applies machine unlearning for harmful responses removing and hallucinations eliminating. However, these studies have been limited to fine-tuned models or a single corpus source. Our work explores unlearning pre-trained LLMs on more diverse datasets.
Memorization and Forgetting. Carlini et al. (2019) first quantifies unintended memorization by a metric called exposure, revealing severe privacy issues, e.g., membership inference attacks (Carlini et al., 2022) or verbatim data extraction (Carlini et al., 2021). Contrary to memorization, catastrophic forgetting, where a model loses previously learned knowledge when training on new data, has been studied (Kemker et al., 2018; Shao and Feng, 2022). It is a passive phenomenon different from unlearning, which actively forces models to “forget” specific samples.

heading: 6 Conclusion
text: In this paper, we investigate the challenge of removing copyrighted pre-training data from LLMs. We present a unified formulation for unlearning LLMs, from which seven unlearning methodologies are derived. We introduce approximate retraining as an evaluation technique to bypass the impracticality of retraining LLMs from scratch. Our experimental analysis across three pre-training data domains validates the efficacy of the unlearning approaches. Furthermore, we find that combining gradient ascent with gradient descent on in-distribution data enhances hyperparameter robustness. We also offer guidelines to streamline the tuning of hyperparameters essential to the unlearning process.
Limitations
This work primarily focuses on conducting experiments with the Yi-6B model. A significant challenge arises since most LLMs do not open-source their pre-training data, making the collection of forget sets infeasible. We encourage future research to investigate the applicability of unlearning processes to other models, including those of larger
sizes such as 13B or 70B, or more complicated architecture such as the mixture of experts. Additionally, our experiments are mainly conducted on three specific pre-training data domains. Future research should aim to explore unlearning across other domains, including Wikipedia and News.
Moreover, our work concentrates on unlearning copyrighted content from LLMs. Future studies could expand our methodologies to address other challenges, such as unlearning biases or harmful outputs in LLMs. Given that our methods are nonconvergent and may reduce model utility until convergence, the adjustment of hyperparameters becomes crucial for ideal unlearning results. While our guidelines simplify and streamline this process, we hope that future research will develop convergent methods that are less dependent on hyperparameter adjustments.
This study emphasizes the practical aspects of approximate unlearning in LLMs. However, since distinguishing between member and non-member data in LLMs remains challenging, the evaluation of approximate unlearning can be complex. A more principled theoretical investigation of unlearning in LLMs is necessary for future work. Additionally, more powerful MIA methods and alternative methods beyond MIA are needed for evaluating unlearning methods in the context of LLMs. While our focus is on unlearning data within a single domain while maintaining the unlearned model’s general capability, exploring the unlearning of taskspecific data and assessing the impact on the unlearned model’s performance in that task could be an interesting and important direction for future research.
Ethics Statement
In this work, we focus on unlearning pre-trained generative LLMs. Our goal is to enable LLMs to selectively forget particular training sequences while preserving the model’s utility. This approach aims to address ethical concerns, including copyright infringement and privacy breaches. The evaluation datasets are compiled from publicly accessible sources, adhering to the licenses associated with the collected data. We also encourage researchers and developers to use our methods responsibly and ethically.

heading: Acknowledgements
text: The authors thank the Yi model and its developer for providing a sample of pre-training data, along with permission for its use and open-sourcing. Wang was partially supported by NSF OAC2319988.

heading: A Additional Ablation Studies
text: Figures 3a to 3c display the results of unlearning 2720 sequences of GitHub code, with the batch size varied from 85 to 2720 and other hyperparameters fixed. The results demonstrate that a small batch size leads to more optimization steps, which can cause detrimental damage to the model’s general utility. However, a higher batch size also reduces the unlearning efficacy. As mentioned in Section 4.6, a batch size with corresponding optimization steps of four would be the best practice to balance utility and unlearning effect.
Figures 3d to 3f show the results of unlearning GitHub code with varying forget set sizes (512 to 8192 sequences) and fixed hyperparameters. The results show that excessively large unlearning data sizes lead to an exponential increase in perplexity on both the forget and general sets and also cause a significant decrease in model general utility. Integrating gradient ascent with gradient descent on in-distribution data proves most stable, aligning with insights in Section 4.6. For unlearning large datasets, we recommend using a relatively large batch size for stability.

heading: B Related Work (Full Version)
text: In this section, we provide greater detail about related work on machine unlearning, memorization and forgetting, the relation between machine unlearning, differential privacy, and alignment, exact unlearning, and second-order methods of machine unlearning.
Machine Unlearning. Cao and Yang (2015) introduce the notion of machine unlearning. They give a heuristic method, transforming learning algorithms into a summation form for forgetting data lineage. Their goal is to ensure that unlearned models exactly match the ones retrained from scratch. Subsequently, it is formalized as exact unlearning or data deletion (Ginart et al., 2019; Bourtoule et al., 2021) of a specific training sample, requiring the distributions of unlearned and retrained models are identical. Ginart et al. (2019) propose two tailored approaches for k-means, while Bourtoule et al. (2021) propose a general unlearning framework: sharded, isolated, sliced, aggregated (SISA).
Exact unlearning may be too “strong” to achieve; it can be “relaxed” to approximate unlearning (Ginart et al., 2019) by bounding the “distance” (e.g., Rényi divergence (Chourasia and Shah, 2023) or
indistinguishability (Sekhari et al., 2021)) between the two models’ distributions. More generally, one can unlearn a subset of training points (Sekhari et al., 2021) that can even be adaptively chosen (Gupta et al., 2021).
Since the seminal proposal, machine unlearning has been widely studied in ML in general (Xu et al., 2024; Gong et al., 2024) but remains rarely explored in NLP, notably generative LLMs. Zhang et al. (2023a) discusses the challenges and implications of unlearning and other approaches to realize RTBF in LLMs. Kumar et al. (2022) propose SISA-FC and SISA-A, two extensions of SISA for classification LMs, e.g., BERT. SISA-FC only trains fully connected task layers, and SISA-A resorts to Adapters (Houlsby et al., 2019) that only update a few plug-in parameters. Chen and Yang (2023) propose an efficient unlearning method via a selective teacher-student formulation for both classification and summarization tasks. They also design a fusion mechanism to merge unlearning layers for sequential data forgetting. To unlearn knowledge in generative models, Jang et al. (2023) simply perform gradient ascent on target sequences. Wang et al. (2024) presents a selective unlearning method to minimize negative impacts on unlearned model’s capabilities and proposes evaluation metrics focusing on sensitive information. Eldan and Russinovich (2023) consider a special case of unlearning the Harry Potter books from Llama2-7b. They first use a reinforced model to identify the tokens that are most related to the unlearning target and then replace idiosyncratic terms with generic ones to generate alternative labels for fine-tuning the model. Yao et al. (2023) applies machine unlearning for harmful responses removing and hallucinations eliminating. Maini et al. (2024) presents a benchmark for unlearning fictitious authors on fine-tuned models.
Memorization and Forgetting. Training data memorization to some extent is pivotal for model generalization, but unintended memorization, first quantified by a metric called exposure (Carlini et al., 2019), poses severe privacy issues, e.g., membership inference attacks (Carlini et al., 2022), verbatim data extraction (Carlini et al., 2021), or property inference attacks (Mao et al., 2023). Carlini et al. (2023) illustrates that memorization relies on the model scale, training data deduplication, and prompting context length.
As opposed to memorization, catastrophic for-
getting, which means that a model tends to forget previously learned knowledge when training on new data, has been studied (Kemker et al., 2018; Shao and Feng, 2022). It is a passive phenomenon different from unlearning, which actively forces models to “forget” specific samples. As with memorization, concurrent works (Tirumala et al., 2022; Jagielski et al., 2023) define and measure forgetting as a form of privacy leakage.
Machine Unlearning vs. Differential Privacy. DP is a rigorous framework for protecting indi-
vidual privacy in data analytics by adding calibrated noise to query results (Dwork and Roth, 2014), which has been explored in language models (Yue et al., 2021, 2022; Li et al., 2021; Du et al., 2023a,b). Definition-wise, approximate unlearning is reminiscent of DP. They use the same metric for distributional closeness (e.g., (ϵ, δ)indistinguishability (Guo et al., 2020)) but with a substantial difference. Unlearning compares two algorithms–unlearning and retraining–on the same dataset, whereas DP compares the same algorithm
run on neighboring datasets (differing in an individual’s data). DP is a sufficient (not necessary) condition for unlearning (Guo et al., 2020): An DP mechanism working on datasets with edit distance m naturally unlearns any m samples. Prior DP-based unlearning designs (Guo et al., 2020; Sekhari et al., 2021; Izzo et al., 2021) often assume convex loss functions. Sekhari et al. (2021); Huang and Canonne (2023) bound the “deletion” capacity (i.e., how many samples can be unlearned while ensuring desirable loss) better than m in DP. Also, DP can mitigate the adaptivity of unlearning requests (Gupta et al., 2021). Garg et al. (2020) provide an alternative definitional framework for RTBF from cryptographic primitives.
Machine Unlearning vs. Alignment. Alignment in LLMs, the process of adjusting these models to resonate with human values, is typically accomplished through techniques like supervised finetuning (SFT) (Ouyang et al., 2022; Conover et al., 2023; Chiang et al., 2023; Köpf et al., 2023; Touvron et al., 2023b) and reinforcement learning with human feedback (RLHF) (Christiano et al., 2017; Stiennon et al., 2020; Ouyang et al., 2022; Bai et al., 2022; Touvron et al., 2023a,b). These methods rely on human-generated demonstrations or rewards and penalty systems. Machine unlearning, on the other hand, uniquely focuses not on promoting correct behavior but discouraging outputs misaligned with human values (Yao et al., 2023). This method thus offers a complementary approach to standard SFT techniques.
Second-order methods of Machine Unlearning. The high-level idea of almost all second-order unlearning methods is through Taylor expansion on the gradient at the stationary point. This leads to a Newton-type update, which involves Hessian inverse (or its approximation) computation (Golatkar et al., 2020; Peste et al., 2021). Apparently, the hessian-related operation is prohibitive to LLM due to its billions if not trillions parameters. Nevertheless, current theoretical approximate unlearning approaches with privacy guarantees are all secondorder to the best of our knowledge (Guo et al., 2020; Sekhari et al., 2021; Chien et al., 2023). We decided to briefly introduce them in the context of classification and discuss the potential way of extending them for LLM.
Here, we denote M for both the LLM and its model parameters with a slight abuse of notation.
Assume M is well-trained with respect to the training loss L(PM ;D) so that it is a stationary point ∇L(PM ;D) = 0. Similarly, the retrain model MUr is also a stationary point with respect to the loss L(PMUr ;D \ U), so that ∇L(PMUr ;D \ U) = 0. We can apply a first order Tayler expansion on ∇L(PMUr ;D \ U) at M , which leads to
∇L(PM ;D \ U) +∇2L(PM ;D \ U)(MUr −M) ≈ 0 ⇒ MUr ≈ M − (∇2L(PM ;D \ U))−1∇L(PM ;D \ U).
The theoretical unlearning approach will further introduce some privacy noise (similar to the Gaussian mechanism (Mironov, 2017)) to obfuscate the potential privacy leakage rigorously (Guo et al., 2020; Sekhari et al., 2021; Chien et al., 2023), where the noise variance determined by the worst-case error of the Taylor approximation. This analysis can only be done for strongly convex problems with additional smoothness assumptions and is thus not applicable to LLMs. In practice, some researchers still follow this second-order update with a heuristic-based noise addition design, which has demonstrated superior performance on privacy and utility (Golatkar et al., 2020). The main focus of this direction is to improve the computation complexity of the second-order update, with ideas leveraging the Fisher information matrix (Golatkar et al., 2020) and rank one update by Sherman-Morrison lemma (Peste et al., 2021). Nevertheless, the computation complexity of these advanced second-order methods is still too expensive for LLM. One potential direction is to apply these second-order updates only for adaptor (Houlsby et al., 2019) or LoRA (Hu et al., 2022), which contain much fewer parameters to be modified. It remains open whether it is possible to apply secondorder methods for LLM or not at the moment.
Exact Unlearning. We introduce exact unlearning methods that correspond to (ϵ, δ) notion of unlearning with ϵ = δ = 0. While ensuring ϵ = δ = 0 is desired in some extreme cases, it generally fails to explore the beneficial trade-off between unlearning quality, model utility, and time complexity.
SISA (Sharded, Isolated, Sliced, and Aggregated) framework (Bourtoule et al., 2021) is a general approach to achieve exact unlearning for general deep neural networks at the cost of changing the training pipeline significantly. The main idea is to partition the training dataset D into K disjoint sets D1, . . . ,DK . For each Di, we train or
fine-tune M on it independently, which results in K models Mi = A(Di). We use any fixed aggregation strategy for these K models for the final prediction or output. Unlearning in the SISA framework is straightforward. Given an unlearning request U , we retrain all models Mi for i such that U ∩ Di ̸= ∅. Apparently, storing K copies of LLMs is memory-expensive and impractical which makes the SISA approach not applicable to the pretraining task. The authors of (Kumar et al., 2022) leverage the SISA approach to the fine-tuning task by only fine-tuning a fully connected layer (FC) or Adapter (A) on top of a freeze public pretrained model M . They termed these methods SISA-FC and SISA-A respectively.
The SISA framework is currently the only method providing a theoretical privacy guarantee while applicable to LLMs. However, the efficiency and utility of this approach are greatly affected by the choice of K and dataset dependent. Clearly, when K = 1 we simply arrive at retraining from scratch, which maximally preserves the utility but exhibits impractical time complexity. Choosing a large K can improve the efficiency but may degrade model utility. It is unclear at the moment how to choose an appropriate K.

heading: Future Work
text: We encourage future research to investigate the applicability of unlearning processes to other models, including those of larger
sizes such as 13B or 70B, or more complicated architecture such as the mixture of experts. Additionally, our experiments are mainly conducted on three specific pre-training data domains. Future research should aim to explore unlearning across other domains, including Wikipedia and News. Moreover, our work concentrates on unlearning copyrighted content from LLMs. Future studies could expand our methodologies to address other challenges, such as unlearning biases or harmful outputs in LLMs. Given that our methods are nonconvergent and may reduce model utility until convergence, the adjustment of hyperparameters becomes crucial for ideal unlearning results. While our guidelines simplify and streamline this process, we hope that future research will develop convergent methods that are less dependent on hyperparameter adjustments. This study emphasizes the practical aspects of approximate unlearning in LLMs. However, since distinguishing between member and non-member data in LLMs remains challenging, the evaluation of approximate unlearning can be complex. A more principled theoretical investigation of unlearning in LLMs is necessary for future work. Additionally, more powerful MIA methods and alternative methods beyond MIA are needed for evaluating unlearning methods in the context of LLMs. While our focus is on unlearning data within a single domain while maintaining the unlearned model’s general capability, exploring the unlearning of taskspecific data and assessing the impact on the unlearned model’s performance in that task could be an interesting and important direction for future research