Skip to content

Applied-Machine-Learning-Lab/MM4KE

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Model Merging for Knowledge Edit

This repository contains modified versions of EasyEdit and mergekit for experiments on model merging after knowledge editing.

Quick Start

Installation

git clone https://github.com/Applied-Machine-Learning-Lab/MM4KE.git
cd MM4KE
conda create -n MM4KE python=3.9.7
conda activate MM4KE

# Install EasyEdit dependencies
cd EasyEdit
pip install -r requirements.txt

# Install mergekit dependencies
cd ../mergekit
pip install -e .

Knowledge Edit

cd EasyEdit/examples
python run_knowedit_llama2.py \
    --editing_method=FT \
    --hparams_dir=../hparams/FT/qwen2.5-7b \
    --data_dir=./data \
    --datatype='counterfact'

Model Merging

cd ../../mergekit
mergekit-pytorch examples/task_arithmetic.yml ./output_pytorch_model_directory

Changes

Changes of EasyEdit

  1. Sequential Editing Support (EasyEdit/examples/run_knowedit_llama2.py#L265)

    • Added sequential_edit=True parameter to enable sequential knowledge editing
  2. Extended Training Epochs (EasyEdit/easyeditor/editors/editor.py#L375-376)

    • Added epoch loop with epoch = 5 for improved editing performance
    • Allows multiple training iterations over the edit data
  3. Qwen2.5 Model Support (EasyEdit/hparams/FT/qwen2.5-7b.yaml)

    • Added configuration file for Qwen2.5-7B model
    • Enables knowledge editing on the latest Qwen model series

Changes of mergekit

  1. Sparsification for Task Arithmetic (mergekit/mergekit/merge_methods/registry.py#L31)
    • Added sparsification_method=SparsificationMethod.magnitude to task arithmetic merging
    • Enables sparsification similar to TIES method but without TIES regularization
    • Allows for more controlled model merging with magnitude-based pruning

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 43