fl4health.clients.instance_level_dp_client module¶
- class InstanceLevelDpClient(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 for Instance/Record level Differentially Private Federated Averaging
- 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 Falseclient_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.
- setup_client(config)[source]¶
Performs the same flow as BasicClient to setup a client. This functionality straps on a processing of two configuration variables
self.clipping_bound
andself.noise_multiplier
. The last step is to do some processing of the model and optimizers with Opacus to make them DP compatible and to setup the privacy engine used for privacy accounting. This is done with thesetup_opacus_objects
function.- Parameters:
config (Config) – Configurations sent by the server to allow for customization of this functions behavior.
- Return type:
- setup_opacus_objects(config)[source]¶
Validates and potentially fixes the PyTorch model of the client to be compatible with Opacus and privacy mechanisms, sets up the privacy engine of Opacus using the model, optimizer, dataloaders etc. for DP training
- Parameters:
config (Config) – Configurations sent by the server to allow for customization of this functions behavior.
- Return type: