Strategy#

class Strategy[source]#

Bases : ABC

Abstract base class for server strategy implementations.

Methods

aggregate_evaluate(server_round, results, ...)

Aggregate evaluation results.

aggregate_fit(server_round, results, failures)

Aggregate training results.

configure_evaluate(server_round, parameters, ...)

Configure the next round of evaluation.

configure_fit(server_round, parameters, ...)

Configure the next round of training.

evaluate(server_round, parameters)

Evaluate the current model parameters.

initialize_parameters(client_manager)

Initialize the (global) model parameters.

abstract aggregate_evaluate(server_round: int, results: List[Tuple[ClientProxy, EvaluateRes]], failures: List[Tuple[ClientProxy, EvaluateRes] | BaseException]) Tuple[float | None, Dict[str, bool | bytes | float | int | str]][source]#

Aggregate evaluation results.

Paramètres:
  • server_round (int) – The current round of federated learning.

  • results (List[Tuple[ClientProxy, FitRes]]) – Successful updates from the previously selected and configured clients. Each pair of (ClientProxy, FitRes constitutes a successful update from one of the previously selected clients. Not that not all previously selected clients are necessarily included in this list: a client might drop out and not submit a result. For each client that did not submit an update, there should be an Exception in failures.

  • failures (List[Union[Tuple[ClientProxy, EvaluateRes], BaseException]]) – Exceptions that occurred while the server was waiting for client updates.

Renvoie:

aggregation_result – The aggregated evaluation result. Aggregation typically uses some variant of a weighted average.

Type renvoyé:

Tuple[Optional[float], Dict[str, Scalar]]

abstract aggregate_fit(server_round: int, results: List[Tuple[ClientProxy, FitRes]], failures: List[Tuple[ClientProxy, FitRes] | BaseException]) Tuple[Parameters | None, Dict[str, bool | bytes | float | int | str]][source]#

Aggregate training results.

Paramètres:
  • server_round (int) – The current round of federated learning.

  • results (List[Tuple[ClientProxy, FitRes]]) – Successful updates from the previously selected and configured clients. Each pair of (ClientProxy, FitRes) constitutes a successful update from one of the previously selected clients. Not that not all previously selected clients are necessarily included in this list: a client might drop out and not submit a result. For each client that did not submit an update, there should be an Exception in failures.

  • failures (List[Union[Tuple[ClientProxy, FitRes], BaseException]]) – Exceptions that occurred while the server was waiting for client updates.

Renvoie:

parameters – If parameters are returned, then the server will treat these as the new global model parameters (i.e., it will replace the previous parameters with the ones returned from this method). If None is returned (e.g., because there were only failures and no viable results) then the server will no update the previous model parameters, the updates received in this round are discarded, and the global model parameters remain the same.

Type renvoyé:

Tuple[Optional[Parameters], Dict[str, Scalar]]

abstract configure_evaluate(server_round: int, parameters: Parameters, client_manager: ClientManager) List[Tuple[ClientProxy, EvaluateIns]][source]#

Configure the next round of evaluation.

Paramètres:
  • server_round (int) – The current round of federated learning.

  • parameters (Parameters) – The current (global) model parameters.

  • client_manager (ClientManager) – The client manager which holds all currently connected clients.

Renvoie:

evaluate_configuration – A list of tuples. Each tuple in the list identifies a ClientProxy and the EvaluateIns for this particular ClientProxy. If a particular ClientProxy is not included in this list, it means that this ClientProxy will not participate in the next round of federated evaluation.

Type renvoyé:

List[Tuple[ClientProxy, EvaluateIns]]

abstract configure_fit(server_round: int, parameters: Parameters, client_manager: ClientManager) List[Tuple[ClientProxy, FitIns]][source]#

Configure the next round of training.

Paramètres:
  • server_round (int) – The current round of federated learning.

  • parameters (Parameters) – The current (global) model parameters.

  • client_manager (ClientManager) – The client manager which holds all currently connected clients.

Renvoie:

fit_configuration – A list of tuples. Each tuple in the list identifies a ClientProxy and the FitIns for this particular ClientProxy. If a particular ClientProxy is not included in this list, it means that this ClientProxy will not participate in the next round of federated learning.

Type renvoyé:

List[Tuple[ClientProxy, FitIns]]

abstract evaluate(server_round: int, parameters: Parameters) Tuple[float, Dict[str, bool | bytes | float | int | str]] | None[source]#

Evaluate the current model parameters.

This function can be used to perform centralized (i.e., server-side) evaluation of model parameters.

Paramètres:
  • server_round (int) – The current round of federated learning.

  • parameters (Parameters) – The current (global) model parameters.

Renvoie:

evaluation_result – The evaluation result, usually a Tuple containing loss and a dictionary containing task-specific metrics (e.g., accuracy).

Type renvoyé:

Optional[Tuple[float, Dict[str, Scalar]]]

abstract initialize_parameters(client_manager: ClientManager) Parameters | None[source]#

Initialize the (global) model parameters.

Paramètres:

client_manager (ClientManager) – The client manager which holds all currently connected clients.

Renvoie:

parameters – If parameters are returned, then the server will treat these as the initial global model parameters.

Type renvoyé:

Optional[Parameters]