Machine Unlearning in Large Language Models: Mathematical Foundations of Gradient Ascent, Negative Preference Optimization, and Representation Misdirection
Machine unlearning in large language models (LLMs) addresses the challenge of removing specific training data, copyrighted material, private identifiers, or hazardous capabilities from a pre-trained model without retraining the network from scratch. Because training frontier language models requires millions of GPU-hours and petabyte-scale corpora, exact retraining on a filtered dataset is computationally infeasible.
Instead, approximate machine unlearning methods modify the model parameters to approximate the statistical distribution of a hypothetical model retrained without the forget set , while strictly preserving general utility and knowledge on a retain set .

The Formal Unlearning Objective
Let denote the pre-trained or fine-tuned model parameters. The data distribution is partitioned into:
- Forget Set (): Input-target pairs containing the facts, documents, or skills to be expunged.
- Retain Set (): Input-target pairs representing general language capabilities, factual knowledge, and reasoning benchmarks that must remain intact.
The theoretical ideal of exact unlearning produces a parameter configuration drawn from the distribution of models trained solely on :
In generative language modeling, exact parameter equivalence is relaxed to output distribution equivalence:
Because evaluating is intractable, practical unlearning algorithms optimize surrogate objectives that balance forgetting performance on with utility preservation on .
1. Gradient Ascent and Retain-Regularized Objectives
The earliest and most direct approach to unlearning is Gradient Ascent (GA), which reverses standard cross-entropy minimization on the forget set.
Vanilla Gradient Ascent (GA)
Given the standard causal language modeling loss:
Vanilla Gradient Ascent updates parameters in the direction of increasing loss:
The Collapse Mechanism of Vanilla GA
While mathematically straightforward, vanilla GA suffers from severe optimization pathology:
- Logit Divergence: The gradient $\nabla_\theta \log P_\theta(y_t \mid x, y_{<t}) = \nabla_\theta z_{y_t} - \sum_k P_\theta(k) \nabla_\theta z_k$ pushes the target logit while driving non-target logits arbitrarily high.
- Catastrophic Representation Collapse: Because neural representations are dense and polysemantic, unconstrained gradient ascent destroys shared intermediate attention circuits and feed-forward keys, degrading general perplexity on within a few optimization steps.
Gradient Difference (GD) and KL Regularization
To stabilize Gradient Ascent, practical implementations combine forget-set ascent with retain-set descent and Kullback-Leibler divergence constraints against the original reference model :
Here, enforces retain task accuracy, while penalizes drift away from the baseline model's output distribution on non-target queries.
2. Preference-Based Unlearning: Negative Preference Optimization (NPO)
Direct Preference Optimization (DPO) aligns language models by reparameterizing the reward function . Zhang et al. (2024) extended this framework to unlearning by formulating Negative Preference Optimization (NPO).
In standard DPO, the loss over preferred completions and dispreferred completions is:
In pure unlearning settings, a paired high-quality target completion may not exist. NPO treats the forget completion strictly as a negative sample, removing the positive term:
Vanilla Gradient Ascent (GA):
Gradient scale: Unbounded as P_theta(y|x) -> 0
Risk: Logit divergence, output degeneration to repetitive gibberish
Negative Preference Optimization (NPO):
Gradient scale: Bounded by sigmoid derivative sigma(-beta * log-ratio)
Risk: Controlled suppression relative to reference baseline P_refGradient Dynamics of NPO
The parameter gradient for a single token under NPO is:
When the model assigns high probability to the forget sequence (), the gating weight approaches , applying strong negative gradient updates. As drops significantly below , the probability ratio approaches zero, and the gating factor decays exponentially:
This self-regulating property eliminates the logit explosion seen in vanilla GA, preventing catastrophic model degradation while steadily suppressing forget tokens.
3. Representation-Level Unlearning: Representation Misdirection (RMU)
Rather than manipulating output logits, representation-level methods intervene directly on hidden states within intermediate transformer layers. Li et al. (2024) introduced Representation Misdirection for Unlearning (RMU) in the Weapons of Mass Destruction Proxy (WMDP) benchmark.

The RMU Formulation
Let denote the hidden activation vector at layer produced by model for prompt . RMU selects an intermediate layer (typically layer ) and fine-tunes a subset of weights (such as the feed-forward down-projection matrices) using two simultaneous objectives:
- Misdirection on Forget Set: Steer the hidden representation of forget prompts toward a predetermined, uninformative steering vector :
where controls the perturbation magnitude.
- Stability on Retain Set: Constrain the hidden representation of retain prompts to match the frozen reference activations :
Here, is a high penalty weight (often set between and ). By modifying only intermediate projections, downstream layers receive uninformative random activations for forget queries, causing the attention and generation heads to output harmless generic text or refuse the prompt without corrupting general linguistic capabilities.
4. Weight-Space Arithmetic and Task Vector Inversion
Model unlearning can also be framed as vector subtraction in parameter space, extending the task arithmetic framework of Ilharco et al. (2023).
Let be the initial pre-trained model. If a model is fine-tuned on the forget set to obtain , the parameter displacement defines a "forget task vector":
To unlearn the target domain, the task vector is subtracted with a scaling coefficient :
Subspace Truncation (TIES and DARE Inversion)
Direct subtraction can introduce cross-task interference across unrelated parameter coordinates. Advanced weight-space unlearning applies directional filtering:
- TIES-Inversion: Identifies top- redundant parameter updates, resolves sign conflicts against retain gradients, and subtracts only coherent forget components.
- DARE-Inversion: Randomly drops a fraction of parameter updates in and rescales remaining weights by before subtraction, minimizing perturbation of shared zero-shot knowledge.
5. Entity Substitution and Generic Hallucination Reinforcement
In domain-specific factual unlearning, such as removing copyrighted literature (Eldan and Russinovich, 2023 in "Who's Harry Potter?"), optimization techniques replace forget entities with synthetic generic counterparts.
The pipeline operates in three distinct phases:
- Entity Extraction and Mapping: Target entities (e.g., character names, locations, spells) are identified and mapped to plausible generic alternatives (e.g., "Harry Potter" "David", "Hogwarts" "boarding school").
- Anchor Inversion: The model is evaluated on prompts involving forget entities to generate completions. Prompts are translated into generic equivalents, and target logits are aligned to generic completions using cross-entropy loss:
- Retain Regularization: Predictions on general knowledge prompts are tied to original reference outputs via KL divergence or retain cross-entropy.
6. Evaluation Benchmarks and Fragility of Unlearning
Evaluating whether knowledge has been truly deleted rather than superficially masked requires multi-metric validation suites.
+--------------------------------------------------------------------------------+
| Unlearning Evaluation Framework |
+--------------------------------------------------------------------------------+
| Forget Efficacy: |
| * Forget Set QA Accuracy (Target -> Near-Random Guessing) |
| * Forget Perplexity / Probability Ratio: P_unlearn(y|x) / P_orig(y|x) |
| * Membership Inference Attack (MIA) Resistance |
+--------------------------------------------------------------------------------+
| Retain & Model Utility: |
| * Retain Set Perplexity & Accuracy |
| * Downstream Benchmarks (MMLU, GSM8K, HumanEval, MT-Bench) |
| * Linguistic Coherence & Repetition Penalties |
+--------------------------------------------------------------------------------+
| Robustness & Adversarial Recovery: |
| * Re-learning Vulnerability (Few-shot Fine-Tuning Rebound) |
| * Adversarial Jailbreaks & Paraphrased Extraction |
| * Latent Directional Ablation Recovery |
+--------------------------------------------------------------------------------+Standardized Benchmarks
- TOFU (Task of Fictitious Unlearning): Maini et al. (2024) introduced a synthetic dataset of 200 fictitious author biographies (each containing 20 QA pairs). By controlling the pre-training and fine-tuning data, TOFU provides an exact retrained ground-truth baseline to measure forget quality and retain preservation.
- WMDP (Weapons of Mass Destruction Proxy): Li et al. (2024) compiled 4,157 multiple-choice questions spanning biosecurity, chemical security, and cyberattack methodologies to test hazardous capability removal in frontier models.
Known Vulnerabilities of Approximate Unlearning
Empirical evaluations reveal critical failure modes across current unlearning algorithms:
- Shallow Erasure vs. Deep Deletion: Many unlearning methods alter generation routing without destroying underlying associative weights. Adversarial prompting or soft prompt tuning often recovers unlearned facts.
- Re-Learning Sensitivity: Fine-tuning an unlearned model on as few as 10 to 50 domain examples frequently restores full performance on the forget set, demonstrating that representations remain latent in orthogonal parameter subspaces.
- Over-Generalization: Aggressive unlearning can inadvertently suppress adjacent domains, such as degrading general organic chemistry reasoning while attempting to unlearn chemical weapon synthesis.
Algorithmic Comparison
- Vanilla Gradient Ascent (GA): Reverses cross-entropy on . Highly unstable; prone to rapid logit explosion and catastrophic model collapse.
- Gradient Difference (GD + KL): Pairs forget ascent with retain descent and KL divergence constraints. Moderately stable; requires careful hyperparameter balancing between and .
- Negative Preference Optimization (NPO): DPO-derived negative-only loss with sigmoid-bounded gradient updates. Stable optimization; effectively suppresses forget sequences without divergence.
- Representation Misdirection (RMU): Aligns intermediate hidden states to a random steering vector while freezing retain states. Highly effective for hazardous domain suppression; retains strong MMLU performance.
- Task Vector Subtraction: Subtracts fine-tuned forget weights from base model parameters. Computationally fast; sensitive to task entanglement and weight scaling.
- Entity Substitution: Trains the model to produce generic completions for target entity prompts. Effective for targeted narrative unlearning; high data preparation overhead.
Sources
- TOFU: A Task of Fictitious Unlearning for LLMs (Maini et al., 2024)
- Negative Preference Optimization: From Catastrophic Collapse to Effective Unlearning (Zhang et al., 2024)
- The WMDP Benchmark: Measuring and Reducing Malicious Use With Unlearning (Li et al., 2024)
- Who's Harry Potter? Making LLMs forget (Eldan & Russinovich, 2023)
- Editing Models with Task Arithmetic (Ilharco et al., 2023)
- Rethinking Machine Unlearning for Large Language Models (Liu et al., Nature Machine Intelligence 2025)
