armlet.FL_pipeline.FL_algorithms package#
Module contents#
- class armlet.FL_pipeline.FL_algorithms.ArmletCentralizedFL(hyperparameters: DDict | dict[str, Any], n_clients: int, data_splitter: DataSplitter, val_data: dict, clients: list[Client] = None, server: Server = None, **kwargs)#
Bases:
CentralizedFL- get_client_class() type[Client]#
Get the client class. This method should be overridden 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:
type[Client]
- get_server_class() type[Server]#
Get the server class. This method should be overridden 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:
type[Server]
- init_clients(clients_tr_data: list[FastDataLoader], clients_te_data: list[FastDataLoader], config: DDict) Sequence[Client]#
Creates 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 details about the configuration of the clients, see the configuration page.
See also
fluke.client.Client- Returns:
List of initialized clients.
- Return type:
Sequence[Client]
- init_server(model: Any, data: FastDataLoader, config: DDict) Server#
Creates the server.
- Parameters:
model (Any) – The global model.
data (FastDataLoader) – The server-side test set.
config (DDict) – Configuration of the server.
- Returns:
The initialized server.
- Return type:
Server
- class armlet.FL_pipeline.FL_algorithms.ArmletClient(index: int, train_set: FastDataLoader | DataLoader, test_set: FastDataLoader | DataLoader, val_set: FastDataLoader | None, optimizer_cfg: OptimizerConfigurator, loss_fn: Module, local_epochs: int, fine_tuning_epochs: int = 0, clipping: float = 0, persistency: bool = True, **kwargs)#
Bases:
Client- evaluate(evaluator: Evaluator, test_set: FastDataLoader) dict[str, float]#
Evaluate the local model on the client’s
test_set. If the test set is not set or the client has not received the global model from the server, the method returns an empty dictionary.- Parameters:
evaluator (Evaluator) – The evaluator to use for the evaluation.
test_set (FastDataLoader) – The test set to use for the evaluation.
- Returns:
The evaluation results. The keys are the metrics and the values are the results.
- Return type:
dict[str, float]
- class armlet.FL_pipeline.FL_algorithms.ArmletServer(model: Module, test_set: FastDataLoader | None, val_set: FastDataLoader | None, clients: Sequence[Client], weighted: bool = False, lr: float = 1, **kwargs)#
Bases:
Server- evaluate(evaluator: Evaluator, test_set: FastDataLoader) dict[str, float]#
Evaluate the global federated model on the
test_set. If the test set is not set, the method returns an empty dictionary.- Returns:
- The evaluation results. The keys are the metrics and the values are
the results.
- Return type:
dict[str, float]
- fit(n_rounds: int = 10, eligible_perc: float = 0.1, finalize: bool = True, **kwargs) None#
Run the federated learning algorithm. The default behaviour of this method is to run the Federated Averaging algorithm. The server selects a percentage of the clients to participate in each round, sends the global model to the clients, which compute the local updates and send them back to the server. The server aggregates the models of the clients and repeats the process for a number of rounds.
- Parameters:
n_rounds (int, optional) – The number of rounds to run. Defaults to 10.
eligible_perc (float, optional) – The percentage of clients that will be selected for each round. Defaults to 0.1.
finalize (bool, optional) – If True, the server will finalize the federated learning process. Defaults to True.
**kwargs – Additional keyword arguments.