fluke.algorithms.decentralized¶
Submodules¶
This module implements clients for decentralized federated learning (DFL) algorithms. |
Classes included in fluke.algorithms.decentralized
This class represents the topology of the decentralized FL algorithm. |
|
Decentralized Federated Learning (DFL) is a class of federated learning algorithms where clients communicate directly with each other without a central server. |
|
Gossip Decentralized Federated Learning (GossipDFL) is a specific implementation of a decentralized FL algorithm where clients communicate with their neighbors in a gossip-like manner. |
class fluke.algorithms.decentralized.Topology
- class fluke.algorithms.decentralized.Topology(graph: Graph)[source]¶
This class represents the topology of the decentralized FL algorithm. It is essentially a wrapper around a networkx graph, with some additional methods to facilitate the creation and manipulation of the graph. The nodes of the graph represent the clients, and the edges represent the communication links between the clients. The graph can be directed or undirected, depending on the use case.
- static fully_connected(num_nodes: int) Topology[source]¶
Create a fully connected (complete) graph with num_nodes nodes.
- static random(num_nodes: int, p: float = 0.5) Topology[source]¶
Create a random d-regular graph with num_nodes nodes and edge probability p.
- property num_nodes: int¶
Get the number of nodes in the topology graph.
- Returns:
The number of nodes.
- Return type:
- add_node(node: int) None[source]¶
Add a node to the topology graph.
- Parameters:
node (int) – The node to add.
- add_edge(node1: int, node2: int, weight: float = None) None[source]¶
Add an edge between two nodes in the topology graph.
- has_edge(node1: int, node2: int) bool[source]¶
Check if an edge exists between two nodes in the topology graph.
abstract class fluke.algorithms.decentralized.DecentralizedFL
- class fluke.algorithms.decentralized.DecentralizedFL(n_clients: int, data_splitter: DataSplitter, hyper_params: DDict | dict[str, Any], topology: Topology = None, clients: list[AbstractDFLClient] | None = None, test_data: FastDataLoader | DataLoader | None = None, **kwargs)[source]¶
Decentralized Federated Learning (DFL) is a class of federated learning algorithms where clients communicate directly with each other without a central server. This class represents the base implementation of a decentralized FL algorithm, which can be extended to implement specific algorithms like
GossipFL, etc.- Parameters:
n_clients (int) – The number of clients in the federation.
data_splitter (DataSplitter) – The data splitter to use for splitting the dataset among the clients.
hyper_params (DDict | dict[str, Any]) – The hyperparameters of the algorithm.
topology (Topology, optional) – The topology of the communication graph. If not provided, a fully connected topology will be used by default.
clients (list[AbstractDFLClient], optional) – A list of client instances to use in the federation. If not provided, clients will be initialized based on the provided hyperparameters and topology.
test_data (FastDataLoader | DataLoader, optional) – The test dataset to be used for evaluation. If not provided, the test dataset will be generated by the data splitter along with the training datasets for the clients.
**kwargs – Additional keyword arguments passed to the parent class.
- property id: str¶
Get the unique identifier of this instance of the algorithm.
- Returns:
Unique identifier of the instance of the algorithm.
- Return type:
- get_client_class() type[AbstractDFLClient][source]¶
Get the class of the client to be used in the decentralized FL algorithm.
- Returns:
The class of the client.
- Return type:
- set_callbacks(callbacks: callable | Collection[Callable]) None[source]¶
Set the callbacks for the server the clients and the channel.
The callbacks are expected to be instances of the
fluke.server.ServerObserver,fluke.client.ClientObserverorfluke.comm.ChannelObserverclasses. Each callback will be attached to the corresponding entity.- Parameters:
callbacks (Union[callable, Collection[callable]]) – Callbacks to attach to the algorithm.
abstract class fluke.algorithms.decentralized.GossipDFL
- class fluke.algorithms.decentralized.GossipDFL(n_clients: int, data_splitter: DataSplitter, hyper_params: DDict | dict[str, Any], topology: Topology = None, clients: list[AbstractDFLClient] | None = None, test_data: FastDataLoader | DataLoader | None = None, **kwargs)[source]¶
Gossip Decentralized Federated Learning (GossipDFL) is a specific implementation of a decentralized FL algorithm where clients communicate with their neighbors in a gossip-like manner. In each round, active clients send their model to a randomly chosen neighbor, and then perform local updates based on the received models.