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.

Parameters:
  • 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.

Returns:

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

Return type:

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.

Parameters:
  • 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.

Returns:

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.

Return type:

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.

Parameters:
  • 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.

Returns:

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.

Return type:

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.

Parameters:
  • 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.

Returns:

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.

Return type:

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.

Parameters:
  • server_round (int) – The current round of federated learning.

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

Returns:

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

Return type:

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

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

Initialize the (global) model parameters.

Parameters:

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

Returns:

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

Return type:

Optional[Parameters]