How yaojin17/unlearning_llm works
Project Type and Purpose
• This is a research and experimentation framework for exploring “machine unlearning” in pre-trained LLMs.
• The README, along with file names (e.g., ascent_plus_descent, gradient_ascent, etc.), shows that the system provides several methods to “unlearn” specific data from a model.
• It also supports evaluation pipelines (including membership inference attack evaluation) and tokenization utilities for preparing datasets.
File Structure
• Top-Level Files: The repo has common software files such as .gitignore, LICENSE, README.md, requirements.txt, and setup.py.
• Main Application Directory: “llm_unlearn” contains the core code.
– Subdirectory “methods”: This contains different unlearning strategies such as gradient_ascent, ascent_plus_descent, ascent_plus_KLdivergence, and unlearning_argument.
– Subdirectory “utils”: This hosts various helper scripts for tokenization, dataset preparation, evaluation (MIA evaluation, top-k sampling), and common utilities.
– Script Files (run_unlearn.py, run_eval.py, run_mia.py): These are the main entry points for unlearning experiments, evaluation runs, and membership inference attacks, respectively.
• The file structure clearly separates unlearning methods from utilities, hinting at a modular design.
README for Additional Insights
• The README explains the experimental framework, external dependencies (like the Yi-6B model and the unlearn_dataset from Hugging Face), and detailed steps to run tokenization, unlearning, evaluation, and membership inference experiments.
a. Main Components:
– External Dependencies:
▪ Pre-trained Yi-6B model (downloaded separately; an external component).
▪ Unlearn Dataset (fetched via Hugging Face).
– Data Preparation & Tokenization:
▪ Tokenized dataset creation using utilities (e.g., save_tokenized_dataset.py, ascent_plus_descent_tokenizer.py).
– Unlearning Engine:
▪ Core experiment runner from run_unlearn.py which orchestrates the unlearning pipeline.
▪ Unlearning Methods Module: Contains individual strategy implementations (gradient_ascent, ascent_plus_descent, etc.).
– Evaluation Subsystem:
▪ run_eval.py which evaluates unlearned models.
– Membership Inference Attack (MIA) Module:
▪ run_mia.py and associated utilities (mia_eval.py) that evaluate privacy risks.
– Utility/Helper Functions:
▪ Additional utilities for tokenization, embedding resize, and top-k sampling.
b. Relationships and Interactions:
– The “External Dependencies” (pre-trained model and dataset) feed into the “Data Preparation & Tokenization” module.
– Prepared data then flows into the “Unlearning Engine”, where one of several “Unlearning Methods” is applied.
– The output model from unlearning feeds into the “Evaluation Subsystem” (for model performance) and the “MIA Module” (for membership inference attack evaluation).
– Utility functions support these processes throughout, ensuring smooth tokenization, sampling, and data transformation.
c. Architectural Patterns or Design Principles:
– Modularity: Separation into distinct directories (methods vs. utils) to encapsulate different functionalities.
– Configurability: The unlearning method is parameterized (via command-line arguments) to select among multiple strategies.
– Pipeline Flow: A clear sequential data flow from dataset preparation to experiment execution, evaluation, and attack assessment.
d. Relevant Technologies, Frameworks, or Libraries:
– PyTorch (as indicated by the use of torchrun and specific GPU-related settings).
– Hugging Face Datasets (for loading the unlearn_dataset).
– WandB is referenced (for logging, as indicated by the need to replace the wandb key) and possibly other experimental tracking tools.
– Python’s argparse-based command line interfaces are implied in the runner scripts.