fl4health.clients.clipping_client module¶
- class NumpyClippingClient(data_path, metrics, device, loss_meter_type=LossMeterType.AVERAGE, checkpoint_and_state_module=None, reporters=None, progress_bar=False, client_name=None)[source]¶
Bases:
BasicClient
- __init__(data_path, metrics, device, loss_meter_type=LossMeterType.AVERAGE, checkpoint_and_state_module=None, reporters=None, progress_bar=False, client_name=None)[source]¶
Client that clips updates being sent to the server where noise is added. Used to obtain Client Level Differential Privacy in FL setting.
- Parameters:
data_path (Path) – path to the data to be used to load the data for client-side training
metrics (Sequence[Metric]) – Metrics to be computed based on the labels and predictions of the client model
device (torch.device) – Device indicator for where to send the model, batches, labels etc. Often ‘cpu’ or ‘cuda’
loss_meter_type (LossMeterType, optional) – Type of meter used to track and compute the losses over each batch. Defaults to LossMeterType.AVERAGE.
checkpoint_and_state_module (ClientCheckpointAndStateModule | None, optional) – A module meant to handle both checkpointing and state saving. The module, and its underlying model and state checkpointing components will determine when and how to do checkpointing during client-side training. No checkpointing (state or model) is done if not provided. Defaults to None.
reporters (Sequence[BaseReporter] | None, optional) – A sequence of FL4Health reporters which the client should send data to. Defaults to None.
progress_bar (bool, optional) – Whether or not to display a progress bar during client training and validation. Uses tqdm. Defaults to False
client_name (str | None, optional) – An optional client name that uniquely identifies a client. If not passed, a hash is randomly generated. Client state will use this as part of its state file name. Defaults to None.
- get_parameter_exchanger(config)[source]¶
Returns Full Parameter Exchangers. Subclasses that require custom Parameter Exchangers can override this.
- Parameters:
config (Config) – The config from server.
- Returns:
Used to exchange parameters between server and client.
- Return type:
- get_parameters(config)[source]¶
This function performs clipping through compute_weight_update_and_clip and stores the clipping bit as the last entry in the NDArrays
- set_parameters(parameters, config, fitting_round)[source]¶
This function assumes that the parameters being passed contain model parameters followed by the last entry of the list being the new clipping bound. They are unpacked for the clients to use in training. If it is called in the first fitting round, we assume the full model is being initialized and use the FullParameterExchanger() to set all model weights.
- Parameters:
parameters (NDArrays) – Parameters have information about model state to be added to the relevant client model and also the clipping bound.
config (Config) – The config is sent by the FL server to allow for customization in the function if desired.
fitting_round (bool) – Boolean that indicates whether the current federated learning round is a fitting round or an evaluation round. This is used to help determine which parameter exchange should be used for pulling parameters. A full parameter exchanger is used if the current federated learning round is the very first fitting round.
- Return type: