Coder Social home page Coder Social logo

fl-analysis's Introduction


Logo

Federated Learning with Adversaries

Table of Contents
  1. About The Project
  2. Getting Started
  3. Usage
  4. License
  5. Contact

About the Project

This framework can be used to simulate and analyse a federated learning setting in which some clients are compromised by an adversary. The adversary attempts to compromise the integrity of the shared global model by sending malicious updates to the server.

The framework was used to perform the analysis of federated learning robustness under a norm bound defense as part of RoFL: Attestable Robustness for Secure Federated Learning. A research implementation of the secure federated learning with constraints framework can be found here.

Backdoor attacks

In federated learning, adversaries can perform backdoor attacks to poison the global model. This framework implements existing attack strategies such as model replacement, on a wide variety of tasks and backdoor attack targets proposed in previous work, such as attacks on prototypical targets or edge cases.

Robustness

The framework provides several tools to analyse client updates, measure backdoor performance and deploy defenses to gain insight on model robustness in federated learning.

Getting Started

We now describe how to set up this framework.

Requirements

The dependencies can be automatically installed through pipenv. The high-level requirements are as follows.

  • Python 3 (tested on version 3.7)
  • TensorFlow (version 2.0)

Before starting, ensure that you have pipenv installed:

pip install pipenv

Installation

  1. Clone the repo
git clone https://github.com/pps-lab/fl-analysis.git
  1. Install the Python packages
pipenv install

Usage

The configuration of the framework is specified in a config file in YAML format. A minimal example of a config is shown below.

environment:
  num_clients: 3383
  num_selected_clients: 30
  num_malicious_clients: 0
  experiment_name: "Sample run without attackers"

server:
  num_rounds: 80
  num_test_batches: 5
  aggregator:
    name: FedAvg
  global_learning_rate: -1

client:
  clip:
    type: l2
    value: 10
  model_name: resnet18
  benign_training:
    num_epochs: 2
    batch_size: 24
    optimizer: Adam
    learning_rate: 0.001

dataset:
  dataset: femnist
  data_distribution: nonIID

The full specification of the supported config options can be found here Some example config files can be find in train_configs.

Sample usage:

With a config file config.yml ready, the framework can be started by invoking:

python -m src.main -c config.yml

Available models

Some pre-trained models are available in the models for experiments and can be included in training using the environment.load_model config key.

  • lenet5_emnist_088.h5 LeNet5 for federated-MNIST at 0.88 accuracy.
  • lenet5_emnist_097.h5 LeNet5 for federated-MNIST at 0.97 accuracy.
  • lenet5_emnist_098.h5 LeNet5 for federated-MNIST at 0.98 accuracy.
  • resnet18.h5 ResNet18 for CIFAR-10 at 0.88 accuracy.
  • resnet18_080.h5 ResNet18 for CIFAR-10 at 0.80 accuracy.
  • resnet18_082.h5 ResNet18 for CIFAR-10 at 0.82 accuracy.
  • resnet156_082.h5 ResNet56 for CIFAR-10 at 0.86 accuracy.

Output

Basic training progress is sent to standard output. More elaborate information is stored in an output folder. The directory location can be specified through the XXX option. By default, its ... . The framework stores progress in tfevents, which can be viewed using Tensorboard, e.g.,

tensorboard --logdir ./experiments/{experiment_name}

License

This project's code is distributed under the MIT License. See LICENSE for more information.

Contact

Project Links:

fl-analysis's People

Contributors

hiddely 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

Watchers

 avatar  avatar  avatar  avatar  avatar

fl-analysis's Issues

Low Training Accuracy

Hi,

I am getting very low accuracy when running training without any malicious clients. For ResNet18 for Cifar10, the accuracy peaks at about 0.25 and starts getting worse after that with increasing rounds.

I am using the same parameters as mentioned in the RoFL paper, here is my config.yml file (accuracy stays bad even when I remove clipping):

environment:
  num_clients: 100
  num_selected_clients: 40
  num_malicious_clients: 0
  experiment_name: "Sample run without attackers"

load_model: ./models/resnet18.h5

server:
  num_rounds: 20
  num_test_batches: 50
  aggregator:
    name: FedAvg
  global_learning_rate: 1

client:
  clip:
    type: l8
    value: 10
  model_name: resnet18
  benign_training:
    num_epochs: 2
    batch_size: 64
    optimizer: SGD
    learning_rate: 0.02
    step_decay: true

dataset:
  dataset: cifar10
  data_distribution: nonIID

Since the readme on the repo says that the included models are pre-trained, do you know why am I seeing such low accuracy? Here is a sample run for 2 rounds:

INFO:root:Starting training...
round= 0 	test_accuracy= 0.0859375 	adv_success= 0 	test_loss= 4.521559
DEBUG:root:Memory info: 2522755072
round= 1 	test_accuracy= 0.10375 	adv_success= 0 	test_loss= 2.4279819 	duration= 270.714478969574
DEBUG:root:Memory info: 2390228992

For a pre-trained model, shouldn't the test_accuracy of round 0 be already good?

Thanks for the help in advance!

name'DataHolder' is not defined

when I run python -m src.main -c config.yml, there will be a NameError: name 'DataHolder' is not defined. The I found the src.torch_compat.py is missed.

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.