FedOpt#
- class FedOpt(*, fraction_fit: float = 1.0, fraction_evaluate: float = 1.0, min_fit_clients: int = 2, min_evaluate_clients: int = 2, min_available_clients: int = 2, evaluate_fn: Callable[[int, List[ndarray[Any, dtype[Any]]], Dict[str, bool | bytes | float | int | str]], Tuple[float, Dict[str, bool | bytes | float | int | str]] | None] | None = None, on_fit_config_fn: Callable[[int], Dict[str, bool | bytes | float | int | str]] | None = None, on_evaluate_config_fn: Callable[[int], Dict[str, bool | bytes | float | int | str]] | None = None, accept_failures: bool = True, initial_parameters: Parameters, fit_metrics_aggregation_fn: Callable[[List[Tuple[int, Dict[str, bool | bytes | float | int | str]]]], Dict[str, bool | bytes | float | int | str]] | None = None, evaluate_metrics_aggregation_fn: Callable[[List[Tuple[int, Dict[str, bool | bytes | float | int | str]]]], Dict[str, bool | bytes | float | int | str]] | None = None, eta: float = 0.1, eta_l: float = 0.1, beta_1: float = 0.0, beta_2: float = 0.0, tau: float = 1e-09)[source]#
Bases:
FedAvg
Federated Optim strategy.
Implementation based on https://arxiv.org/abs/2003.00295v5
- Parameters:
fraction_fit (float, optional) β Fraction of clients used during training. Defaults to 1.0.
fraction_evaluate (float, optional) β Fraction of clients used during validation. Defaults to 1.0.
min_fit_clients (int, optional) β Minimum number of clients used during training. Defaults to 2.
min_evaluate_clients (int, optional) β Minimum number of clients used during validation. Defaults to 2.
min_available_clients (int, optional) β Minimum number of total clients in the system. Defaults to 2.
evaluate_fn (Optional[Callable[[int, NDArrays, Dict[str, Scalar]], Optional[Tuple[float, Dict[str, Scalar]]]]]) β Optional function used for validation. Defaults to None.
on_fit_config_fn (Callable[[int], Dict[str, Scalar]], optional) β Function used to configure training. Defaults to None.
on_evaluate_config_fn (Callable[[int], Dict[str, Scalar]], optional) β Function used to configure validation. Defaults to None.
accept_failures (bool, optional) β Whether or not accept rounds containing failures. Defaults to True.
initial_parameters (Parameters) β Initial global model parameters.
fit_metrics_aggregation_fn (Optional[MetricsAggregationFn]) β Metrics aggregation function, optional.
evaluate_metrics_aggregation_fn (Optional[MetricsAggregationFn]) β Metrics aggregation function, optional.
eta (float, optional) β Server-side learning rate. Defaults to 1e-1.
eta_l (float, optional) β Client-side learning rate. Defaults to 1e-1.
beta_1 (float, optional) β Momentum parameter. Defaults to 0.0.
beta_2 (float, optional) β Second moment parameter. Defaults to 0.0.
tau (float, optional) β Controls the algorithmβs degree of adaptability. Defaults to 1e-9.
Methods
aggregate_evaluate
(server_round, results, ...)Aggregate evaluation losses using weighted average.
aggregate_fit
(server_round, results, failures)Aggregate fit results using weighted average.
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 model parameters using an evaluation function.
initialize_parameters
(client_manager)Initialize global model parameters.
num_evaluation_clients
(num_available_clients)Use a fraction of available clients for evaluation.
num_fit_clients
(num_available_clients)Return the sample size and the required number of available clients.
- 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]] #
Aggregate evaluation losses using weighted average.
- 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]] #
Aggregate fit results using weighted average.
- configure_evaluate(server_round: int, parameters: Parameters, client_manager: ClientManager) List[Tuple[ClientProxy, EvaluateIns]] #
Configure the next round of evaluation.
- configure_fit(server_round: int, parameters: Parameters, client_manager: ClientManager) List[Tuple[ClientProxy, FitIns]] #
Configure the next round of training.
- evaluate(server_round: int, parameters: Parameters) Tuple[float, Dict[str, bool | bytes | float | int | str]] | None #
Evaluate model parameters using an evaluation function.
- initialize_parameters(client_manager: ClientManager) Parameters | None #
Initialize global model parameters.
- num_evaluation_clients(num_available_clients: int) Tuple[int, int] #
Use a fraction of available clients for evaluation.
- num_fit_clients(num_available_clients: int) Tuple[int, int] #
Return the sample size and the required number of available clients.