fl4health.servers.scaffold_server module¶
- class DPScaffoldServer(client_manager, fl_config, noise_multiplier, batch_size, num_server_rounds, strategy, local_epochs=None, local_steps=None, delta=None, checkpoint_and_state_module=None, warm_start=False, reporters=None, on_init_parameters_config_fn=None, server_name=None, accept_failures=True)[source]¶
Bases:
ScaffoldServer
,InstanceLevelDpServer
- __init__(client_manager, fl_config, noise_multiplier, batch_size, num_server_rounds, strategy, local_epochs=None, local_steps=None, delta=None, checkpoint_and_state_module=None, warm_start=False, reporters=None, on_init_parameters_config_fn=None, server_name=None, accept_failures=True)[source]¶
Custom FL Server for Instance Level Differentially Private Scaffold algorithm as specified in https://arxiv.org/abs/2111.09278
- Parameters:
client_manager (ClientManager) – Determines the mechanism by which clients are sampled by the server, if they are to be sampled at all.
fl_config (Config) – This should be the configuration that was used to setup the federated training. In most cases it should be the “source of truth” for how FL training/evaluation should proceed. For example, the config used to produce the on_fit_config_fn and on_evaluate_config_fn for the strategy. NOTE: This config is DISTINCT from the Flwr server config, which is extremely minimal.
noise_multiplier (int) – The amount of Gaussian noise to be added to the per sample gradient during DP-SGD.
batch_size (int) – The batch size to be used in training on the client-side. Used in privacy accounting.
num_server_rounds (int) – The number of server rounds to be done in FL training. Used in privacy accounting
local_epochs (int | None, optional) – Number of local epochs to be performed on the client-side. This is used in privacy accounting. One of local_epochs or local_steps should be defined, but not both. Defaults to None.
local_steps (int | None, optional) – Number of local steps to be performed on the client-side. This is used in privacy accounting. One of local_epochs or local_steps should be defined, but not both. Defaults to None.
strategy (Scaffold) – The aggregation strategy to be used by the server to handle client updates and other information potentially sent by the participating clients. This strategy must be of SCAFFOLD type.
checkpoint_and_state_module (DpScaffoldServerCheckpointAndStateModule | None, optional) – This module is used to handle both model checkpointing and state checkpointing. The former is aimed at saving model artifacts to be used or evaluated after training. The latter is used to preserve training state (including models) such that if FL training is interrupted, the process may be restarted. If no module is provided, no checkpointing or state preservation will happen. Defaults to None.
warm_start (bool, optional) – Whether or not to initialize control variates of each client as local gradients. The clients will perform a training pass (without updating the weights) in order to provide a “warm” estimate of the SCAFFOLD control variates. If false, variates are initialized to 0. Defaults to False.
delta (float | None, optional) – The delta value for epsilon-delta DP accounting. If None it defaults to being 1/total_samples in the FL run. Defaults to None.
reporters (Sequence[BaseReporter], optional) – A sequence of FL4Health reporters which the client should send data to.
on_init_parameters_config_fn (Callable[[int], dict[str, Scalar]] | None, optional) – Function used to configure how one asks a client to provide parameters from which to initialize all other clients by providing a Config dictionary. If this is none, then a blank config is sent with the parameter request (which is default behavior for flower servers). Defaults to None.
server_name (str | None, optional) – An optional string name to uniquely identify server. This name is also used as part of any state checkpointing done by the server. Defaults to None.
accept_failures (bool, optional) – Determines whether the server should accept
- fit(num_rounds, timeout)[source]¶
Run DP Scaffold algorithm for the specified number of rounds.
- Parameters:
num_rounds (int) – Number of rounds of FL to perform (i.e. server rounds).
timeout (float | None) – Timeout associated with queries to the clients in seconds. The server waits for timeout seconds before moving on without any unresponsive clients. If None, there is no timeout and the server waits for the minimum number of clients to be available set in the strategy.
- Returns:
- First element of tuple is history object containing the full set of FL
training results, including aggregated loss and metrics. Tuple also includes the elapsed time in seconds for round.
- Return type:
- class ScaffoldServer(client_manager, fl_config, strategy, reporters=None, checkpoint_and_state_module=None, on_init_parameters_config_fn=None, server_name=None, accept_failures=True, warm_start=False)[source]¶
Bases:
FlServer
- __init__(client_manager, fl_config, strategy, reporters=None, checkpoint_and_state_module=None, on_init_parameters_config_fn=None, server_name=None, accept_failures=True, warm_start=False)[source]¶
Custom FL Server for scaffold algorithm to handle warm initialization of control variates as specified in https://arxiv.org/abs/1910.06378.
- Parameters:
client_manager (ClientManager) – Determines the mechanism by which clients are sampled by the server, if they are to be sampled at all.
fl_config (Config) – This should be the configuration that was used to setup the federated training. In most cases it should be the “source of truth” for how FL training/evaluation should proceed. For example, the config used to produce the on_fit_config_fn and on_evaluate_config_fn for the strategy. NOTE: This config is DISTINCT from the Flwr server config, which is extremely minimal.
strategy (Scaffold) – The aggregation strategy to be used by the server to handle client updates and other information potentially sent by the participating clients. This strategy must be of SCAFFOLD type.
reporters (Sequence[BaseReporter] | None, optional) – sequence of FL4Health reporters which the server should send data to before and after each round. Defaults to None.
checkpoint_and_state_module (ScaffoldServerCheckpointAndStateModule | None, optional) – This module is used to handle both model checkpointing and state checkpointing. The former is aimed at saving model artifacts to be used or evaluated after training. The latter is used to preserve training state (including models) such that if FL training is interrupted, the process may be restarted. If no module is provided, no checkpointing or state preservation will happen. Defaults to None.
on_init_parameters_config_fn (Callable[[int], dict[str, Scalar]] | None, optional) – Function used to configure how one asks a client to provide parameters from which to initialize all other clients by providing a Config dictionary. If this is none, then a blank config is sent with the parameter request (which is default behavior for flower servers). Defaults to None.
server_name (str | None, optional) – An optional string name to uniquely identify server. This name is also used as part of any state checkpointing done by the server. Defaults to None.
accept_failures (bool, optional) – Determines whether the server should accept failures during training or evaluation from clients or not. If set to False, this will cause the server to shutdown all clients and throw an exception. Defaults to True.
warm_start (bool, optional) – Whether or not to initialize control variates of each client as local gradients. The clients will perform a training pass (without updating the weights) in order to provide a “warm” estimate of the SCAFFOLD control variates. If false, variates are initialized to 0. Defaults to False.
- fit(num_rounds, timeout)[source]¶
Run the SCAFFOLD FL algorithm for a fixed number of rounds. This overrides the base server fit class just to ensure that the provided strategy is a Scaffold strategy object before proceeding.
- Parameters:
num_rounds (int) – Number of rounds of FL to perform (i.e. server rounds).
timeout (float | None) – Timeout associated with queries to the clients in seconds. The server waits for timeout seconds before moving on without any unresponsive clients. If None, there is no timeout and the server waits for the minimum number of clients to be available set in the strategy.
- Returns:
- The first element of the tuple is a history object containing the full set of
FL training results, including things like aggregated loss and metrics. Tuple also includes elapsed time in seconds for round.
- Return type: