florist.api.servers.strategies module

Definitions for the strategies, strategy enumeration and server constructors.

class ServerFactory(get_server_function)[source]

Bases: object

Factory class that will provide the server constructor.

__init__(get_server_function)[source]

Initialize a ServerFactory.

Parameters:

get_server_function (Callable[[Module, int, list[BaseReporter], dict[str, Any]], FlServer]) – (GetServerFunction) The function that will be used to produce the server constructor.

get_server_constructor(model, n_clients, reporters, server_config)[source]

Make the server constructor based on the self.get_server_function.

Parameters:
  • model (Module) – (torch.nn.Model) The model object.

  • n_clients (int) – (int) The number of clients participating in the FL training.

  • reporters (list[BaseReporter]) – (list[BaseReporter]) A list of reporters to be passed to the FL server.

  • server_config (dict[str, Union[bool, bytes, float, int, str]]) – (dict[str, Any]) A dictionary with the server configuration values.

Return type:

Callable[[Any], FlServer]

Returns:

(Callable[[Any], FlServer]) A callable function that will construct an FL server.

class Strategy(value)[source]

Bases: Enum

The strategies that can be picked for training.

FEDAVG = 'FedAvg'
FEDPROX = 'FedProx'
get_config_parser()[source]

Return the config parser for this strategy.

Return type:

ConfigParser

Returns:

(ConfigParser) An instance of ConfigParser for the corresponding strategy.

Raises:

ValueError – if the strategy is not supported.

get_server_factory()[source]

Return the server factory instance for this strategy.

Return type:

ServerFactory

Returns:

(type[AbstractServerFactory]) A ServerFactory instance that can be used to construct the FL server for the given strategy.

Raises:

ValueError – if the client is not supported.

classmethod list()[source]

List all the supported strategies.

Return type:

list[str]

Returns:

(list[str]) a list of supported strategies.

fit_config_function(server_config, current_server_round)[source]

Produce the fit config dictionary.

Parameters:
  • server_config (dict[str, Union[bool, bytes, float, int, str]]) – (dict[str, Any]) A dictionary with the server configuration.

  • current_server_round (int) – (int) The current server round.

Return type:

dict[str, Union[bool, bytes, float, int, str]]

get_fedavg_server(model, n_clients, reporters, server_config)[source]

Return a server with FedAvg strategy.

Parameters:
  • model (Module) – (torch.nn.Module) The torch.nn.Module instance for the model.

  • n_clients (int) – (int) the number of clients participating in the FL training.

  • reporters (list[BaseReporter]) – (list[BaseReporter]) A list of reporters to be passed to the FL server.

  • server_config (dict[str, Union[bool, bytes, float, int, str]]) – (dict[str, Any]) A dictionary with the server configuration values.

Return type:

FlServer

Returns:

(FlServer) An FlServer instance configured with FedAvg strategy.

get_fedprox_server(model, n_clients, reporters, server_config)[source]

Return a server with FedProx strategy.

Parameters:
  • model (Module) – (nn.Module) The torch.nn.Module instance for the model.

  • n_clients (int) – (int) the number of clients participating in the FL training.

  • reporters (list[BaseReporter]) – (list[BaseReporter]) A list of reporters to be passed to the FL server.

  • server_config (dict[str, Union[bool, bytes, float, int, str]]) – (dict[str, Any]) A dictionary with the server configuration values.

Return type:

FlServer

Returns:

(FlServer) An FlServer instance configured with FedProx strategy.