Giter VIP home page Giter VIP logo

fedsgd-dpc's Introduction

Optimizing the Numbers of Queries and Replies in Federated Learning with Differential Privacy

This repository is the source code for the paper: https://arxiv.org/pdf/2107.01895.pdf

Requirements

To install requirements:

pip install -r requirements.txt
  • Python3
  • Pytorch
  • Torchvision
  • TensorflowPrivacy

Datasets

We provide two datasets under corresponding folders.

  • MNIST: 10 different classes, 70,000 handwritten digit images with 28 by 28 gray-scale pixels.
  • FEMNIST: 62 different classes (10 digits, 26 lowercase, 26 uppercase), images are 28 by 28 pixels (with option to make them all 128 by 128 pixels), 3500 users.

For quickly generating datasets, run the following scripts in data folders:

python generate_data.py -N 10 -dataset mnist
python generate_data.py -N 10 -dataset femnist

References

@misc{title={LEAF: A Benchmark for Federated Settings},
author={Sebastian Caldas and Sai Meher Karthik Duddu and Peter Wu and Tian Li and Jakub Konečný and H. Brendan McMahan and Virginia Smith and Ameet Talwalkar},
year={2018},
eprint={1812.01097},
archivePrefix={arXiv},
primaryClass={cs.LG}
}

Parameter Estimation

We estimate the problem-specific parameters with two methods: learning process and random initialization.

  • learning process: each client achieves its local optimal all by oneself, so total iterations T and local iterations E have the same value (e.g., 200). The results of estimation are saved in estimate/$dataset/clients_$N/.
python estimate.py -dp=laplace -dataset=mnist -T=200 -E=200 -N=10 -b=10 -q=1.0
python estimate.py -dp=gaussian -dataset=mnist -T=200 -E=200 -N=10 -b=10 -q=0.01
  • random initialization: each client randomly initializes its model parameters and performs SGD steps. The results of estimation are saved in estimate/$dataset/clients_$N/.
python estimate.py -dp=laplace -dataset=mnist -T=100 -E=100 -N=10 -b=10 -q=1.0 -random
python estimate.py -dp=gaussian -dataset=mnist -T=100 -E=100 -N=10 -b=10 -q=0.01 -random

Optimizing T and b

Calculate the optimal values of T and b according to parameters estimated above and the optimal results are stored in estimate/$dataset/clients_$N/result/$dp

python cal_optimal.py -dataset=mnist -dp=laplace -N=10 -p=7840 -d=60000 -C=300
python cal_optimal.py -dataset=mnist -dp=gaussian -N=10 -p=7840 -d=60000 -C=10

Training

Training with optimal values of T and b, and other candidates. The results of loss and accuracy are in result result/$dataset/clients_$N

python batch_dp_train.py -dp laplace -dataset mnist -S 10 -q 1.0 -C 300
python batch_dp_train.py -dp gaussian -dataset mnist -S 10 -q 0.01 -C 10

Results

  • log/: training log.
  • estimate/$dataset/clients_$N/result/$dp/: estimated parameters and optimal results.
  • result/$dataset/client_$N/: training (test) loss and accuracy.

Code Parameters

  • -q := sampling probability, 1.0 for Laplace mechanism, or 0.01 for Gaussian mechanism
  • -dataset := datasets used, either mnist or femnist.
  • -p := number of model parameters, e.g., 7,840 and 11,0526 for mnist and femnist, respectively.
  • -d := total number of training datasets, e.g. 60,000 for mnist.

fedsgd-dpc's People

Contributors

liuliuliu0605 avatar

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.