fluke.nets
¶
This module contains the definition of several neural networks used in state-of-the-art federated learning papers.
Encoder (aka backbone) + Head Network [Base Class] This type of networks are defined as two subnetworks, where one is meant to be the encoder/backbone network that learns a latent representation of the input, and the head network that is the classifier part of the model. |
|
Global-Local Network (Abstract Class). |
|
This implementation of the Global-Local Network ( |
|
This implementation of the Global-Local Network ( |
|
Multi-layer Perceptron for MNIST. |
|
Encoder for the |
|
Head for the |
|
Convolutional Neural Network for MNIST. |
|
Encoder for the |
|
Head for the |
|
Convolutional Neural Network with Batch Normalization for CIFAR-10. |
|
Encoder for the |
|
Head for the |
|
Logistic Regression for MNIST. |
|
Convolutional Neural Network for CIFAR-10. |
|
Encoder for the |
|
Head for the |
|
ResNet-9 network for CIFAR-100 classification. |
|
Encoder for the |
|
Head for the |
|
Convolutional Neural Network for FEMNIST. |
|
Encoder for the |
|
Head for the |
|
Encoder for the |
|
Head for the |
|
VGG-9 network for FEMNIST classification. |
|
ResNet-18 network as defined in the torchvision library. |
|
ResNet-34 network as defined in the torchvision library. |
|
ResNet-50 network as defined in the torchvision library. |
|
ResNet-18 network as defined in the torchvision library but with Group Normalization layers instead of Batch Normalization. |
|
Encoder for the |
|
Head for the |
|
Convolutional Neural Network for CIFAR-10. |
|
Encoder for the |
|
Head for the |
|
LeNet-5 for CIFAR. |
|
Encoder for the |
|
Head for the |
|
LSTM for Shakespeare. |
Classes¶
This module contains the definition of several neural networks used in state-of-the-art federated learning papers.
- class fluke.nets.EncoderHeadNet(encoder: Module, head: Module)[source]¶
Bases:
Module
Encoder (aka backbone) + Head Network [Base Class] This type of networks are defined as two subnetworks, where one is meant to be the encoder/backbone network that learns a latent representation of the input, and the head network that is the classifier part of the model. The forward method should work as usual (i.e., \(g(f(\mathbf{x}))\) where \(\mathbf{x}\) is the input, \(f\) is the encoder and \(g\) is the head), but the
forward_encoder
andforward_head
methods should be used to get the output of the encoder and head subnetworks, respectively. If this is not possible, they fallback to the forward method (default behavior).- Parameters:
encoder (nn.Module) – Encoder subnetwork.
head (nn.Module) – Head subnetwork.
- property encoder: Module¶
Return the encoder subnetwork.
- Returns:
Encoder subnetwork.
- Return type:
nn.Module
- property head: Module¶
Return the head subnetwork.
- Returns:
head subnetwork.
- Return type:
nn.Module
- class fluke.nets.GlobalLocalNet(*args, **kwargs)[source]¶
Bases:
Module
Global-Local Network (Abstract Class). This is a network that has two subnetworks, one is meant to be shared (global) and one is meant to be personalized (local). The
forward
method should work as expected, but theforward_local
andforward_global
methods should be used to get the output of the local and global subnetworks, respectively. If this is not possible, they fallback to the forward method (default behavior).
- class fluke.nets.HeadGlobalEncoderLocalNet(model: EncoderHeadNet)[source]¶
Bases:
GlobalLocalNet
This implementation of the Global-Local Network (
GlobalLocalNet
) is meant to be used with the Encoder-Head architecture. The global (i.e., that is shared between clients and server) subnetwork is the head and the local (i.e., not shared) subnetwork is the encoder.- Parameters:
model (EncoderHeadNet) – The federated model to use.
- class fluke.nets.EncoderGlobalHeadLocalNet(model: EncoderHeadNet)[source]¶
Bases:
GlobalLocalNet
This implementation of the Global-Local Network (
GlobalLocalNet
) is meant to be used with the Encoder-Head architecture. The global (i.e., that is shared between clients and server) subnetwork is the encoder and the local (i.e., not shared) subnetwork is the head.- Parameters:
model (EncoderHeadNet) – The federated model to use.
- class fluke.nets.MNIST_2NN(hidden_size: tuple[int, int] = (200, 100), softmax: bool = False)[source]¶
Bases:
EncoderHeadNet
Multi-layer Perceptron for MNIST. This is a 2-layer neural network for MNIST classification first introduced in the [FedAvg] paper, where the hidden layers have 200 neurons each and the output layer with sigmoid activation.
Similar architectures are also used in other papers:
[SuPerFed]:
hidden_size=(200, 200)
, same as FedAvg;[pFedMe]:
hidden_size=(100, 100)
with softmax on the output layer;[FedDyn]:
hidden_size=(200, 100)
.
- Parameters:
See also
References
[FedAvg]H. Brendan McMahan, Eider Moore, Daniel Ramage, Seth Hampson, Blaise Aguera y Arcas. “Communication-Efficient Learning of Deep Networks from Decentralized Data”. In AISTATS (2017).
[SuPerFed]Seok-Ju Hahn, Minwoo Jeong, and Junghye Lee. Connecting Low-Loss Subspace for Personalized Federated Learning. In KDD (2022).
[pFedMe]Canh T. Dinh, Nguyen H. Tran, and Tuan Dung Nguyen. Personalized Federated Learning with Moreau Envelopes. In NeurIPS (2020).
[FedDyn]S. Wang, T. Liu, and M. Hong. “FedDyn: A Dynamic Federated Learning Framework”. In ICLR (2021).
- class fluke.nets.MNIST_2NN_E(hidden_size: tuple[int, int] = (200, 100))[source]¶
Bases:
Module
Encoder for the
MNIST_2NN
network.- Parameters:
hidden_size (tuple[int, int], optional) – Size of the hidden layers. Defaults to (200, 200).
See also
- class fluke.nets.MNIST_2NN_D(hidden_size: int = 100, use_softmax: bool = False)[source]¶
Bases:
Module
Head for the
MNIST_2NN
network.- Parameters:
See also
- class fluke.nets.MNIST_CNN[source]¶
Bases:
EncoderHeadNet
Convolutional Neural Network for MNIST. This is a simple CNN for MNIST classification first introduced in the [FedAvg] paper, where the architecture consists of two convolutional layers with 32 and 64 filters, respectively, followed by two fully connected layers with 512 and 10 neurons, respectively.
Very same architecture is also used in the [SuPerFed] paper.
- class fluke.nets.FedBN_CNN(channels: int = 1)[source]¶
Bases:
EncoderHeadNet
Convolutional Neural Network with Batch Normalization for CIFAR-10. This network follows the architecture proposed in the [FedBN] paper, where the encoder consists of four convolutional layers with 64, 64, 128, and 128 filters, respectively, and the head network consists of three fully connected layers with 2048, 512, and 10 neurons, respectively.
- Parameters:
channels (int, optional) – Number of input channels. Defaults to 1.
Note
In the original paper, the size of the last convolutional layer is erroneously reported.
See also
References
[FedBN]Xiaoxiao Li, Meirui JIANG, Xiaofei Zhang, Michael Kamp, and Qi Dou. FedBN: Federated Learning on Non-IID Features via Local Batch Normalization. In ICLR (2021).
- class fluke.nets.FedBN_CNN_E(channels: int = 1)[source]¶
Bases:
Module
Encoder for the
FedBN_CNN
network.- Parameters:
channels (int, optional) – Number of input channels. Defaults to 1.
See also
- class fluke.nets.MNIST_LR[source]¶
Bases:
Module
Logistic Regression for MNIST. This is a simple logistic regression model for MNIST classification used in the [FedProx] paper for both MNIST and FEMNIST datasets.
References
[FedProx]Tian Li, Anit Kumar Sahu, Manzil Zaheer, Maziar Sanjabi, Ameet Talwalkar, and Virginia Smith. Federated Optimization in Heterogeneous Networks. Adaptive & Multitask Learning Workshop. In Open Review https://openreview.net/pdf?id=SkgwE5Ss3N (2018).
- class fluke.nets.CifarConv2[source]¶
Bases:
EncoderHeadNet
Convolutional Neural Network for CIFAR-10. This is a CNN for CIFAR-10 classification as described in the [FedNH] paper, where the architecture consists of two convolutional layers with 64 filters, followed by two fully connected layers with 384 and 100 neurons, respectively. The convolutional layers are followed by ReLU activations and max pooling. The last classification layer is a linear layer with 10 neurons.
- Parameters:
See also
References
[FedNH]Yutong Dai, Zeyuan Chen, Junnan Li, Shelby Heinecke, Lichao Sun, Ran Xu. Tackling Data Heterogeneity in Federated Learning with Class Prototypes. In AAAI (2023).
- class fluke.nets.CifarConv2_E[source]¶
Bases:
Module
Encoder for the
CifarConv2
network.See also
- class fluke.nets.CifarConv2_D[source]¶
Bases:
Module
Head for the
CifarConv2
network.See also
- class fluke.nets.ResNet9[source]¶
Bases:
EncoderHeadNet
ResNet-9 network for CIFAR-100 classification. This network follows the architecture proposed in the [SuPerFed] paper, which fllows the standard ResNet-9. The encoder consists of all the layers but the last fully connected layer, and thus the head network consists of the last fully connected layer.
- class fluke.nets.FEMNIST_CNN[source]¶
Bases:
EncoderHeadNet
Convolutional Neural Network for FEMNIST. This is a simple CNN for FEMNIST classification first introduced in the [DITTO] paper, where the architecture consists of two convolutional layers with 32 and 64 filters, respectively, followed by two fully connected layers with 1024 and 62 neurons, respectively. Each convolutional layer is followed by a ReLU activation and a max pooling layer.
References
[DITTO]Tian Li, Shengyuan Hu, Ahmad Beirami, and Virginia Smith. Ditto: Fair and Robust Federated Learning Through Personalization. In ICML (2021).
- class fluke.nets.FEMNIST_CNN_E[source]¶
Bases:
Module
Encoder for the
FEMNIST_CNN
network.See also
- class fluke.nets.FEMNIST_CNN_D[source]¶
Bases:
Module
Head for the
FEMNIST_CNN
network.See also
- class fluke.nets.VGG9_E(seed: int = 98765)[source]¶
Bases:
Module
Encoder for the
VGG9
network.- Parameters:
seed (int, optional) – Seed used for weight initialization. Defaults to 98765.
- class fluke.nets.VGG9_D(input_size: int = 512, output_size: int = 62, seed: int = 98765)[source]¶
Bases:
Module
Head for the
VGG9
network.
- class fluke.nets.VGG9(output_size: int = 62, seed: int = 98765)[source]¶
Bases:
EncoderHeadNet
VGG-9 network for FEMNIST classification. This network follows the architecture proposed in the [SuPerFed] paper which follows the standard VGG-9 architecture. In this implementation all convolutional layers are considered as the encoder and the fully connected layers are considered as the head network.
- class fluke.nets.ResNet18(output_size=10)[source]¶
Bases:
Module
ResNet-18 network as defined in the torchvision library.
Note
This class is a wrapper around the ResNet-18 model from torchvision and it does not implement the
EncoderHeadNet
interface.- Parameters:
output_size (int, optional) – Number of output classes. Defaults to 10.
- class fluke.nets.ResNet34(output_size: int = 100)[source]¶
Bases:
Module
ResNet-34 network as defined in the torchvision library.
Note
This class is a wrapper around the ResNet-18 model from torchvision and it does not implement the
EncoderHeadNet
interface.- Parameters:
output_size (int, optional) – Number of output classes. Defaults to 100.
- class fluke.nets.ResNet50(output_size: int = 100)[source]¶
Bases:
Module
ResNet-50 network as defined in the torchvision library.
Note
This class is a wrapper around the ResNet-18 model from torchvision and it does not implement the
EncoderHeadNet
interface.- Parameters:
output_size (int, optional) – Number of output classes. Defaults to 100.
- class fluke.nets.ResNet18GN(output_size: int = 10)[source]¶
Bases:
ResNet18
ResNet-18 network as defined in the torchvision library but with Group Normalization layers instead of Batch Normalization.
Note
This class is a wrapper around the ResNet-18 model from torchvision and it does not implement the
EncoderHeadNet
interface.- Parameters:
output_size (int, optional) – Number of output classes. Defaults to 10.
- class fluke.nets.MoonCNN[source]¶
Bases:
EncoderHeadNet
Convolutional Neural Network for CIFAR-10. This is a CNN for CIFAR-10 classification first described in the [MOON] paper, where the architecture consists of two convolutional layers with 6 and 16 filters, respectively, followed by two fully connected layers with 120 and 84 neurons, respectively, and a projection head with 256 neurons followed by the output layer with 10 neurons.
References
[MOON]Qinbin Li, Bingsheng He, and Dawn Song. Model-Contrastive Federated Learning. In CVPR (2021).
- class fluke.nets.LeNet5_D(output_size: int = 100)[source]¶
Bases:
Module
Head for the
LeNet5
network.- Parameters:
output_size (int, optional) – Number of output classes. Defaults to 100.
- class fluke.nets.LeNet5(output_size: int = 100)[source]¶
Bases:
EncoderHeadNet
LeNet-5 for CIFAR. This is a LeNet-5 for CIFAR-10/100 classification as described in the [FedRep] paper, where the architecture consists of two convolutional layers with 6 and 16 filters, respectively, followed by two fully connected layers with 120 and 84 neurons, respectively, and the output layer with 10 neurons. The activation functions are ReLU. The architecture is also used in the [LG-FedAvg] paper.
- Parameters:
output_size (int, optional) – Number of output classes. Defaults to 100.
References
[FedRep]Liam Collins, Hamed Hassani, Aryan Mokhtari, and Sanjay Shakkottai. Exploiting shared representations for personalized federated learning. In ICML (2021).
[LG-FedAvg]Paul Pu Liang, Terrance Liu, Liu Ziyin, Nicholas B. Allen, Randy P. Auerbach, David Brent, Ruslan Salakhutdinov, Louis-Philippe Morency. Think Locally, Act Globally: Federated Learning with Local and Global Representations. In arXiv https://arxiv.org/abs/2001.01523 (2020).
- class fluke.nets.Shakespeare_LSTM_E[source]¶
Bases:
Module
Encoder for the
Shakespeare_LSTM
network.See also
- class fluke.nets.Shakespeare_LSTM_D[source]¶
Bases:
Module
Head for the
Shakespeare_LSTM
network.See also
- class fluke.nets.Shakespeare_LSTM[source]¶
Bases:
EncoderHeadNet
LSTM for Shakespeare. This is an LSTM for Shakespeare classification first introduced in the [SuPerFed] paper, where the architecture consists of an embedding layer with 8 dimensions, followed by a two-layer LSTM with 256 hidden units, and a linear layer with 256 neurons.
See also