fl4health.strategies.feddg_ga_with_adaptive_constraint module

class FedDgGaAdaptiveConstraint(*, min_fit_clients=2, min_evaluate_clients=2, min_available_clients=2, evaluate_fn=None, on_fit_config_fn=None, on_evaluate_config_fn=None, accept_failures=True, initial_parameters, fit_metrics_aggregation_fn=None, evaluate_metrics_aggregation_fn=None, initial_loss_weight=1.0, adapt_loss_weight=False, loss_weight_delta=0.1, loss_weight_patience=5, weighted_train_losses=False, fairness_metric=None, adjustment_weight_step_size=0.2)[source]

Bases: FedDgGa

__init__(*, min_fit_clients=2, min_evaluate_clients=2, min_available_clients=2, evaluate_fn=None, on_fit_config_fn=None, on_evaluate_config_fn=None, accept_failures=True, initial_parameters, fit_metrics_aggregation_fn=None, evaluate_metrics_aggregation_fn=None, initial_loss_weight=1.0, adapt_loss_weight=False, loss_weight_delta=0.1, loss_weight_patience=5, weighted_train_losses=False, fairness_metric=None, adjustment_weight_step_size=0.2)[source]

Strategy for the FedDG-GA algorithm (Federated Domain Generalization with Generalization Adjustment, Zhang et al. 2023) combined with the Adaptive Strategy for Auxiliary constraints like FedProx. See documentation on FedAvgWithAdaptiveConstraint for more information.

NOTE: Initial parameters are NOT optional. They must be passed for this strategy.

Parameters:
  • 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 (Callable[[int, NDArrays, dict[str, Scalar]], tuple[float, dict[str, Scalar]] | None] | None) – Optional function used for validation. Defaults to None.

  • on_fit_config_fn (Callable[[int], dict[str, Scalar]] | None, optional) – Function used to configure training. Defaults to None.

  • on_evaluate_config_fn (Callable[[int], dict[str, Scalar]] | None, optional) – Function used to configure validation. Defaults to None

  • initial_parameters (Parameters) – Initial global model parameters.

  • accept_failures (bool, optional) – Whether or not accept rounds containing failures. Defaults to True.

  • fit_metrics_aggregation_fn (MetricsAggregationFn | None, optional) – Metrics aggregation function, Defaults to None.

  • evaluate_metrics_aggregation_fn (MetricsAggregationFn | None, optional) – Metrics aggregation function. Defaults to None.

  • initial_loss_weight (float, optional) – Initial penalty loss weight (mu in FedProx). If adaptivity is false, then this is the constant weight used for all clients. Defaults to 1.0.

  • adapt_loss_weight (bool, optional) – Determines whether the value of the penalty loss weight is adaptively modified by the server based on aggregated train loss. Defaults to False.

  • loss_weight_delta (float, optional) – This is the amount by which the server changes the value of the penalty loss weight based on the modification criteria. Only applicable if adaptivity is on. Defaults to 0.1.

  • loss_weight_patience (int, optional) – This is the number of rounds a server must see decreasing aggregated train loss before reducing the value of the penalty loss weight. Only applicable if adaptivity is on. Defaults to 5.

  • weighted_train_losses (bool, optional) – Determines whether the training losses from the clients should be aggregated using a weighted or unweighted average. These aggregated losses are used to adjust the proximal weight in the adaptive setting. Defaults to False.

  • fairness_metric (FairnessMetric | None, optional) – he metric to evaluate the local model of each client against the global model in order to determine their adjustment weight for aggregation. Can be set to any default metric in FairnessMetricType or set to use a custom metric. Optional, default is FairnessMetric(FairnessMetricType.LOSS) when specified as None.

  • adjustment_weight_step_size (float, optional) – The step size to determine the magnitude of change for the generalization adjustment weight. It has to be 0 < adjustment_weight_step_size < 1. Optional, default is 0.2.

aggregate_fit(server_round, results, failures)[source]

Aggregate fit results by weighing them against the adjustment weights and then summing them.

Collects the fit metrics that will be used to change the adjustment weights for the next round.

If applicable, determine whether the constraint weight should be updated based on the aggregated loss seen on the clients.

Parameters:
  • server_round (int) – (int) the current server round.

  • results (list[tuple[ClientProxy, FitRes]]) – (list[tuple[ClientProxy, FitRes]]) The clients’ fit results.

  • failures (list[tuple[ClientProxy, FitRes] | BaseException]) – (list[tuple[ClientProxy, FitRes] | BaseException]) the clients’ fit failures.

Return type:

tuple[Parameters | None, dict[str, Union[bool, bytes, float, int, str]]]

Returns:

(tuple[Parameters | None, dict[str, Scalar]]) A tuple containing the aggregated parameters

and the aggregated fit metrics. For adaptive constraints, the server also packs a constraint weight to be sent to the clients. This is sent even if adaptive constraint weights are turned off and the value simply remains constant.