Authors: Krishna Pillutla, Kshitiz Malik, Abdelrahman Mohamed, Michael Rabbat, Maziar Sanjabi, Lin Xiao
Contact: pillutla@cs.washington.edu, linx@fb.com
Install PyTorch version 1.9 for your appropriate cuda version, as well torchvision and torchaudio.
Then, install other dependences with pip install -r requirements.txt
.
Here is the outline:
- The implementations of various federated optimization algorithms and federated dataloaders are in the folder
pfl
- There are two main files:
train_pfl.py
andtrain_finetune.py
- All the scripts are in the
scripts/
folder
The overall pipeline for each task is:
- Pretrain the model without personalization (i.e., using FedAvg variants)
- Personalize with partial model personalization (using the proposed FedAlt or FedSim) or pFedMe. Note that this stage does not apply for finetuning or Ditto (finetuning with L2 regularization)
- Finetune locally (for PFL, pFedMe and Ditto)
The two main files are:
train_pfl.py
: for non-personalized pretraining (FedAvg variants) or federated personalization (partial peronsalization with FedAlt/FedSim or pFedMe). These correspond to steps 1 and 2 of the experiment pipeline.train_finetune.py
: for personalization with local finetuning. Run directly on the pretrained model for full model finetuning or Ditto. Run on the output of personalization for partial personalization and pFedMe. This corresponds to step 3 of the experiment pipeline.
Here is the breakdown of the directory scripts/federated
. This contains the scripts to run steps 1 and 2 of the pipeline.
scripts/federated/pretrain
: pretrain each model with FedAvg variantsscripts/federated/partial_personalization
: train partial personalization with stateful clientsscripts/federated/pfedme
: run personalization with pFedMescripts/federated/generalization_L2
: train partial personalization with local regularization (for the generalization experiments)scripts/federated/generaliazation_dropout
: train partial personalization with dropout (for the generalization experiments)
Here is the breakdown of the directory scripts/finetune
. This containts the scripts to run step 3 of the pipeline.
scripts/finetune/finetune
: finetune pretrained model either fully or partially (same model parts as partial personalization)scripts/finetune/ditto
: finetune pretrained models with L2 regularization (Ditto objective)scripts/finetune/partial_personalization
: finetune models trained with FedAlt/FedSimscripts/finetune/pfedme
: finetune pFedMe modelsscripts/finetune/generalization_L2
: finetune PFL + regularization modelsscripts/finetune/generalization_dropout
: finetune PFL + dropout models
The scripts for the experimental pipeline are:
- Pretrain in a non-personalized manner with FedAvg:
scripts/federated/pretrain/stackoverflow.sh
- Run FedAlt:
scripts/federated/partial_personalization/stackoverflow.sh
- Note: the saved model in step 1 is loaded again in step 2. Make sure the argumentpretrained_model_path
points to the correct checkpoint from step 1 - Local Finetuning:
scripts/finetune/partial_personalization/stackoverflow.sh
The codebase is constructed in a modular and extensible manner. The main functionality is divided into 3 parts: data, models and optimization.
Correspondingly, the folder pfl
contains the following subfolders:
pfl/data
: federated dataloaders, from which individual client dataloaders can be obtainedpfl/models
: implementation of the models. Includes splitting the model between the client and server parts, which can be accessed withmodel.client_parameters()
andmodel.server_parameters()
respectivelypfl/optim
: implementation of federated learning algorithms including FedAvg, partial personalization approaches (FedSim and FedAlt) as well as pFedMe
Each of these See the README in each of these folders for more details. The details on how to add new datasets or new optimization algorithms are given there. In the current implementation, a new dataset also requires models specific to these datasets to be implemented.
- Abstract out the datasets into different tasks, so that the models are not data dependent
- Multi-GPU training
This project is released under MIT License, which allows commercial use. See LICENSE for details.
If you find this repository useful, please consider giving a star ⭐ and citation:
@inproceedings{Pillutla2022pfl,
author = {Krishna Pillutla, Kshitiz Malik, Abdelrahman Mohamed, Michael Rabbat, Maziar Sanjabi, Lin Xiao},
title = {Federated Learning with Partial Model Personalization},
booktitle = {Proceedings of the 39th International Conference on Machine Learning (ICML'22)},
year = {2022},
}