StrategyΒΆ
- class Strategy[source]ΒΆ
Bases:
ABC
Abstract base class for server strategy implementations.
Methods
aggregate_evaluate
(server_round, replies)Aggregate evaluation metrics from client nodes.
aggregate_train
(server_round, replies)Aggregate training results from client nodes.
configure_evaluate
(server_round, arrays, ...)Configure the next round of evaluation.
configure_train
(server_round, arrays, ...)Configure the next round of training.
start
(grid, initial_arrays[, num_rounds, ...])Execute the federated learning strategy.
summary
()Log summary configuration of the strategy.
- abstract aggregate_evaluate(server_round: int, replies: Iterable[Message]) MetricRecord | None [source]ΒΆ
Aggregate evaluation metrics from client nodes.
- Parameters:
server_round (int) β The current round of federated learning.
replies (Iterable[Message]) β Iterable of reply messages received from client nodes after evaluation. MetricRecords in the messages are aggregated.
- Returns:
Aggregated evaluation metrics from all participating clients, or None if aggregation failed.
- Return type:
Optional[MetricRecord]
- abstract aggregate_train(server_round: int, replies: Iterable[Message]) tuple[ArrayRecord | None, MetricRecord | None] [source]ΒΆ
Aggregate training results from client nodes.
- Parameters:
server_round (int) β The current round of federated learning, starting from 1.
replies (Iterable[Message]) β Iterable of reply messages received from client nodes after training. Each message contains ArrayRecords and MetricRecords that get aggregated.
- Returns:
A tuple containing: - ArrayRecord: Aggregated ArrayRecord, or None if aggregation failed - MetricRecord: Aggregated MetricRecord, or None if aggregation failed
- Return type:
tuple[Optional[ArrayRecord], Optional[MetricRecord]]
- abstract configure_evaluate(server_round: int, arrays: ArrayRecord, config: ConfigRecord, grid: Grid) Iterable[Message] [source]ΒΆ
Configure the next round of evaluation.
- Parameters:
server_round (int) β The current round of federated learning.
arrays (ArrayRecord) β Current global ArrayRecord (e.g. global model) to be sent to client nodes for evaluation.
config (ConfigRecord) β Configuration to be sent to clients nodes for evaluation.
grid (Grid) β The Grid instance used for node sampling and communication.
- Returns:
An iterable of messages to be sent to selected client nodes for evaluation.
- Return type:
Iterable[Message]
- abstract configure_train(server_round: int, arrays: ArrayRecord, config: ConfigRecord, grid: Grid) Iterable[Message] [source]ΒΆ
Configure the next round of training.
- Parameters:
server_round (int) β The current round of federated learning.
arrays (ArrayRecord) β Current global ArrayRecord (e.g. global model) to be sent to client nodes for training.
config (ConfigRecord) β Configuration to be sent to clients nodes for training.
grid (Grid) β The Grid instance used for node sampling and communication.
- Returns:
An iterable of messages to be sent to selected client nodes for training.
- Return type:
Iterable[Message]
- start(grid: Grid, initial_arrays: ArrayRecord, num_rounds: int = 3, timeout: float = 3600, train_config: ConfigRecord | None = None, evaluate_config: ConfigRecord | None = None, evaluate_fn: Callable[[int, ArrayRecord], MetricRecord] | None = None) Result [source]ΒΆ
Execute the federated learning strategy.
Runs the complete federated learning workflow for the specified number of rounds, including training, evaluation, and optional centralized evaluation.
- Parameters:
grid (Grid) β The Grid instance used to send/receive Messages from nodes executing a ClientApp.
initial_arrays (ArrayRecord) β Initial model parameters (arrays) to be used for federated learning.
num_rounds (int (default: 3)) β Number of federated learning rounds to execute.
timeout (float (default: 3600)) β Timeout in seconds for waiting for node responses.
train_config (ConfigRecord, optional) β Configuration to be sent to nodes during training rounds. If unset, an empty ConfigRecord will be used.
evaluate_config (ConfigRecord, optional) β Configuration to be sent to nodes during evaluation rounds. If unset, an empty ConfigRecord will be used.
evaluate_fn (Callable[[int, ArrayRecord], MetricRecord], optional) β Optional function for centralized evaluation of the global model. Takes server round number and array record, returns a MetricRecord. If provided, will be called before the first round and after each round. Defaults to None.
- Returns:
Results containing final model arrays and also training metrics, evaluation metrics and global evaluation metrics (if provided) from all rounds.
- Return type:
Results