Code Monkey home page Code Monkey logo

lte's Introduction

Learning to Edit: Aligning LLMs with Knowledge Editing (ACL 2024)

Github HuggingFace

We introduces a novel Learning to Edit (LTE) framework for effective and efficient knowledge editing of large language models (LLMs). our LTE framework focuses on teaching LLMs to apply updated knowledge into input questions, inspired by the philosophy of "Teach a man to fish."

As the below figure shows, LTE features a two-phase process: (i) the Alignment Phase, which fine-tunes LLMs on a meticulously curated parallel dataset to make reliable, in-scope edits while preserving out-of-scope information and linguistic proficiency; and (ii) the Inference Phase, which employs a retrieval-based mechanism for real-time and mass knowledge editing.



⚙️ How to implement

Requirements

Note: Please use Python 3.10+ for LTE. To get started, simply install conda and run:

conda create -n LTE python=3.10
conda activate LTE
conda install pytorch==2.1.1 torchvision==0.16.1 torchaudio==2.1.1 pytorch-cuda=12.1 -c pytorch -c nvidia
pip install -r requirements.txt

1. Alignment Phrase

Firstly, please download the training data of LTE from HuggingFace and put it into data/.

LLaMA2-Chat-7B

The code is based on FastChat. Standard fine-tuning was conducted on 4×A100 GPUs (80G) for about 9 hours.

cd LTE/
bash FastChat/ft_train.sh

To reduce the total memory footprint, LTE also supports LoRA, which fine-tunes low-rank slices of the query, key, and value embedding heads.

cd LTE/
bash FastChat/lora_train.sh

Qwen-Chat-7B

The code is based on Qwen. Standard fine-tuning was conducted on 4×A100 GPUs (80G) for about 9 hours.

cd LTE/
bash Qwen/finetune/finetune_ds.sh

To reduce the total memory footprint, LTE also supports LoRA, which fine-tunes low-rank slices of the query, key, and value embedding heads.

cd LTE/
bash Qwen/finetune/finetune_lora_single_gpu.sh

2. Inference Phrase

The evaluation of our proposed LTE is based on EasyEdit. Please download multi-qa-mpnet-base-dot-v1 and add it to "LTE/SeqEdit/multi-qa-mpnet-base-dot-v1".

Please run the following command for experiments of LLaMA2-Chat-7B:

cd LTE/
bash EasyEdit/run_lte_llama.sh
bash SeqEdit/run_lte_llama.sh

Please run the following command for experiments of Qwen-Chat-7B:

cd LTE/
bash EasyEdit/run_lte_qwen.sh
bash SeqEdit/run_lte_qwen.sh

📝 Citation

Please cite our paper if you use the data or code in this repo.

@misc{jiang2024lte,
      title={Learning to Edit: Aligning LLMs with Knowledge Editing}, 
      author={Yuxin Jiang and Yufei Wang and Chuhan Wu and Wanjun Zhong and Xingshan Zeng and Jiahui Gao and Liangyou Li and Xin Jiang and Lifeng Shang and Ruiming Tang and Qun Liu and Wei Wang},
      year={2024},
      eprint={2402.11905},
      archivePrefix={arXiv},
      primaryClass={cs.CL}
}

lte's People

Contributors

yjiangcm avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

lte's Issues

How to load LoRA model for evaluation?

Hello👋
Thank you for your great work for the community!

I've been trying to reproduce your results, but I'm a bit stuck. Due to the limited computing resources, I can only train Llama2-7b using LoRA. Still, there is only an evaluation script for full FT. So, I'm not sure how to use this script to evaluate the LoRA model.

Thank you in advance for your time and support!

Provide trained models

Hi @YJiangcm, the performance of the model trained using the code in this repository differs from that claimed in the paper.

At your convenience, would you provide the trained models for evaluation please? Thank you so much.

How to perform a batch edit experiment?

The base method adopted by LTE is the IKE method, but the batch_editor file shows that the IKE method does not support batch edit, so how is the batch edit experiment carried out in the paper?

OOM question

Excellent work! But I ran into OOM issue when i runing the lora method for llama-2-7b-chat model:

Specifically, I applied 4xA100(80GB) in the slurm system and then run the code below:
bash FastChat/lora_train.sh

The following error messages are displayed

torch.cudatorch.cuda..OutOfMemoryErrorOutOfMemoryError: : CUDA out of memory. Tried to allocate 2.00 GiB (GPU 0; 79.15 GiB total capacity; 77.13 GiB already allocated; 307.31 MiB free; 78.21 GiB reserved in total by PyTorch) If reserved memory is >> allocated memory try setting max_split_size_mb to avoid fragmentation. See documentation for Memory Management and PYTORCH_CUDA_ALLOC_CONFCUDA out of memory. Tried to allocate 2.00 GiB (GPU 3; 79.15 GiB total capacity; 77.13 GiB already allocated; 355.31 MiB free; 78.21 GiB reserved in total by PyTorch) If reserved memory is >> allocated memory try setting max_split_size_mb to avoid fragmentation. See documentation for Memory Management and PYTORCH_CUDA_ALLOC_CONF

I'm confused about this situation, lora should be a peft method, why this OOM issue could occur when applying 4xA100(80GB)?
What could be the reason, please?

Clarification on Ablation Study for Retrieval Number and Additional Code Request

Hi there,
I am running the code in the repo and notice that prompt and target_new are being used directly as updated information without retrieval. I'm curious about how you've approached the ablation study for the retrieval number k. Are you following the IKE method? Also, would it be possible to share more code to shed light on this process?

Thanks for the fantastic work you're doing! I can't wait to hear back from you.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.