Giter VIP home page Giter VIP logo

openfedllm's Introduction

OpenFedLLM: Training Large Language Models on Decentralized Private Data via Federated Learning

OpenFedLLM is an open-source research-use codebase for training Large Language Models (LLM) via federated learning. Please check our paper for details and the corresponding empirical study.

OpenFedLLM includes the following key features:

  • 7 federated learning algorithms (e.g., FedAvg, FedProx, SCAFFOLD, FedAvgM, etc.).
  • 2 LLM training algorithms, including instruction tuning (i.e. SFT) and value alignment (i.e., DPO).
  • 30+ evaluation metrics covering general capabilities, medical QA, financial QA, code generation, math solving, and more.

intro

Setup

Clone the repo and install the required packages.

git clone https://github.com/rui-ye/OpenFedLLM.git
cd OpenFedLLM
conda create -n fedllm python=3.10
conda activate fedllm
pip install -r requirements.txt

Training

We provide training scripts under training_scripts/. Try them out from the top-level directory of this repository.

Federated Instruction Tuning

The training script is in training_scripts/run_sft.sh.

CUDA_VISIBLE_DEVICES=1 python main_sft.py \
 --model_name_or_path "meta-llama/Llama-2-7b-hf" \
 --dataset_name "vicgalle/alpaca-gpt4" \
 --dataset_sample 20000 \
 --fed_alg "fedavg" \
 --num_clients 20 \
 --sample_clients 2 \
 --max_steps 10 \
 --num_rounds 200 \
 --batch_size 16 \
 --gradient_accumulation_steps 1 \
 --seq_length 512 \
 --peft_lora_r 32 \
 --peft_lora_alpha 64 \
 --use_peft \
 --load_in_8bit \
 --output_dir "./output" \
 --template "alpaca" \

Key arguments:

  • model_name_or_path: the name or local location of your base model
  • template: template for chatting. Define your own template in utils/template.py.
  • dataset_name: the name of dataset. You may modify utils/process_dataset.py if your interested dataset has not been supported.
  • dataset_sample: needed if you want to sample a specific number of samples from the original dataset.
  • fed_alg: the name of federated learning algorithm
  • num_clients/sample_clients: num_clients clients in total, sample_clients clients for each round
  • max_steps: the number of model update steps for one client at each round.

Federated Value Alignment

The training script is in training_scripts/run_dpo.sh.

python main_dpo.py --template "vicuna_v1.1"

Note that the main difference between the usage of main_sft.py and main_dpo.py lies in the template argument. We plan to make them consistent in the future.

  • For SFT, templates are defined in utils/template.py
  • For DPO, templates are defined in utils/conversation.py

Evaluation

Evaluation codes are put in evaluation/ directory. Most of our evaluations follow existing high-incluence open-source repos. Please refer to each sub-directory for the corresponding detailed README and running script.

For example, evaluation/open_ended/ include open-ended evaluations on three benchmarks, covering MT-Bench, Vicuna Bench, and AdvBench; see README.md.

Citation

Please cite our paper if you find the repository helpful.

@article{ye2024openfedllm,
  title={OpenFedLLM: Training Large Language Models on Decentralized Private Data via Federated Learning},
  author={Ye, Rui and Wang, Wenhao and Chai, Jingyi and Li, Dihan and Li, Zexi and Xu, Yinda and Du, Yaxin and Wang, Yanfeng and Chen, Siheng},
  journal={arXiv preprint arXiv:2402.06954},
  year={2024}
}

openfedllm's People

Contributors

eltociear avatar marmotatzju avatar motigrez avatar rui-ye avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  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

openfedllm's Issues

Evaluation on other datasets?

Hello and thank you for your great work. In addition to MT-Bench, Vicuna benchmark, and Advbench, do you have test details or codes for the other datasets?

Results of training on Alpaca-GPT4 and testing on MT-Bench

Hello, directly run your code, the configuration has not changed, the test steps are also according to your evaluation/open_ended process, but gen_judge_mtbench.py results are all ERROR. What's the problem? Looking forward to your reply.

Run the following command:

  1. sh training_scripts/run_sft.sh
  2. python utils/merge_lora.py --base_model_path "meta-llama/Llama-2-7b-hf" --lora_path "output/alpaca-gpt4_20000_fedavg_c20s2_i10_b16a1_l512_r32a64_20240313104822/checkpoint-200"
  3. CUDA_VISIBLE_DEVICES=2 python gen_model_answer_mt.py --base_model_path "../../output/alpaca-gpt4_20000_fedavg_c20s2_i10_b16a1_l512_r32a64_20240313104822/full-200" --template "alpaca"
  4. python gen_judge_mtbench.py --judge_model gpt-4-1106-preview --model_list alpaca-gpt4_20000_fedavg_c20s2_i10_b16a1_l512_r32a64_20240313104822_200
  5. python show_results_mt.py --model_list alpaca-gpt4_20000_fedavg_c20s2_i10_b16a1_l512_r32a64_20240313104822_200 --judge_model gpt-4-1106-preview

Here are the results of running on the A40:
model_answer.zip
model_judgment.zip

Continue training according to checkpoint

I have generated several checkpoint model folders after 200 rounds of training, can I continue training with this model next time? If so, how to use the trained model parameters.

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.