fluke.algorithms
¶
Warning
This section of the documentation is under construction!
This module contains (as submodules) the implementation of several the federated learning algorithms.
Classes included in fluke.algorithms
Centralized Federated Learning algorithm. |
|
Personalized Federated Learning algorithm. |
class fluke.algorithms.CentralizedFL
- class fluke.algorithms.CentralizedFL(n_clients: int, data_splitter: DataSplitter, hyper_params: DDict)[source]¶
Centralized Federated Learning algorithm. This class is a generic implementation of a centralized federated learning algorithm that follows the Federated Averaging workflow. This class represents the entry point to the federated learning algorithm. Each new algorithm should inherit from this class and implement the specific logic of the algorithm. The main components of the algorithm are:
Clients
: Each client should implementfluke.client.Client
class and the specific specialization must be defined in theget_client_class()
method. The initialization of the clients is done in theinit_clients()
method.Server
: The server is the entity that coordinates the training process. It should implement thefluke.server.Server
class and the specific specialization must be defined in theget_server_class()
method. The initialization of the server is done in theinit_server()
method.Optimizer
: The optimizer used by the clients. The default optimizer class is defined in theget_optimizer_class()
method.
To run the algorithm, the
run()
method should be called with the number of rounds and the percentage of eligible clients. This method will call theServer.fit()
method which will orchestrate the training process.- Parameters:
n_clients (int) – Number of clients.
data_splitter (DataSplitter) – Data splitter object.
hyper_params (DDict) – Hyperparameters of the algorithm. This set of hyperparameteers should be divided in two parts: the client hyperparameters and the server hyperparameters.
- can_override_optimizer() bool [source]¶
Return whether the optimizer can be changed user-side. Generally, the optimizer can be configured by the user. However, in some cases, the algorithm may require a specific optimizer and the user should not be able to change it.
- Returns:
Whether the optimizer can be changed user-side.
- Return type:
- get_optimizer_class() Optimizer [source]¶
Get the optimizer class.
- Returns:
Optimizer class.
- Return type:
torch.optim.Optimizer
- get_client_class() Client [source]¶
Get the client class. This method should be overriden by the subclasses when a different client class is defined. This allows to reuse all the logic of the algorithm and only change the client class.
- Returns:
Client class.
- Return type:
- get_server_class() Server [source]¶
Get the server class. This method should be overriden by the subclasses when a different server class is defined. This allows to reuse all the logic of the algorithm and only change the server class.
- Returns:
Server class.
- Return type:
- init_clients(clients_tr_data: list[FastDataLoader], clients_te_data: list[FastDataLoader], config: DDict) None [source]¶
Initialize the clients.
- Parameters:
clients_tr_data (list[FastDataLoader]) – List of training data loaders, one for each client.
clients_te_data (list[FastDataLoader]) – List of test data loaders, one for each client. The test data loaders can be
None
.config (DDict) – Configuration of the clients.
Important
For more deatils about the configuration of the clients, see the configuration page.
See also
- init_server(model: Any, data: FastDataLoader, config: DDict)[source]¶
Initailize the server.
- Parameters:
model (Any) – The global model.
data (FastDataLoader) – The server-side test set.
config (DDict) – Configuration of the server.
- set_callbacks(callbacks: callable | Iterable[callable])[source]¶
Set the callbacks.
- Parameters:
callbacks (Union[callable, Iterable[callable]]) – Callbacks to attach to the algorithm.
- run(n_rounds: int, eligible_perc: float, finalize: bool = True, **kwargs: dict[str, Any])[source]¶
Run the federated algorithm. This method will call the
Server.fit()
method which will orchestrate the training process.
abstract class fluke.algorithms.PersonalizedFL
- class fluke.algorithms.PersonalizedFL(n_clients: int, data_splitter: DataSplitter, hyper_params: DDict)[source]¶
Personalized Federated Learning algorithm. This class is a simple extension of the
CentralizedFL
class where the clients are expected to implement thefluke.client.PFLClient
class (seeget_client_class()
). The main difference with respect to theCentralizedFL
class is that the clients initialization requires a model that is the personalized model of the client.Important
Differently from
CentralizedFL
, which is actually the FedAvg algorithm, thePersonalizedFL
class must not be used as is because it is a generic implementation of a personalized federated learning algorithm. The subclasses of this class should implement the specific logic of the personalized federated learning algorithm.See also