florist.api.servers.utils module

Utilities functions and definitions for starting a server.

fit_config(batch_size, local_epochs, current_server_round)[source]

Return a dictionary used to configure the server’s fit function.

Parameters:
  • batch_size (int) – (int) the size of the batch of samples.

  • local_epochs (int) – (int) the number of local epochs the clients will run.

  • current_server_round (int) – (int) the current server round

Return type:

Dict[str, int]

Returns:

(Dict[str, int]) A dictionary to the used at the config for the fit function.

get_server(model, reporters, fit_config=<function fit_config>, n_clients=2, batch_size=8, local_epochs=1)[source]

Return a server instance with FedAvg aggregation strategy.

Parameters:
  • model (Module) – (torch.nn.Model) the model the server and clients will be using.

  • fit_config (Callable[[int, int, int], Dict[str, int]]) – (Callable[[int, int, int], Dict[str, int]]) the function to configure the fit method.

  • n_clients (int) – (int) the number of clients that will participate on training. Optional, default is 2.

  • batch_size (int) – (int) the size of the batch of samples. Optional, default is 8.

  • local_epochs (int) – (int) the number of local epochs the clients will run. Optional, default is 1.

  • reporters (list[BaseReporter]) – (list[fl4health.reporting.base_reporter.BaseReporter]) An optional metrics reporter instance. Default is None.

Return type:

FlServer

Returns:

(fl4health.server.base_server.FlServer) An instance of FlServer with FedAvg as strategy.