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:
- Returns:
(type[torch.nn.Module]) A torch.nn.Module class corresponding to the given model.
- Raises:
ValueError – if the client is not supported.
- 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:
- 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.
- fit_config_function(server_config, current_server_round)[source]¶
Produce the fit config dictionary.
- 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.