Code Monkey home page Code Monkey logo

per-fedavg's Introduction

Personalized federated learning with theoretical guarantees: A model-agnostic meta-learning approach [NIPS 2020]

PyTorch Implementation of Per-FedAvg.

For simulating Non-I.I.D scenario, the dataset is split by labels and each client has only two classes of data.

It’s just a toy demo for demonstrating algorithm, so take it easy. 🀣

Note that I have recently released a benchmark of federated learning that includes this method and many ohter baselines. Welcome to check my benchmark and star it! πŸ€—

Requirements

torch~=1.10.2
path~=16.4.0
numpy~=1.21.2
fedlab~=1.1.4
torchvision~=0.11.3
rich~=12.2.0
pip install -r requirements.txt

Preprocess dataset

MNIST and CIFAR-10 is prepared.🌟

cd data; python preprocess.py

The way of preprocessing is adjustable, more details in each dataset folder's preprocess.py.

Run the experiment

Before run the experiment, please make sure that the dataset is downloaded and preprocessed already.

It’s so simple.πŸ€ͺ

python main.py

Hyperparameters

--global_epochs: Num of communication rounds. Default: 200

--local_epochs: Num of local training rounds. Default: 4

--pers_epochs: Num of personalization rounds (while in evaluation phase). Default: 1

--dataset: Name of experiment dataset. Default: mnist

--fraction: Percentage of training clients in all alients. Default: 0.9

--client_num_per_round: Num of clients that participating training at each communication round. Default: 5

--alpha: Learning rate $\alpha$ in paper. Default: 0.01

--beta: Learning rate $\beta$ in paper. Default: 0.001

--gpu: Non-zero value for using CUDA; 0 for using CPU. Default: 1

--batch_size: Batch size of client local dataset. Default: 40.

--eval_while_training: Non-zero value for performing evaluation while in training phase. Default: 1

--valset_ratio: Percentage of validation set in client local dataset. Default: 0.1

--hf: Non-zero value for performing Per-FedAvg(HF); 0 for Per-FedAvg(FO). Default: 1

--seed: Random seed for init model parameters and selected clients. Default: 17

--log: Non-zero value for recording experiment's output to a .html file in ./log. Default: 0

per-fedavg's People

Contributors

karhoutam 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

Watchers

 avatar  avatar

per-fedavg's Issues

question about SGD one step

In the section 5, the author wrote "Note that the model obtained by any of these three methods is later updated using one step of stochastic gradient descent at the test time".
May I ask you why the testset data is used here instead of the validation set data ? This problem confuses me a lot.

About gradient descent on the client side

Hi, Jiahao Tan.
Thanks for your work.

I have some confusion about the code on lines 98 of "per-fedavg /perfedavg.py".
param.data.sub_(self.beta * grad1 - self.beta * self.alpha * grad2)
According to the formula in the article, I think "self.beta * self.alpha * grad2" seems to miss "grad1".

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.