This repository contains the code for simulating the fine-tuning of Language Model Models (LLMs) in a federated learning setting for Code Tasks. The users can configure the model, fine-tuning technique, federated aggregation implementations for the FL simulation according to code task at hand.
Tool demonstration video: https://youtu.be/-byKkaiBchw
git clone https://github.com/rishalab/LLM2FedLLM.git
cd LLM2FedLLM
pip install -r requirements.txt- Place your HuggingFace Access Token in the .env file.
- Modify the experiments/configs/fed_config.py and experiments/configs/llm_config.py files to set the desired configurations for the federated learning setting and LLM fine-tuning respectively.
- Unzip the datasets.zip file in the experiments directory to get the sample datasets.
- Make sure to have a snapshots of the experiments/output directory to prevent overwriting & appending of the results.
- Clear the output directory if you want to start fresh.
- Make sure you have placed the datasets in the datasets directory and edited the config files accordingly. Refer to example datasets in the experiments/datasets directory.
experiments/datasets/
---> code_docstring_corpus_data_test/
---> code_docstring_corpus_data_train/For FL client split, split the data into required no of clients based on the unique marker (such as project, task, etc) in the dataset.
experiments/datasets/
---> client_datasets/client_*/- General command to run the experiments.
cd experiments
python3 <*>.py- Run the central training script to train & evaluate the LLM on the central server.
python3 central.py- Run the federated learning script to train & evaluate the LLM in the federated setting.
python3 fed0.py- Edit the fed_config.py file to set the desired number of rounds.
- Run the federated learning script to train & evaluate the LLM in the federated setting using any Federated aggregation implentation such as FedAvg.
python3 fedn.pyBy default the experiment will run the evaluation for central, fed0, fedn setting and generate the metric results in the output directory and anecdotal results in the experiments directory.
- Edit the run_fedNBest to True and set the id of the best model to be used for the federated learning evaluation.
python3 fedn.py- Edit the run_clientEvaluation to True.
python3 fedn.py