Skip to content

zjunlp/unlearn

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Knowledge Unlearning for Large Language Models

📄arXiv🤗HFPaper🤗HF Collection

This repository provides the official PyTorch implementation of our paper:

ReLearn: Unlearning via Learning for Large Language Models

Haoming Xu1, Ningyuan Zhao2, Liming Yang3, Sendong Zhao4, Shumin Deng5, Mengru Wang1, Bryan Hooi5, Nay Oo5, Huajun Chen1, Ningyu Zhang1

1Zhejiang University, 2Xiamen University, 3Tsinghua University, 4Harbin Institute of Technology, 5National University of Singapore

🎉 News

🏆 Our team won 2nd place in the SEMEval 2025 Challenge on Unlearning Sensitive Content from Large Language Models! Check out our implementation in the Semeval25 directory.

🌟 Overview

Introduction

📦 Installation

# Create and activate conda environment
conda create -n relearn python=3.10.15
conda activate relearn

# Install PyTorch with CUDA support
conda install pytorch pytorch-cuda=11.8 -c pytorch -c nvidia
conda install -c "nvidia/label/cuda-11.8.0" cuda-toolkit

# Install dependencies
pip install -r requirements.txt
pip install flash-attn --no-build-isolation

🚀 Quick Start

1. Data Augmentation

cd dataAugument
bash augu.sh

2. Model Training

Currently supports:

  • Llama3-8b instruct
  • Gemma2-2b-it
  • Llama2-7b chat
cd baselines/pretrain_scripts/
bash kud-pt.sh

3. Unlearning Process

cd baselines/unlearn_scripts/
bash kud-relearn.sh

4. Evaluation

cd evals
bash merge_all.sh
bash inf_all.sh
bash eval_all.sh

🔧 Supported Methods

Method Script Source & Notes
GA / NPO unlearn/baselines/unlearn_scripts/kud-baselines.sh Source
SURE unlearn/baselines/unlearn_scripts/kud-baselines.sh Source
Memflex unlearn/baselines/unlearn_scripts/kud-baselines.sh Source (Iterative version)
ReLearn unlearn/baselines/unlearn_scripts/kud-relearn.sh Our Method
ReLearn_dpo unlearn/baselines/unlearn_scripts/kud-relearn.sh Uses augmented data as positive samples

📂 Open Resources

Pretrained Models

Datasets

🙏 Acknowledgements

This repository builds upon code from:TOFU and MUSE.

We thank the authors for their excellent work.

📝 Citation

If you find this work useful for your research, please cite our paper:

@misc{xu2025relearnunlearninglearninglarge,
      title={ReLearn: Unlearning via Learning for Large Language Models}, 
      author={Haoming Xu and Ningyuan Zhao and Liming Yang and Sendong Zhao and 
              Shumin Deng and Mengru Wang and Bryan Hooi and Nay Oo and 
              Huajun Chen and Ningyu Zhang},
      year={2025},
      eprint={2502.11190},
      archivePrefix={arXiv},
      primaryClass={cs.CL},
      url={https://arxiv.org/abs/2502.11190}
}