SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2506.01339 · ICML · 2025

Invariance Makes LLM Unlearning Resilient Even to Unanticipated Downstream Fine-Tuning

Sijia Liu, Dennis Wei, Yuguang Yao, Jinghan Jia, Yihua Zhang, Parikshit Ram, Nathalie Baracaldo, Soumyadeep Pal, Changsheng Wang

arXiv · PDF · Open in the Atlas

Code that ran

5 of 6 samples (functions and classes) lifted from this paper's linked repositories executed on a synthesized input in Syntology's jail (0 of them constructed an object rather than computing a result; 0 honoured the contract we drafted, 0 violated it and 2 have no contract verdict; 3 failures of our instrument; 1 no recorded run), measured 2026-11-23; repository links from the Papers with Code archive attributed under CC BY-SA, no affiliation; bodies inline only under a permissive licence as GitHub detects it. Not a reproduction of the paper's results.

"Ran" means the function executed on a synthesized input and returned a value. It is not a reproduction of the paper's results. This record, dated, as JSON: /api/ran/2506.01339.json · badge: /api/ran/2506.01339.svg

Each repository's role is a label: a classifier's output recorded on the link, or, where no role is recorded, what the Papers with Code archive marked. The line under it names its basis. Neither says who wrote the code.

RepositoryRoleRan
OPTML-Group/Unlearn-ILU canonical (classifier label)
classifier basis not recorded on the link
5 ran · 1 no recorded run
FunctionStatusWhere it lives
compute_metrics Ran
ran; our contract draft was wrong, not the code
OPTML-Group/Unlearn-ILU/src/unlearn/base.py
code served (permissive licence) · get_code("88a4f13abd54a00c")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned dict. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch
import numpy as np

torch.manual_seed(0)

# Create a simple pred object with predictions and label_ids attributes
class PredObject:
    def __init__(self, predictions, label_ids):
        self.predictions = predictions
        self.label_ids = label_ids

# Create small tensors: batch_size=2, vocab_size=4, seq_length=3
batch_size = 2
vocab_size = 4
seq_length = 3

# predictions shape: (batch_size, seq_length, vocab_size) - logits
predictions = np.random.randn(batch_size, seq_length, vocab_size).astype(np.float32)

# label_ids shape: (batch_size, seq_length) - token indices
# Use values in range [0, vocab_size) or -100 for ignore_index
label_ids = np.array([
    [1, 2, 0],
    [3, 1, -100]
], dtype=np.int64)

# Create pred object
pred = PredObject(predictions, label_ids)

ARGS = {
    'pred': pred
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
numpy, torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type dict — a dict output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a dict output the recorded ndim 0 and dtype family float describe that coercion, not the output, and are not stated
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
get_batch_loss Ran
ran; our contract draft was wrong, not the code
OPTML-Group/Unlearn-ILU/src/unlearn/utils.py
pointer only (licence: MIT); the stored copy get_code serves, from carol-gutianle/meow, is pointer only (licence: NONE) · get_code("442bc919060e0f2b")
How it ran

The body of this sample is withheld: this paper's link allows the body inline (MIT), but get_code serves the stored copy, first harvested from carol-gutianle/meow, and GitHub detected no licence in that repository when it was checked. The setup block that called it is withheld with it, because it is written against that body. source_path and origin say where the code lives, to read under the repository's own terms. A run is recorded.

get_loss Ran
ran; our contract draft was wrong, not the code
OPTML-Group/Unlearn-ILU/src/unlearn/base.py
code served (permissive licence) · get_code("650d5f6bfcd7d9bb")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned Tensor, ndim 0, dtype family float, shape () as a later run recorded it. The image it ran in was not recorded. If your copy returns the same type, ndim and shape on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch
from torch import nn

torch.manual_seed(0)

# The function expects:
# - output: a tensor that will be reshaped to (-1, vocab_size)
#   It accesses output[..., :-1, :] and output.size(-1)
#   So it needs shape (batch, seq_len, vocab_size)
# - labels: a tensor that will be reshaped to (-1,)
#   It accesses labels[..., 1:] 
#   So it needs shape (batch, seq_len)

batch_size = 2
seq_len = 5
vocab_size = 4

# output shape: (batch_size, seq_len, vocab_size) = (2, 5, 4)
output = torch.randn(batch_size, seq_len, vocab_size)

# labels shape: (batch_size, seq_len) = (2, 5)
# Values should be in range [0, vocab_size-1] or -100 (ignore_index)
labels = torch.randint(0, vocab_size, (batch_size, seq_len))

ARGS = {
    "output": output,
    "labels": labels,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type Tensor, ndim 0, dtype family float, shape () — shape () as a later run recorded it
dtype family
int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
kl_loss Ran
ran on a synthesized input
OPTML-Group/Unlearn-ILU/src/unlearn/KL.py
code served (permissive licence) · get_code("30e138b18347fbb4")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned Tensor, ndim 0, dtype family float, shape () as a later run recorded it. The image it ran in was not recorded. If your copy returns the same type, ndim and shape on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch
import torch.nn as nn

torch.manual_seed(0)

# The function kl_loss takes two probability tensors and computes KL divergence
# It uses:
# - prob_p: a tensor that supports element-wise operations and .sum(-1).mean()
# - prob_q: a tensor that supports element-wise operations and torch.log()

# Create two small probability tensors
# Shape: (batch_size=2, num_classes=4)
prob_p = torch.tensor([
    [0.25, 0.25, 0.25, 0.25],
    [0.1, 0.2, 0.3, 0.4]
], dtype=torch.float32)

prob_q = torch.tensor([
    [0.2, 0.3, 0.25, 0.25],
    [0.15, 0.15, 0.35, 0.35]
], dtype=torch.float32)

ARGS = {
    "prob_p": prob_p,
    "prob_q": prob_q
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type Tensor, ndim 0, dtype family float, shape () — shape () as a later run recorded it
dtype family
int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
run_generation Ran
ran on a synthesized input
OPTML-Group/Unlearn-ILU/src/unlearn/utils.py
code served (permissive licence) · get_code("5a2f4fa433151210")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned tuple, ndim 2, dtype family float; no output shape is stated. The image it ran in was not recorded. If your copy returns the same type and ndim on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch
import torch.nn as nn

torch.manual_seed(0)

class MockTokenizer:
    def __init__(self):
        self.padding_side = 'right'
        self.pad_token = '<pad>'
        self.pad_token_id = 0
        self.eos_token = '</s>'
        self.eos_token_id = 2
        self.vocab_size = 100
    
    def batch_decode(self, token_ids, skip_special_tokens=True):
        # Return mock strings with the split symbol for testing
        return [
            "What is 2+2?### Answer: 4",
            "What is 3+3?### Answer: 6",
        ]
    
    def batch_encode_plus(self, strings, add_special_tokens=True, return_tensors=None, padding=False):
        # Return mock encoded tensors
        batch_size = len(strings)
        seq_length = 5
        input_ids = torch.randint(1, self.vocab_size, (batch_size, seq_length))
        attention_mask = torch.ones((batch_size, seq_length))
        
        class EncodedBatch:
            def __init__(self, ids, mask):
                self.input_ids = ids
                self.attention_mask = mask
            
            def to(self, device):
                self.input_ids = self.input_ids.to(device)
                self.attention_mask = self.attention_mask.to(device)
                return self
        
        return EncodedBatch(input_ids, attention_mask)

class MockModel(nn.Module):
    def __init__(self):
        super().__init__()
        self.device = torch.device('cpu')
        self.embed = nn.Embedding(100, 4)
    
    def generate(self, input_ids, attention_mask=None, max_length=512, max_new_tokens=512, 
                 do_sample=False, use_cache=True, pad_token_id=None):
        # Return mock generated tokens
        batch_size = input_ids.shape[0]
        input_seq_len = input_ids.shape[1]
        new_tokens = 3
        # Generate output with original input_ids plus new tokens
        generated = torch.randint(1, 100, (batch_size, input_seq_len + new_tokens))
        return generated

batch = {
    'input_ids': torch.randint(1, 100, (2, 5))
}

model = MockModel()
tokenizer = MockTokenizer()

ARGS = {
    'batch': batch,
    'model': model,
    'tokenizer': tokenizer,
    'max_length': 512,
    'max_new_tokens': 512,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type tuple, ndim 2, dtype family float — a tuple output has no array shape of its own; none is stated
dtype family
int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
unlearncollector Not yet run
unverified (harvested, no recorded run)
OPTML-Group/Unlearn-ILU/src/dataset/Base.py
code served (permissive licence) · get_code("21b851de3f5356c4")
How it ran

no invocation recorded.

Also present in other papers' code

Of 6 samples lifted from this paper's linked repositories, 6 carry a function identity and 0 do not. Of the 6 distinct functions with an identity, 4 are also present in other papers whose code we hold (4 with at least one paper dated earlier, 0 the same month, 1 later) and 2 are only here among the 52,977 papers whose code Syntology holds (as of 2026-09-26).

Only here means: among the 52,977 papers whose code Syntology holds (51,887 with lifted samples, 1,090 through their assemblies only), as of 2026-09-26, no other paper's lifted samples or current assembly bricks contain an identical function body after normalisation.

FunctionAlso present inEarliest-datedOthers named
compute_metrics 6 other papers
5 dated earlier, 1 same year, order not determinable
2401.06121 (2024-01)
TOFU: A Task of Fictitious Unlearning for LLMs
2406.13356 (2024-06)
UNLEARNING OR OBFUSCATING? JOGGING THE MEM-ORY OF UNLEARNED LLMS VIA BENIGN RELEARNING CONTENT WARNING: THIS MANUSCRIPT CONTAINS EXAMPLES OF HARMFUL/HAZARDOUS TEXT
2407.16997 (2024-07)
Revisiting Who's Harry Potter: Towards Targeted Unlearning from a Causal Intervention Perspective
and 3 more not named here
get_loss 5 other papers
5 dated earlier
2401.06121 (2024-01)
TOFU: A Task of Fictitious Unlearning for LLMs
2406.11614 (2024-06)
Intrinsic Test of Unlearning Using Parametric Knowledge Traces
2406.13356 (2024-06)
UNLEARNING OR OBFUSCATING? JOGGING THE MEM-ORY OF UNLEARNED LLMS VIA BENIGN RELEARNING CONTENT WARNING: THIS MANUSCRIPT CONTAINS EXAMPLES OF HARMFUL/HAZARDOUS TEXT
and 2 more not named here
get_batch_loss 4 other papers
3 dated earlier, 1 later
2307.13702 (2023-07)
Measuring Faithfulness in Chain-of-Thought Reasoning
2409.11844 (2024-09)
MEOW: MEMOry Supervised LLM Unlearning Via Inverted Facts
2502.14829 (2025-02)
Measuring Chain of Thought Faithfulness by Unlearning Reasoning Steps
and 1 more not named here
unlearncollector 2 other papers
2 dated earlier
2404.18239 (2024-04)
SOUL: Unlocking the Power of Second-Order Optimization for LLM Unlearning
2410.17509 (2024-10)
WAGLE: Strategic Weight Attribution for Effective and Modular Unlearning in Large Language Models

Presence, not direction: an identical function body in two papers' repositories does not say who wrote it, which came from which, or that either paper's method rests on it. Matching is exact after normalisation, so a renamed or edited function is not matched. Dates are when papers appeared, not when code was written. Only .py files the harvester lifted are covered; notebooks are not read. A new-style arXiv id YYMM.NNNN dates a paper to the month 20YY-MM; otherwise Paper.year dates it to the year; otherwise it is undated. Dates are when the paper appeared, not when the code was written. Read 2026-11-23.

Repositories linked to this paper

Some links come from the archived Papers with Code dataset (CC BY-SA 4.0): attribution and licence.

Abstract

Machine unlearning offers a promising solution to privacy and safety concerns in large language models (LLMs) by selectively removing targeted knowledge while preserving utility. However, current methods are highly sensitive to downstream fine-tuning, which can quickly recover forgotten information-even from unrelated tasks. To address this, we introduce invariance into unlearning for the first time, inspired by invariant risk minimization (IRM). Building on this principle, we propose invariant LLM unlearning (ILU), a regularization-based framework that enhances robustness. Notably, ILU generalizes well to diverse fine-tuning tasks, even when trained using a single dataset. A task vector analysis is also provided to further elucidate the rationale behind ILU's effectiveness. Extensive experiments on the WMDP and MUSE benchmark, reveal that ILU significantly outperforms state-of-the-art unlearning methods, including negative preference optimization (NPO) and representation misdirection for unlearning (RMU). Notably, ILU achieves superior unlearning robustness across diverse downstream fine-tuning scenarios (e.g., math, paraphrase detection, and sentiment analysis) while preserving the fine-tuning performance. Our experiments and codes are available at https://github.com/OPTML-Group/Unlearn-ILU.

For agents

The same record, over MCP at https://syntology.ai/mcp:

get_harvested_code_for_paper("2506.01339")
get_code_for_paper("2506.01339")
have("2506.01339")

The run record, dated, one paper per request, free:

curl https://syntology.ai/api/ran/2506.01339.json

A badge for a README (the split and the date, never a ratio):

[![Syntology run record](https://syntology.ai/api/ran/2506.01339.svg)](https://syntology.ai/paper/2506.01339)

Connect an agent — have() is free.