Welcome to the official documentation of ByzFL, developed by DCL from EPFL and WIDE from INRIA Rennes!
What is ByzFL?#
ByzFL is a Python library for Byzantine-resilient Federated Learning. It is designed to be fully compatible with both PyTorch tensors and NumPy arrays, making it versatile for a wide range of machine learning workflows.
Key Features#
Robust Aggregators and Pre-Aggregators: Implement state-of-the-art aggregation strategies, such as Trimmed Mean, alongside pre-aggregation techniques like Static Clipping and Nearest Neighbor Mixing (NNM), to ensure resilience against Byzantine participants in federated learning workflows.
Byzantine Attacks: Simulate a wide range of adversarial attack scenarios, including Inner Product Manipulation (IPM) and A Little Is Enough (ALIE), to rigorously test the robustness of federated learning systems under malicious conditions.
Comprehensive Federated Learning Pipelines: Seamlessly integrate key components — such as Client, Server, Byzantine Client, and Data Distributor — to train, simulate, and benchmark robust aggregation schemes. The framework supports various datasets, models, and custom configurations, enabling researchers to replicate real-world distributed learning setups with heterogeneity and adversarial threats.
Installation#
You can install the ByzFL library via pip:
pip install byzfl
After installation, the library is ready to use. Here’s a quick example of how to use the Trimmed Mean robust aggregator and the Sign Flipping Byzantine attack:
Quick Start Example - Using PyTorch Tensors#
import byzfl
import torch
# Number of Byzantine participants
f = 1
# Honest vectors
honest_vectors = torch.tensor([[1., 2., 3.],
[4., 5., 6.],
[7., 8., 9.]])
# Initialize and apply the attack
attack = byzfl.SignFlipping()
byz_vector = attack(honest_vectors)
# Create f identical attack vectors
byz_vectors = byz_vector.repeat(f, 1)
# Concatenate honest and Byzantine vectors
all_vectors = torch.cat((honest_vectors, byz_vectors), dim=0)
# Initialize and perform robust aggregation
aggregate = byzfl.TrMean(f=f)
result = aggregate(all_vectors)
print("Aggregated result:", result)
Output:
Aggregated result: tensor([2.5000, 3.5000, 4.5000])
Quick Start Example - Using NumPy Arrays#
import byzfl
import numpy as np
# Number of Byzantine participants
f = 1
# Honest vectors
honest_vectors = np.array([[1., 2., 3.],
[4., 5., 6.],
[7., 8., 9.]])
# Initialize and apply the attack
attack = byzfl.SignFlipping()
byz_vector = attack(honest_vectors)
# Create f identical attack vectors
byz_vectors = np.tile(byz_vector, (f, 1))
# Concatenate honest and Byzantine vectors
all_vectors = np.concatenate((honest_vectors, byz_vectors), axis=0)
# Initialize and perform robust aggregation
aggregate = byzfl.TrMean(f=f)
result = aggregate(all_vectors)
print("Aggregated result:", result)
Output:
Aggregated result: [2.5 3.5 4.5]
Learn More#
Explore the key components of ByzFL below:
License#
ByzFL is open-source and distributed under the MIT License.
Our code is hosted on Github. Contributions are welcome!