Server

class openfgl.flcore.base.BaseServer(args, global_data, data_dir, message_pool, device, personalized=False)[source]

Bases: object

Base class for a server in a federated learning setup.

Attributes:

args (Namespace): Arguments containing model and training configurations.

message_pool (object): Pool for managing messages between client and server.

device (torch.device): Device to run the computations on.

task (object): Task-specific data and functions loaded via the load_task utility.

personalized (bool): Flag to indicate if the server is using a personalized algorithm.

__init__(args, global_data, data_dir, message_pool, device, personalized=False)[source]

Initialize the BaseServer with provided arguments and data.

Attributes:

args (Namespace): Arguments containing model and training configurations.

global_data (object): Global data accessible to the server.

data_dir (str): Directory containing the data.

message_pool (object): Pool for managing messages between client and server.

device (torch.device): Device to run the computations on.

personalized (bool, optional): Flag to indicate if the server is using a personalized algorithm. Defaults to False.

execute()[source]

Server global execution. This method should be implemented by subclasses.

send_message()[source]

Send messages to clients. This method should be implemented by subclasses.

class openfgl.flcore.fedavg.server.FedAvgServer(args, global_data, data_dir, message_pool, device)[source]

Bases: BaseServer

FedAvgServer implements the server-side logic for the Federated Averaging (FedAvg) algorithm, as introduced in the paper “Communication-Efficient Learning of Deep Networks from Decentralized Data” by McMahan et al. (2017). This class is responsible for aggregating model updates from clients and broadcasting the updated global model to all participants in the federated learning process.

Attributes:

None (inherits attributes from BaseServer)

__init__(args, global_data, data_dir, message_pool, device)[source]

Initializes the FedAvgServer.

Attributes:

args (Namespace): Arguments containing model and training configurations.

global_data (object): Global dataset accessible by the server.

data_dir (str): Directory containing the data.

message_pool (object): Pool for managing messages between server and clients.

device (torch.device): Device to run the computations on.

execute()[source]

Executes the server-side operations. This method aggregates model updates from the clients by computing a weighted average of the model parameters, based on the number of samples each client used for training.

send_message()[source]

Sends a message to the clients containing the updated global model parameters after aggregation.

class openfgl.flcore.adafgl.server.AdaFGLServer(args, global_data, data_dir, message_pool, device)[source]

Bases: BaseServer

AdaFGLServer implements the server-side logic for federated learning using the AdaFGL model, as described in the paper “AdaFGL: A New Paradigm for Federated Node Classification with Topology Heterogeneity”. It extends the BaseServer class by managing the aggregation of model updates from clients, and coordinating the training process across different phases, particularly handling topology heterogeneity.

Attributes:

phase (int): Indicates the current phase of the server’s operations. It starts at 0 (initial phase) and switches to 1 (AdaFGL phase) when the vanilla rounds are completed.

__init__(args, global_data, data_dir, message_pool, device)[source]

Initializes the AdaFGLServer.

Attributes:

args (Namespace): Arguments containing model and training configurations.

global_data (object): Global dataset accessible by the server.

data_dir (str): Directory containing the data.

message_pool (object): Pool for managing messages between server and clients.

device (torch.device): Device to run the computations on.

execute()[source]

Executes the server-side operations. This method handles the switching between different phases of the federated learning process, and aggregates model updates from clients during the initial phase.

send_message()[source]

Sends a message to the clients containing the aggregated model parameters. The content of the message depends on the current phase.

class openfgl.flcore.feddc.server.FedDCServer(args, global_data, data_dir, message_pool, device)[source]

Bases: BaseServer

FedDCServer is a server implementation for the Federated Learning algorithm with Drift Decoupling and Correction (FedDC). It extends the BaseServer class and manages the aggregation of client model updates, correcting for local drift, and computes the average updates across all clients.

Attributes:

avg_update (list): A list of tensors representing the average update across all clients for each model parameter.

__init__(args, global_data, data_dir, message_pool, device)[source]

Initializes the FedDCServer.

Attributes:

args (Namespace): Arguments containing model and training configurations.

global_data (object): Global dataset accessible by the server.

data_dir (str): Directory containing the data.

message_pool (object): Pool for managing messages between server and clients.

device (torch.device): Device to run the computations on.

execute()[source]

Executes the server-side operations. This method aggregates the model updates from the clients by computing a weighted average of the model parameters, considering both the local parameters and the local drift corrections from each client. It also computes the average of the last updates from all clients.

send_message()[source]

Sends a message to the clients containing the updated global model parameters after aggregation, along with the average of the last updates from all clients.

class openfgl.flcore.feddep.server.FedDEPEServer(args, global_data, data_dir, message_pool, device)[source]

Bases: BaseServer

FedDEPEServer is a server implementation for the Federated Learning algorithm with Deep Efficient Private Neighbor Generation for Subgraph Federated Learning (FedDEP). This server manages the aggregation of model parameters from multiple clients and oversees the global model updates in a federated learning environment.

Attributes:

None (inherits attributes from BaseServer)

__init__(args, global_data, data_dir, message_pool, device)[source]

Initializes the FedDEPEServer.

Attributes:

args (Namespace): Arguments containing model and training configurations.

global_data (object): Global dataset accessible by the server.

data_dir (str): Directory containing the data.

message_pool (object): Pool for managing messages between server and clients.

device (torch.device): Device to run the computations on.

execute()[source]

Executes the server-side operations. If it’s not the initial round, this method aggregates the model parameters received from sampled clients by computing their weighted average to update the global model.

get_override_evaluate()[source]

Overrides the default evaluation method. This method evaluates the global model on the training, validation, and test datasets using the specified evaluation metrics.

Returns:

function: A custom evaluation function.

send_message()[source]

Sends a message to the clients containing the updated global model parameters after aggregation.

class openfgl.flcore.fedgl.server.FedGLServer(args, global_data, data_dir, message_pool, device)[source]

Bases: BaseServer

FedGLServer is a server implementation for the Federated Graph Learning (FedGL) framework with global self-supervision. It extends the BaseServer class and manages the aggregation of model parameters from multiple clients, updates global pseudo-labels, and reconstructs the global graph structure.

Attributes:

pseudo_labels (list): List of pseudo-labels generated by the server for each client.

pseudo_labels_mask (list): List of masks indicating which nodes have pseudo-labels for each client.

whole_adj (list): List of reconstructed adjacency matrices for each client.

__init__(args, global_data, data_dir, message_pool, device)[source]

Initializes the FedGLServer.

Attributes:

args (Namespace): Arguments containing model and training configurations.

global_data (object): Global dataset accessible by the server.

data_dir (str): Directory containing the data.

message_pool (object): Pool for managing messages between server and clients.

device (torch.device): Device to run the computations on.

execute()[source]

Executes the server-side operations. This includes aggregating model parameters from sampled clients, updating global pseudo-labels, and reconstructing the global adjacency matrix if needed.

send_message()[source]

Sends a message to the clients. In the initial round, only the global model parameters are sent. In subsequent rounds, the server also sends the pseudo-labels, pseudo-labels masks, and reconstructed adjacency matrices to the clients.

class openfgl.flcore.fedgta.server.FedGTAServer(args, global_data, data_dir, message_pool, device)[source]

Bases: BaseServer

FedGTAServer is a server implementation for the Federated Graph Learning framework with Topology-aware Averaging (FedGTA). This server manages the aggregation of model parameters from multiple clients, applies personalized model updates, and handles communication with the clients.

Attributes:

aggregated_models (list): A list of model copies, one for each client, used for personalized model aggregation.

__init__(args, global_data, data_dir, message_pool, device)[source]

Initializes the FedGTAServer.

Attributes:

args (Namespace): Arguments containing model and training configurations.

global_data (object): Global dataset accessible by the server.

data_dir (str): Directory containing the data.

message_pool (object): Pool for managing messages between server and clients.

device (torch.device): Device to run the computations on.

execute()[source]

Executes the server-side operations for aggregating model parameters. The method computes the similarity between clients based on their label propagation moments and aggregates the models from similar clients to create personalized models.

send_message()[source]

Sends a message to the clients. In the initial round, only the global model parameters are sent. In subsequent rounds, the server also sends personalized models to each client based on the results of the aggregation process.

switch_personalized_global_model(client_id)[source]

Switches between the personalized and global models for a specific client. If the server has a personalized model for the client, it loads it into the global model; otherwise, it loads the general global model.

Args:

client_id (int): The ID of the client for which the model switch is being performed.

class openfgl.flcore.fedproto.server.FedProtoServer(args, global_data, data_dir, message_pool, device)[source]

Bases: BaseServer

FedProtoServer is a server implementation for the Federated Prototype Learning (FedProto) framework. This server is responsible for aggregating local prototypes from clients to update the global prototypes, which are then used in the federated learning process.

Attributes:

global_prototype (dict): A dictionary storing the global prototypes for each class, updated based on the local prototypes received from the clients.

__init__(args, global_data, data_dir, message_pool, device)[source]

Initializes the FedProtoServer.

Attributes:

args (Namespace): Arguments containing model and training configurations.

global_data (object): Global dataset accessible by the server.

data_dir (str): Directory containing the data.

message_pool (object): Pool for managing messages between server and clients.

device (torch.device): Device to run the computations on.

execute()[source]

Executes the server-side operations for aggregating local prototypes from clients. The global prototypes for each class are computed as the weighted average of the local prototypes from the sampled clients.

send_message()[source]

Sends a message to the clients containing the updated global prototypes. These prototypes are used by the clients in their local training processes to ensure alignment with the global model.

class openfgl.flcore.fedprox.server.FedProxServer(args, global_data, data_dir, message_pool, device)[source]

Bases: BaseServer

FedProxServer is a server implementation for the Federated Proximal (FedProx) framework, introduced in the paper “Federated Optimization in Heterogeneous Networks.” This server is responsible for aggregating model parameters from multiple clients and updating the global model based on these aggregated parameters.

Attributes:

None

__init__(args, global_data, data_dir, message_pool, device)[source]

Initializes the FedProxServer.

Attributes:

args (Namespace): Arguments containing model and training configurations.

global_data (object): Global dataset accessible by the server.

data_dir (str): Directory containing the data.

message_pool (object): Pool for managing messages between server and clients.

device (torch.device): Device to run the computations on.

execute()[source]

Executes the server-side operations for aggregating model parameters from clients. The global model is updated as a weighted average of the model parameters from sampled clients, where the weights are proportional to the number of samples each client used during training.

send_message()[source]

Sends a message to the clients containing the updated global model parameters. This information is used by the clients to synchronize their local models with the global model.

The message includes:
  • weight: The updated global model parameters.

class openfgl.flcore.fedstar.server.FedStarServer(args, global_data, data_dir, message_pool, device)[source]

Bases: BaseServer

FedStarServer is the server-side implementation for the Federated Learning algorithm described in the paper ‘Federated Learning on Non-IID Graphs via Structural Knowledge Sharing’. This class handles the aggregation of model updates from clients, structural knowledge sharing, and the distribution of the aggregated global model.

Attributes:

task (object): The task object that holds the model and data for training.

device (torch.device): The device on which computations will be performed.

__init__(args, global_data, data_dir, message_pool, device)[source]

Initializes the FedStarServer.

Attributes:

args (Namespace): Arguments containing model and training configurations.

global_data (object): The global dataset used for centralized pretraining or evaluation.

data_dir (str): Directory containing the data.

message_pool (object): Pool for managing messages between server and clients.

device (torch.device): Device to run the computations on.

execute()[source]

Executes the model aggregation process on the server.

The server collects the model weights from the sampled clients, aggregates them using weighted averaging based on the number of samples each client has, and updates the global model’s structural knowledge parameters.

send_message()[source]

Sends the aggregated global model to the clients.

The server sends the global model’s state_dict, which includes the updated structural knowledge parameters, to the clients for the next round of training.

class openfgl.flcore.fedtad.server.FedTADServer(args, global_data, data_dir, message_pool, device)[source]

Bases: BaseServer

FedTADServer implements the server-side operations for the Federated Learning algorithm described in the paper ‘FedTAD: Topology-aware Data-free Knowledge Distillation for Subgraph Federated Learning’. This class handles global model aggregation, the training of a generator for knowledge distillation, and the coordination of knowledge sharing between clients.

Attributes:

generator (FedTAD_ConGenerator): A generator model used for creating pseudo graphs to facilitate knowledge distillation.

generator_optimizer (torch.optim.Optimizer): Optimizer for the generator model.

__init__(args, global_data, data_dir, message_pool, device)[source]

Initializes the FedTADServer.

Attributes:

args (Namespace): Arguments containing model and training configurations.

global_data (object): Global dataset accessible to the server.

data_dir (str): Directory containing the data.

message_pool (object): Pool for managing messages between client and server.

device (torch.device): Device to run the computations on.

execute()[source]

Executes the main operations of the server during a federated learning round.

This includes aggregating the model parameters from the clients, training a generator to create pseudo graphs for knowledge distillation, and updating the global model based on the generated data and the knowledge shared by the clients.

send_message()[source]

Sends the updated global model weights to the clients.

The message sent to the clients includes the updated model parameters after aggregation and knowledge distillation.

class openfgl.flcore.fedtgp.server.FedTGPServer(args, global_data, data_dir, message_pool, device, fedtgp_lambda=1, num_glb_epochs=10, lr_glb=0.01)[source]

Bases: BaseServer

FedTGPServer implements the server-side operations for the Federated Learning algorithm described in the paper ‘FedTGP: Trainable Global Prototypes with Adaptive-Margin-Enhanced Contrastive Learning for Data and Model Heterogeneity in Federated Learning’. This class handles the global aggregation of prototypes, the training of global prototypes, and communication with the clients.

Attributes:

fedtgp_lambda (float): Weight for the FedTGP loss component.

num_glb_epochs (int): Number of global epochs for training the prototypes.

lr_glb (float): Learning rate for the global prototype optimizer.

trainable_prototypes (nn.Module): A trainable model for generating global prototypes.

gp_optimizer (torch.optim.Optimizer): Optimizer for training the global prototypes.

global_prototype (dict): Dictionary to store the global prototypes for each class.

__init__(args, global_data, data_dir, message_pool, device, fedtgp_lambda=1, num_glb_epochs=10, lr_glb=0.01)[source]

Initializes the FedTGPServer.

Attributes:

args (Namespace): Arguments containing model and training configurations.

global_data (object): The global dataset, if available.

data_dir (str): Directory containing the data.

message_pool (object): Pool for managing messages between server and clients.

device (torch.device): Device to run the computations on.

fedtgp_lambda (float): Weight for the FedTGP loss component, default is 1.

num_glb_epochs (int): Number of global epochs for training the prototypes, default is 10.

lr_glb (float): Learning rate for the global prototype optimizer, default is 1e-2.

execute()[source]

Executes the global aggregation and prototype training process. The method first aggregates local prototypes from the clients, computes the global prototypes, and trains the global prototypes using an adaptive-margin-enhanced contrastive learning approach.

send_message()[source]

Sends a message to the clients containing the updated global prototypes.

class openfgl.flcore.fggp.server.FGGPServer(args, global_data, data_dir, message_pool, device)[source]

Bases: BaseServer

FGGPServer is the server-side implementation for the Federated Graph Learning with Generalizable Prototypes (FGGP) framework. The server aggregates model parameters and prototypes from clients and performs prototype clustering using the FINCH algorithm to generate generalizable prototypes across federated clients.

Attributes:

global_protos (dict): A dictionary containing the aggregated global prototypes for each class.

__init__(args, global_data, data_dir, message_pool, device)[source]

Initializes the FGGPServer.

Attributes:

args (Namespace): Arguments containing model and training configurations.

global_data (torch_geometric.data.Data): Global graph data available to the server, if any.

data_dir (str): Directory containing the data.

message_pool (dict): Pool for managing messages between client and server.

device (torch.device): The device on which computations will be performed (e.g., CPU or GPU).

execute()[source]

Executes the global aggregation of model parameters and prototype aggregation from all sampled clients. The model parameters are aggregated based on either the number of samples or equally, depending on the configuration. The prototypes from clients are aggregated using the FINCH algorithm.

proto_aggregation()[source]

Aggregates the prototypes received from clients. For each class, the prototypes are clustered using the FINCH algorithm to find representative prototypes. The resulting prototypes are averaged for each cluster.

Returns:

dict: A dictionary containing the aggregated prototypes for each class.

send_message()[source]

Sends the aggregated global model parameters to the clients.

class openfgl.flcore.gcfl_plus.server.GCFLPlusServer(args, global_data, data_dir, message_pool, device)[source]

Bases: BaseServer

GCFLPlusServer implements the server-side functionality for the Federated Graph Classification framework (GCFL+). This server manages client updates, performs clustering of clients based on their gradient sequences, and updates the global model. The server also handles the distribution of model updates to clients based on their cluster assignments.

Attributes:

task (object): The task object containing the model and data configurations.

W (dict): A dictionary containing the current global model parameters.

cluster_indices (list): A list of lists, where each inner list contains the client indices that belong to a cluster.

seqs_grads (dict): A dictionary that stores the sequence of gradient norms for each client.

EPS_1 (float): A threshold for the mean update norm to determine if clustering should occur.

EPS_2 (float): A threshold for the maximum update norm to determine if clustering should occur.

seq_length (int): The length of the gradient sequence to be considered for DTW-based clustering.

standardize (bool): A flag indicating whether to standardize the gradient sequences before computing DTW distances.

num_clients (int): The number of clients in the federated learning setup.

cluster_weights (list): A list of lists, where each inner list contains the model weights for each client in a cluster.

__init__(args, global_data, data_dir, message_pool, device)[source]

Initializes the GCFLPlusServer with the provided arguments, data, and device.

Attributes:

args (Namespace): Arguments containing model and training configurations.

global_data (object): The global dataset available to the server (if any).

data_dir (str): Directory containing the data.

message_pool (dict): Pool for managing messages between the server and clients.

device (torch.device): Device on which computations will be performed (e.g., CPU or GPU).

compute_max_update_norm(cluster)[source]

Computes the maximum norm of gradient updates for a given cluster of clients.

Attributes:

cluster (list): A list of client IDs in the cluster.

Returns:

float: The maximum gradient update norm within the cluster.

compute_mean_update_norm(cluster)[source]

Computes the mean norm of gradient updates for a given cluster of clients.

Attributes:

cluster (list): A list of client IDs in the cluster.

Returns:

float: The mean gradient update norm within the cluster.

compute_pairwise_distances(seqs, standardize=False)[source]

Computes the pairwise DTW (Dynamic Time Warping) distances between sequences of gradient norms.

Attributes:

seqs (list): A list of sequences of gradient norms. standardize (bool): Whether to standardize the sequences before computing DTW distances.

Returns:

np.array: A matrix of pairwise DTW distances.

execute()[source]

Executes the server-side update procedure. The server collects gradient norms from clients, computes pairwise DTW distances, and performs clustering of clients based on these distances. If clustering conditions are met, the clients are split into new clusters, and their weights are updated accordingly.

get_cluster_weights()[source]

Aggregates the model weights for each cluster of clients based on their gradient updates.

Returns:

list: A list of model weights for each cluster.

min_cut(similarity, idc)[source]

Performs a min-cut on a similarity graph to split clients into two clusters.

Attributes:

similarity (np.array): A matrix of similarities between clients. idc (list): A list of client IDs corresponding to the similarity matrix.

Returns:

tuple: Two lists of client IDs representing the two new clusters.

send_message()[source]

Sends the updated cluster indices and corresponding weights back to the clients. This information is used by the clients to update their local models based on their cluster assignment.

class openfgl.flcore.moon.server.MoonServer(args, global_data, data_dir, message_pool, device)[source]

Bases: BaseServer

MoonServer implements the server-side logic for Model-contrastive Federated Learning (MOON). The server is responsible for aggregating the model parameters from multiple clients based on their contributions (e.g., number of samples) and then sending the updated global model back to the clients.

Attributes:

None (inherits all attributes from BaseServer).

__init__(args, global_data, data_dir, message_pool, device)[source]

Initializes the MoonServer with the provided arguments, global data, and device.

Attributes:

args (Namespace): Arguments containing model and training configurations.

global_data (object): The global dataset used by the server.

data_dir (str): Directory containing the data.

message_pool (dict): Pool for managing messages between the clients and the server.

device (torch.device): The device (CPU or GPU) to be used for computations.

execute()[source]

Aggregates the model parameters received from the clients. The aggregation is done based on the proportion of samples each client has, ensuring that the contributions of each client are weighted appropriately in the global model update.

send_message()[source]

Sends the updated global model parameters to the clients. This is done by placing the model parameters in the message_pool under the “server” key, which clients can then retrieve and use to update their local models.

class openfgl.flcore.isolate.server.IsolateServer(args, global_data, data_dir, message_pool, device)[source]

Bases: BaseServer

IsolateServer represents a federated learning server that operates in isolation. Unlike a typical federated server, it does not aggregate client updates or communicate with clients. This class is intended for scenarios where each client trains independently without contributing to a global model.

Attributes:

task (object): The task object containing the global model, data, and training configurations.

__init__(args, global_data, data_dir, message_pool, device)[source]

Initializes the IsolateServer with the provided arguments, global data, and device.

Attributes:

args (Namespace): Arguments containing model and training configurations.

global_data (object): The global dataset for server-side operations, if any.

data_dir (str): Directory containing the data.

message_pool (dict): Pool for managing messages between the server and clients.

device (torch.device): Device on which computations will be performed (e.g., CPU or GPU).

execute()[source]

Executes the server’s operations. In this isolated setup, the server does not perform any aggregation or other federated learning tasks. It asserts that all clients are sampled but does not process any updates.

send_message()[source]

An empty send_message method, as this server does not communicate with clients. No messages or model updates are sent to the clients.

class openfgl.flcore.scaffold.server.ScaffoldServer(args, global_data, data_dir, message_pool, device)[source]

Bases: BaseServer

ScaffoldServer implements the server-side logic for the SCAFFOLD algorithm in Federated Learning. SCAFFOLD aims to reduce the variance caused by client drift by introducing control variates (local and global control variables) that adjust the client updates during training.

Attributes:

global_control (list[torch.Tensor]): A list of tensors representing the global control variates for each parameter in the model.

__init__(args, global_data, data_dir, message_pool, device)[source]

Initializes the ScaffoldServer with the provided arguments, global data, and device.

Args:

args (Namespace): Arguments containing model and training configurations. global_data (object): The global dataset used for training (if applicable). data_dir (str): Directory containing the data. message_pool (dict): Pool for managing messages between the server and the clients. device (torch.device): Device to run the computations on (CPU or GPU).

execute()[source]

Executes the aggregation of client updates by averaging the local model parameters from the sampled clients. It also updates the global control variates based on the local control variates received from the clients.

send_message()[source]

Sends the updated global model parameters and global control variates to the clients after the aggregation step. This information is used by the clients to adjust their local updates in the next round.

update_global_control()[source]

Updates the global control variates by averaging the local control variates from the sampled clients. This step is crucial for mitigating the variance caused by client drift in the federated learning process.