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.
- 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:
- 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:
- 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:
- 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.
- 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
) – (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.