fluke.algorithms.decentralized.client

This module implements clients for decentralized federated learning (DFL) algorithms.

Classes included in fluke.algorithms.decentralized.client

AbstractDFLClient

Abstract client for decentralized federated learning (DFL).

GossipClient

A client for decentralized federated learning using gossip protocol.

class fluke.algorithms.decentralized.client.AbstractDFLClient

class fluke.algorithms.decentralized.client.AbstractDFLClient(index: int, model: Module, neighbours: list[int], train_set: FastDataLoader | DataLoader, test_set: FastDataLoader | DataLoader, optimizer_cfg: OptimizerConfigurator, loss_fn: Module, local_epochs: int = 3, fine_tuning_epochs: int = 0, clipping: float = 0, persistency: bool = True, activation_rate: float = 1, **kwargs)[source]

Abstract client for decentralized federated learning (DFL).

Parameters:
  • index (int) – The index of the client.

  • model (Module) – The model to be trained.

  • neighbours (list[int]) – The indices of the neighbouring clients.

  • train_set (FastDataLoader | DataLoader) – The training dataset.

  • test_set (FastDataLoader | DataLoader) – The testing dataset.

  • optimizer_cfg (OptimizerConfigurator) – The optimizer configuration.

  • loss_fn (Module) – The loss function.

  • local_epochs (int) – Number of local training epochs. Defaults to 3.

  • fine_tuning_epochs (int) – Number of fine-tuning epochs. Defaults to 0.

  • clipping (float) – Gradient clipping value. Defaults to 0 (no clipping).

  • persistency (bool) – Whether to persist the model across rounds. Defaults to True.

  • activation_rate (float) – Probability of the client being active in each round. Defaults to 1 (always active).

  • **kwargs – Additional keyword arguments passed to the parent class.

is_active(iter: int) bool[source]

Check if the client is active in the current iteration.

Parameters:

iter (int) – The current iteration number.

Returns:

True if the client is active, False otherwise.

Return type:

bool

class fluke.algorithms.decentralized.client.GossipClient

class fluke.algorithms.decentralized.client.GossipClient(*args, policy: str = typing.Literal['random', 'aggregate', 'last', 'best'], **kwargs)[source]

A client for decentralized federated learning using gossip protocol.

In the gossip protocol, clients send their model to a randomly chosen neighbour. Upon receiving models from neighbours, the client applies a specified policy to update its model. Possible policies include: - “random”: Selects a random model from the received messages. - “aggregate”: Aggregates all received models using the average. - “last”: Uses the last received model based on the timestamp. - “best”: Selects the model with the highest accuracy on the local test set.

In case of ties, the last model processed in the order of receipt is chosen.

Parameters:
  • *args – Positional arguments passed to the parent class.

  • policy (str) – The policy to apply when receiving models from neighbours. Must be one of “random”, “aggregate”, “last”, or “best”. Defaults to “random”.

  • **kwargs – Keyword arguments passed to the parent class.

Raises:

AssertionError – If the provided policy is not one of the allowed values.