https://github.com/denpalrius/bft-federated-learning
Federated Learning with Byzantine Fault Tolerance
https://github.com/denpalrius/bft-federated-learning
artificial-intelligence bft bft-protocols cifar-10 distributed-training fault-tolerance federated-learning federated-learning-algorithm flower grpc machine-learning-algorithms pytorch
Last synced: 4 months ago
JSON representation
Federated Learning with Byzantine Fault Tolerance
- Host: GitHub
- URL: https://github.com/denpalrius/bft-federated-learning
- Owner: denpalrius
- Created: 2024-11-24T01:33:38.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-07-09T16:16:15.000Z (11 months ago)
- Last Synced: 2025-08-13T19:43:19.419Z (10 months ago)
- Topics: artificial-intelligence, bft, bft-protocols, cifar-10, distributed-training, fault-tolerance, federated-learning, federated-learning-algorithm, flower, grpc, machine-learning-algorithms, pytorch
- Language: Jupyter Notebook
- Homepage:
- Size: 11.4 MB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.MD
Awesome Lists containing this project
README
# 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:
```bash
pip install -e .
```
## Loading Initial Weights
To modify the initial weights for the model, run the following notebook to generate new weights:
```bash
./notebooks/cifar10_cnn.ipynb
```
## Running the Simulation Engine
To run the local simulation, execute the following command from the root of the repository:
```bash
flwr run .
```
For optimization advice, refer to the [How to Run Simulations](https://flower.ai/docs/framework/how-to-run-simulations.html) 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**
```bash
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.