Git Product home page Git Product logo

hitsz-tmg / ext-sub Goto Github PK

View Code? Open in Web Editor NEW
6.0 1.0 2.0 78.6 MB

Official implementation of our paper "Separate the Wheat from the Chaff: Model Deficiency Unlearning via Parameter-Efficient Module Operation". A model merge method for deficiency unlearning, compitable with huggingface peft (LoRA).

Home Page: https://arxiv.org/abs/2308.08090

License: MIT License

Python 98.63% Shell 1.37%

ext-sub's Introduction

Separate the Wheat from the Chaff: Model Deficiency Unlearning via Parameter-Efficient Module Operation

โœจ Overview

Code for the paper "Separate the Wheat from the Chaff: Model Deficiency Unlearning via Parameter-Efficient Module Operation".

๐Ÿ’ป Usage

๐ŸŒˆ Environment

conda create -n EXT-SUB python=3.10
conda activate EXT-SUB
pip install -r requirements.txt

or you can simply copy our conda environment:

# You should edit the `prefix` parameter to your local conda path in `environment.yaml`.
conda env create -f environment.yaml
conda activate ext_sub

The utilization of Parameter-Efficient Modules in this work is based on PEFT. Further information can be available in the HuggingFace documentation.

๐Ÿ”ฅ Train

Run the training Bash script with custom parameters: model_name_or_path, data_path, output_dir

cd training
bash train_peft.sh

โš ๏ธ Note: The training code from Alpaca was leveraged in order to resize the embedding of models, thereby incorporating a pad token. When saving the tokenizer after training, it now includes the pad token, which is not present in the original model (as only the PEMs were saved). To effectively utilize the pad token during testing, it is advisable to either resize the embedding once more or substitute the pad token with an existing token.

๐Ÿ”จ PEMs Operation

python ext_sub.py \
  --input_path_1  Your/Expert/PEMs/Path \
  --input_path_2  Your/Anti-Expert/PEMs/Path \
  --alpha 1.0 \
  --method ext-sub \
  --output_path  Your/Output/PEMs/Path

๐Ÿš€ Load Model

from transformers import AutoTokenizer, AutoModelForCausalLM
from peft import PeftConfig, PeftModel


model_name_or_path = ""

config = PeftConfig.from_pretrained(model_name_or_path)
model = AutoModelForCausalLM.from_pretrained(config.base_model_name_or_path, torch_dtype=torch.float16, device_map="auto")
model = PeftModel.from_pretrained(model, model_name_or_path)
model = model.cuda()

tokenizer = AutoTokenizer.from_pretrained(config.base_model_name_or_path, use_fast=False)

๐Ÿ“Š Evaluation

Coming soon

๐Ÿ“ Download

We have made our trained LoRA checkpoints available through Google Drive.

The base model can be obtained from the HuggingFace model hub: huggyllama/llama-7b and huggyllama/llama-13b. Please remember to modify the base_model_name_or_path in the adapter_config.json file to the local path on your system.

๐Ÿค” Insight

Our method tends to prefer contrasting positive and negative examples with larger differences, unlike preference data in DPO or PPO. This implies that generating negative samples becomes more straightforward and convenient in this approach, not requiring hard negatives.

๐Ÿ”— Cite

@article{hu2023separate,
  title={Separate the Wheat from the Chaff: Model Deficiency Unlearning via Parameter-Efficient Module Operation},
  author={Hu, Xinshuo and Li, Dongfang and Zheng, Zihao and Liu, Zhenyu and Hu, Baotian and Zhang, Min},
  journal={arXiv preprint arXiv:2308.08090},
  year={2023}
}

๐Ÿ“œ License

This repository respects to MIT license.

ext-sub's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

ext-sub's Issues

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.