Skip to content

denpalrius/bft-federated-learning

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Federated Learning with Byzantine Fault Tolerance (BFT)

This repository implements multiple Federated Learning strategies with Byzantine Fault Tolerance (BFT) to simulate and defend against attacks from malicious clients. It includes strategies like FedAvg, Krum, and Trimmed Mean, and supports four types of Byzantine attack strategies: Sign Flip, Gaussian Noise, Constant Bias, and Zero Update.

Install Dependencies

At the project root, install the required dependencies and set up the project by running:

pip install -e .

Loading Initial Weights

To modify the initial weights for the model, run the following notebook to generate new weights:

./notebooks/cifar10_cnn.ipynb

Running the Simulation Engine

To run the local simulation, execute the following command from the root of the repository:

flwr run .

For optimization advice, refer to the How to Run Simulations guide in the Flower documentation.

Federated Learning Parameters

Parameter Description & Impact Value Range Default Notes
num-server-rounds Frequency of global model updates. Higher values improve convergence but increase training time. 1-100 10 Critical for convergence.
options.num-supernodes Sets federation size. More nodes increase diversity but slow training. 3-100 7 System resource dependent.
fraction-fit Fraction of clients participating per round. Higher values offer better stability but increase computational load. 0.0-1.0 1.0 Values < 0.5 may cause instability.
local-epochs Local training intensity. More epochs improve local optimization but risk overfitting. 1-10 1 Balance with num-server-rounds.
batch-size Affects memory usage and training speed. Larger batches speed up training but may reduce accuracy. 16-512 32 Dependent on host memory.
byzantine-clients Number of malicious clients. More clients test defense mechanisms but can break training. 0-50% of clients 0 Monitor accuracy closely.
strategy-type Defines update aggregation method. Different strategies offer varying robustness to attacks. fedavg, krum, trimmed_mean fedavg Choose based on threat model.
byzantine-attack-strategy Defines attack vector. Different strategies test various vulnerabilities. sign_flip, gaussian_noise, zero_update none Match with defense strategy.
byzantine-attack-intensity Controls attack strength. Higher values test defense limits. 0.0-1.0 0.0 Strategy-dependent.
randomize-byzantine-strategy Enables random selection of attack strategies for Byzantine clients. true/false false Increases attack diversity.

Critical Combinations

  1. Defense Configurations

    • High Byzantine Clients → Use Krum/Trimmed Mean
    • Random Strategy → Lower Attack Intensity
    • Large Federation → Lower Fraction Fit
  2. Performance Configurations

    • More Local Epochs → Fewer Server Rounds
    • Higher Batch Size → More Clients per Round
    • Random Strategy → More Server Rounds
  3. Example Configurations

   flwr run . \
      --run-config num-server-rounds=5 \
      --run-config options.num-supernodes=20 \
      --run-config byzantine-clients=2 \
      --run-config 'strategy-type="krum"' \
      --run-config 'randomize-byzantine-strategy=false' \
      --run-config 'byzantine-attack-strategy="zero_update"' \
      --run-config byzantine-attack-intensity=1.0 \
      --run-config local-epochs=3

Experiment Results

  • Review the ./notebooks/experiments.ipynb notebook to see detailed analyses and results.
  • The results of the experiments are extracted from experiment logs and analyzed using the ./notebooks/results_review.ipynb notebook, which reviews results in JSON format at ./results/experiments/results_summary.json.

BFT Strategy for Robust Simulation

Ensure the BFT method (e.g., "krum") operates correctly by configuring the following parameters for your system.

Sufficient Number of Clients

For Krum to function effectively, the total number of participating clients (N) must satisfy the inequality:

[ N > 2f ]

Where (f) is the maximum number of Byzantine clients you want to tolerate.

Example: If you want to tolerate (f = 3) Byzantine clients, you need at least (N = 7) clients since 2 x 3 + 1 = 7.

To account for variability and ensure smooth testing, increase the number of clients beyond the minimum required. For example, set num-clients to 15 or 20.