Strategy¶
- class Strategy[source]¶
Bases:
ABC服务器策略实现的抽象基类。
Methods
aggregate_evaluate(server_round, results, ...)Aggregate evaluation results.
aggregate_fit(server_round, results, failures)Aggregate training results.
configure_evaluate(server_round, parameters, ...)配置下一轮评估。
configure_fit(server_round, parameters, ...)配置下一轮训练。
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.
- 参数:
server_round (int) -- 本轮联邦学习。
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.
- 返回:
aggregation_result -- The aggregated evaluation result. Aggregation typically uses some variant of a weighted average.
- 返回类型:
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.
- 参数:
server_round (int) -- 本轮联邦学习。
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.
- 返回:
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.
- 返回类型:
Tuple[Optional[Parameters], Dict[str, Scalar]]
- abstract configure_evaluate(server_round: int, parameters: Parameters, client_manager: ClientManager) list[tuple[ClientProxy, EvaluateIns]][source]¶
配置下一轮评估。
- 参数:
server_round (int) -- 本轮联邦学习。
parameters (Parameters) -- The current (global) model parameters.
client_manager (ClientManager) -- The client manager which holds all currently connected clients.
- 返回:
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.
- 返回类型:
List[Tuple[ClientProxy, EvaluateIns]]
- abstract configure_fit(server_round: int, parameters: Parameters, client_manager: ClientManager) list[tuple[ClientProxy, FitIns]][source]¶
配置下一轮训练。
- 参数:
server_round (int) -- 本轮联邦学习。
parameters (Parameters) -- The current (global) model parameters.
client_manager (ClientManager) -- The client manager which holds all currently connected clients.
- 返回:
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.
- 返回类型:
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.
- 参数:
server_round (int) -- 本轮联邦学习。
parameters (Parameters) -- The current (global) model parameters.
- 返回:
evaluation_result -- The evaluation result, usually a Tuple containing loss and a dictionary containing task-specific metrics (e.g., accuracy).
- 返回类型:
Optional[Tuple[float, Dict[str, Scalar]]]
- abstract initialize_parameters(client_manager: ClientManager) Parameters | None[source]¶
Initialize the (global) model parameters.
- 参数:
client_manager (ClientManager) -- The client manager which holds all currently connected clients.
- 返回:
parameters -- If parameters are returned, then the server will treat these as the initial global model parameters.
- 返回类型:
Optional[Parameters]