For federated learning to be trusted for real world application, particularly where avoiding bias is of critical importance and where data protection legislation such as GDPR limits the ability of the server to validate decisions against datasets directly - the implications of federated learning upon fairness must be better understood. In the current state of the art surveys, the lack of clear definitions or metrics to quantify fairness in federated learning is cited as a key open problem. This project proposes definitions for a number of notions of fairness with corresponding metrics in order to quanity such fairness. The metrics are used to benchmark a number of existing approaches offering a unique insight into fairness performance and improving explainability and transparency of systems, without violating data privacy.
NOTE: This repository demonstrates the output of my final year Electrical and Electronic Engineering MEng, Individual Research Project at the University of Bristol.
The project would not be possible without the fantastic array of open-source tools and datasets that fasciliate federated learning research. This project utilises:
- Flower
- Hugging Face Datasets including NSL-KDD and CIFAR-10
- PyTorch
- TensorFlow Federated Datasets to utilise the natural partioning of the LEAF dataset, FEMNIST
The project uses the Flower simulations and was run on an NVIDIA A40 GPU.
represents Jain's Fairness index, a common measure of uniformity of over datapoints. Where
General fairness in federated learning is broken into the following four, symptomatic notions
Do all clients perform proportionately to their contribution?
Do subgroups of the population that exhibit sensitive attributes perform equivalently to those without?
Are clients rewarded proportionately to their contributions and in equal timeframes?
Does the server succeed in its role of orchestrating a learning ecosystem that maximises the objective function?
General fairness is proposed as the weighted sum of the above notions, in the case that each notion is weighted equally, the following expression arises to define
The project benchmarks use the following variables:
- Approach/ strategy - FedAvg, q-FedAvg, Ditto and FedMinMax
- Datasets and number of clients - CIFAR-10 with 10 clients, CIFAR-10 with 100 clients, NSL-KDD with 100 clients, Federated-EMNIST (FEMNIST) with 205 clients.
-
Heterogeneity - each dataset is simulated with IID and non-IID partioning between clients. The Direchlet partitioner is used to emulate the non-IID setting for NSL-KDD and CIFAR, with values of
varying between datasets. The non-IID case for the FEMNIST dataset is achieved using natural partitioning per writer.
Clone the repository and install the necessary imports:
pip install -r requirements.txt
Select an experiment of choice from the root directory, conditions are indicated by filename and the config parameters at the top of the script may be adjusted. Run the experiment from the root, for example using:
python fedavg_cifar_iid_100c_v1.py
NOTE: for FEMNIST simulations, a .pickle file containing a copy of the appropriately paritioned PyTorch dataloaders must be provided. This is because the dataset used was augmented a TensorFlow Federated Dataset before the release of Flower Datasets. An alternative would be to use the power of Flower and Hugging Face datasets to implement the EMNIST partioning as similarly to what has been achieved for NSL-KDD and CIFAR-10, as in source.load_cifar.py for example.
Using the plotting scripts provided. Results such as below can be obtained:
Federated learning comes in many flavours. In order to constrain the scope, this research is applicable to federated learning systems with the following characteristics:
-
Centrally orchestrated – there exists a single central entity that organises the learning, is responsible for initiating training rounds, aggregating the models and selecting clients. This is referred to as the server and orchestrator interchangeably and will be assumed as trustworthy. Implementations using distributed or blockchain control are out of scope for this project.
-
Horizontal – horizontal federated learning is assumed, where the feature space is consistent across clients as is the case in most federated learning applications including Google’s Gboard, this is for simplicity to focus on fairness without considering the problem of entity alignment in vertical federated learning.
-
Task Agnostic – this work does not have a specific application in mind and the optimisation of the model is considered to be out of scope. Configurations that achieve satisfactory performance in centralised settings are selected and deployed to the clients.
-
Known Sensitive Attributes – the labels corresponding to protected groups must be known by the clients and server in order to be measured.
-
Blackbox Clients – no information is available about the clients, for example regarding database size, dataset distribution, intended participation rate, communication capability, processing ability. However, it can be assumed that the client is capable of processing the model in question.
├── LICENSE
├── README.md
├── requirements.txt
├── Results
├── Ditto_CIFAR_iid_100C_5PC_10E_30R_v1.json
├── ...
│ <.json results files - 3 per experiment>
├── ...
├── q_FedAvg_NSLKDD_niid_100C_5PC_5E_30R_v3.json
└── Plots
├── Ditto_CIFAR_iid_100C_bar.png
├── ...
│ <.png result images>
├── ...
└── q_FedAvg_NSLKDD_niid_100C_tS.png
├── ditto_cifar_iid_100c_v1.py
├── ...
├── <individual experiment .py files>
├── ...
├── q_fedavg_nslkdd_niid_100c_v1.py
├── plotter_v1.py
├── plotter_v2.py
├── femnist
├── femnist_iid_loaded.pickle
└── femnist_niid_loaded.pickle
└── source
├── cifar_net.py
├── client.py
├── ditto.py
├── fedminmax.py
├── femnist_net.py
├── load_cifar.py
├── load_nslkdd.py
├── nslkdd_net.py
├── FEMNIST_loading.ipynb
└── shapley.py
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.