fl4health.servers.model_merge_server module

class ModelMergeServer(*, client_manager, strategy=None, server_model=None, checkpointer=None, parameter_exchanger=None, reporters=None, server_name=None)[source]

Bases: Server

__init__(*, client_manager, strategy=None, server_model=None, checkpointer=None, parameter_exchanger=None, reporters=None, server_name=None)[source]
ModelMergeServer provides functionality to fetch client weights, perform a simple average,

redistribute to clients for evaluation. Optionally can perform server side evaluation as well.

Parameters:
  • client_manager (ClientManager) – Determines the mechanism by which clients are sampled by the server, if they are to be sampled at all.

  • strategy (Strategy | None, optional) – The aggregation strategy to be used by the server to handle client updates sent by the participating clients. Must be ModelMergeStrategy.

  • checkpointer (LatestTorchCheckpointer | None, optional) – To be provided if the server should perform server side checkpointing on the merged model. If none, then no server-side checkpointing is performed. Defaults to None.

  • server_model (nn.Module | None) – Optional model to be hydrated with parameters from model merge if doing server side checkpointing. Must only be provided if checkpointer is also provided. Defaults to None.

  • parameter_exchanger (ExchangerType | None, optional) – A parameter exchanger used to facilitate server-side model checkpointing if a checkpointer has been defined. If not provided then checkpointing will not be done unless the _hydrate_model_for_checkpointing function is overridden. Because the server only sees numpy arrays, the parameter exchanger is used to insert the numpy arrays into a provided model. Defaults to None.

  • reporters (Sequence[BaseReporter], optional) – A sequence of FL4Health reporters which the server should send data to before and after each round.

  • server_name (str | None) – An optional string name to uniquely identify server.

fit(num_rounds, timeout)[source]
Performs a fit round in which the local client weights are evaluated on their test set,

uploaded to the server and averaged, then redistributed to clients for evaluation. Optionally, can perform evaluation of the merged model on the server side as well.

Parameters:
  • num_rounds (int) – Not used.

  • timeout (float | None) – Timeout in seconds that the server should wait for the clients to respond. If none, then it will wait for the minimum number to respond indefinitely.

Returns:

The first element of the tuple is a History object containing the aggregated

metrics returned from the clients. Tuple also contains elapsed time in seconds for round.

Return type:

tuple[History, float]