DifferentialPrivacyClientSideAdaptiveClipping¶
- class DifferentialPrivacyClientSideAdaptiveClipping(strategy: Strategy, noise_multiplier: float, num_sampled_clients: int, initial_clipping_norm: float = 0.1, target_clipped_quantile: float = 0.5, clip_norm_lr: float = 0.2, clipped_count_stddev: float | None = None)[source]¶
- Bases : - DifferentialPrivacyAdaptiveBase- Strategy wrapper for central DP with client-side adaptive clipping. - Use adaptiveclipping_mod modifier at the client side. - In comparison to DifferentialPrivacyServerSideAdaptiveClipping, which performs clipping on the server-side, DifferentialPrivacyClientSideAdaptiveClipping expects clipping to happen on the client-side, usually by using the built-in adaptiveclipping_mod. - Paramètres:
- strategy (Strategy) – The strategy to which DP functionalities will be added by this wrapper. 
- noise_multiplier (float) – The noise multiplier for the Gaussian mechanism for model updates. 
- num_sampled_clients (int) – The number of clients that are sampled on each round. 
- initial_clipping_norm (float) – The initial value of clipping norm. Defaults to 0.1. Andrew et al. recommends to set to 0.1. 
- target_clipped_quantile (float) – The desired quantile of updates which should be clipped. Defaults to 0.5. 
- clip_norm_lr (float) – The learning rate for the clipping norm adaptation. Defaults to 0.2. Andrew et al. recommends to set to 0.2. 
- clipped_count_stddev (float) – The stddev of the noise added to the count of updates currently below the estimate. Andrew et al. recommends to set to expected_num_records/20 
 
 - Exemples - Create a strategy: - strategy = fl.serverapp.FedAvg(...) - Wrap the strategy with the DifferentialPrivacyClientSideAdaptiveClipping wrapper: - dp_strategy = DifferentialPrivacyClientSideAdaptiveClipping( strategy, cfg.noise_multiplier, cfg.num_sampled_clients, ... ) - On the client, add the adaptiveclipping_mod to the client-side mods: - app = fl.client.ClientApp(mods=[adaptiveclipping_mod]) - Methods - aggregate_evaluate(server_round, replies)- Aggregate MetricRecords in the received Messages. - aggregate_train(server_round, replies)- Aggregate ArrayRecords and MetricRecords in the received Messages. - configure_evaluate(server_round, arrays, ...)- Configure the next round of federated evaluation. - configure_train(server_round, arrays, ...)- Configure the next round of training. - start(grid, initial_arrays[, num_rounds, ...])- Execute the federated learning strategy. - summary()- Log summary configuration of the strategy. - aggregate_evaluate(server_round: int, replies: Iterable[Message]) MetricRecord | None¶
- Aggregate MetricRecords in the received Messages. 
 - aggregate_train(server_round: int, replies: Iterable[Message]) tuple[ArrayRecord | None, MetricRecord | None][source]¶
- Aggregate ArrayRecords and MetricRecords in the received Messages. 
 - configure_evaluate(server_round: int, arrays: ArrayRecord, config: ConfigRecord, grid: Grid) Iterable[Message]¶
- Configure the next round of federated evaluation. 
 - configure_train(server_round: int, arrays: ArrayRecord, config: ConfigRecord, grid: Grid) Iterable[Message][source]¶
- Configure the next round of training. 
 - start(grid: Grid, initial_arrays: ArrayRecord, num_rounds: int = 3, timeout: float = 3600, train_config: ConfigRecord | None = None, evaluate_config: ConfigRecord | None = None, evaluate_fn: Callable[[int, ArrayRecord], MetricRecord | None] | None = None) Result¶
- Execute the federated learning strategy. - Runs the complete federated learning workflow for the specified number of rounds, including training, evaluation, and optional centralized evaluation. - Paramètres:
- grid (Grid) – The Grid instance used to send/receive Messages from nodes executing a ClientApp. 
- initial_arrays (ArrayRecord) – Initial model parameters (arrays) to be used for federated learning. 
- num_rounds (int (default: 3)) – Number of federated learning rounds to execute. 
- timeout (float (default: 3600)) – Timeout in seconds for waiting for node responses. 
- train_config (ConfigRecord, optional) – Configuration to be sent to nodes during training rounds. If unset, an empty ConfigRecord will be used. 
- evaluate_config (ConfigRecord, optional) – Configuration to be sent to nodes during evaluation rounds. If unset, an empty ConfigRecord will be used. 
- evaluate_fn (Callable[[int, ArrayRecord], Optional[MetricRecord]], optional) – Optional function for centralized evaluation of the global model. Takes server round number and array record, returns a MetricRecord or None. If provided, will be called before the first round and after each round. Defaults to None. 
 
- Renvoie:
- Results containing final model arrays and also training metrics, evaluation metrics and global evaluation metrics (if provided) from all rounds. 
- Type renvoyé:
- Results