florist.api.servers.models module

Functions and definitions for server models.

class Model(value)[source]

Bases: Enum

Enumeration of supported models.

MNIST_FEDAVG = 'MNIST with FedAvg'
MNIST_FEDPROX = 'MNIST with FedProx'
classmethod class_for_model(model)[source]

Return the class for a given model.

Parameters:

model (Self) – (Model) The model enumeration object.

Return type:

type[Module]

Returns:

(type[torch.nn.Module]) A torch.nn.Module class corresponding to the given model.

Raises:

ValueError – if the client is not supported.

classmethod config_parser_for_model(model)[source]

Return the config parser for a given model.

Parameters:

model (Self) – (Model) The model enumeration object.

Return type:

ConfigParser

Returns:

(type[torch.nn.Module]) A torch.nn.Module class corresponding to the given model.

Raises:

ValueError – if the client is not supported.

classmethod list()[source]

List all the supported models.

Return type:

list[str]

Returns:

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

classmethod server_factory_for_model(model)[source]

Return the server factory instance for a given model.

Parameters:

model (Self) – (Model) The model enumeration object.

Return type:

ServerFactory

Returns:

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

Raises:

ValueError – if the client is not supported.

class ServerFactory(get_server_function, model)[source]

Bases: object

Factory class that will provide the server constructor.

__init__(get_server_function, model)[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.

  • model (Model) – (Model) The model to call the server function with.

get_server_constructor(n_clients, reporters, server_config)[source]

Make the server constructor based on the self.get_server_function.

Parameters:
  • 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, Any]) – (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.

fit_config_function(server_config, current_server_round)[source]

Produce the fit config dictionary.

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

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

Return type:

dict[str, int]

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

Return a server with FedAvg 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, Any]) – (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, Any]) – (dict[str, Any]) A dictionary with the server configuration values.

Return type:

FlServer

Returns:

(FlServer) An FlServer instance configured with FedProx strategy.