flwr-nightly 1.8.0.dev20240314__py3-none-any.whl → 1.15.0.dev20250114__py3-none-any.whl
Sign up to get free protection for your applications and to get access to all the features.
- flwr/cli/app.py +16 -2
- flwr/cli/build.py +181 -0
- flwr/cli/cli_user_auth_interceptor.py +90 -0
- flwr/cli/config_utils.py +343 -0
- flwr/cli/example.py +4 -1
- flwr/cli/install.py +253 -0
- flwr/cli/log.py +182 -0
- flwr/{server/superlink/state → cli/login}/__init__.py +4 -10
- flwr/cli/login/login.py +88 -0
- flwr/cli/ls.py +327 -0
- flwr/cli/new/__init__.py +1 -0
- flwr/cli/new/new.py +210 -66
- flwr/cli/new/templates/app/.gitignore.tpl +163 -0
- flwr/cli/new/templates/app/LICENSE.tpl +202 -0
- flwr/cli/new/templates/app/README.baseline.md.tpl +127 -0
- flwr/cli/new/templates/app/README.flowertune.md.tpl +66 -0
- flwr/cli/new/templates/app/README.md.tpl +16 -32
- flwr/cli/new/templates/app/code/__init__.baseline.py.tpl +1 -0
- flwr/cli/new/templates/app/code/__init__.py.tpl +1 -1
- flwr/cli/new/templates/app/code/client.baseline.py.tpl +58 -0
- flwr/cli/new/templates/app/code/client.huggingface.py.tpl +55 -0
- flwr/cli/new/templates/app/code/client.jax.py.tpl +50 -0
- flwr/cli/new/templates/app/code/client.mlx.py.tpl +73 -0
- flwr/cli/new/templates/app/code/client.numpy.py.tpl +7 -7
- flwr/cli/new/templates/app/code/client.pytorch.py.tpl +30 -21
- flwr/cli/new/templates/app/code/client.sklearn.py.tpl +63 -0
- flwr/cli/new/templates/app/code/client.tensorflow.py.tpl +57 -1
- flwr/cli/new/templates/app/code/dataset.baseline.py.tpl +36 -0
- flwr/cli/new/templates/app/code/flwr_tune/__init__.py +15 -0
- flwr/cli/new/templates/app/code/flwr_tune/client_app.py.tpl +126 -0
- flwr/cli/new/templates/app/code/flwr_tune/dataset.py.tpl +87 -0
- flwr/cli/new/templates/app/code/flwr_tune/models.py.tpl +78 -0
- flwr/cli/new/templates/app/code/flwr_tune/server_app.py.tpl +94 -0
- flwr/cli/new/templates/app/code/flwr_tune/strategy.py.tpl +83 -0
- flwr/cli/new/templates/app/code/model.baseline.py.tpl +80 -0
- flwr/cli/new/templates/app/code/server.baseline.py.tpl +46 -0
- flwr/cli/new/templates/app/code/server.huggingface.py.tpl +38 -0
- flwr/cli/new/templates/app/code/server.jax.py.tpl +26 -0
- flwr/cli/new/templates/app/code/server.mlx.py.tpl +31 -0
- flwr/cli/new/templates/app/code/server.numpy.py.tpl +22 -9
- flwr/cli/new/templates/app/code/server.pytorch.py.tpl +21 -18
- flwr/cli/new/templates/app/code/server.sklearn.py.tpl +36 -0
- flwr/cli/new/templates/app/code/server.tensorflow.py.tpl +29 -1
- flwr/cli/new/templates/app/code/strategy.baseline.py.tpl +1 -0
- flwr/cli/new/templates/app/code/task.huggingface.py.tpl +102 -0
- flwr/cli/new/templates/app/code/task.jax.py.tpl +57 -0
- flwr/cli/new/templates/app/code/task.mlx.py.tpl +102 -0
- flwr/cli/new/templates/app/code/task.numpy.py.tpl +7 -0
- flwr/cli/new/templates/app/code/task.pytorch.py.tpl +29 -24
- flwr/cli/new/templates/app/code/task.sklearn.py.tpl +67 -0
- flwr/cli/new/templates/app/code/task.tensorflow.py.tpl +53 -0
- flwr/cli/new/templates/app/code/utils.baseline.py.tpl +1 -0
- flwr/cli/new/templates/app/pyproject.baseline.toml.tpl +138 -0
- flwr/cli/new/templates/app/pyproject.flowertune.toml.tpl +68 -0
- flwr/cli/new/templates/app/pyproject.huggingface.toml.tpl +46 -0
- flwr/cli/new/templates/app/pyproject.jax.toml.tpl +35 -0
- flwr/cli/new/templates/app/pyproject.mlx.toml.tpl +39 -0
- flwr/cli/new/templates/app/pyproject.numpy.toml.tpl +25 -12
- flwr/cli/new/templates/app/pyproject.pytorch.toml.tpl +29 -14
- flwr/cli/new/templates/app/pyproject.sklearn.toml.tpl +35 -0
- flwr/cli/new/templates/app/pyproject.tensorflow.toml.tpl +29 -14
- flwr/cli/run/__init__.py +1 -0
- flwr/cli/run/run.py +212 -34
- flwr/cli/stop.py +130 -0
- flwr/cli/utils.py +240 -5
- flwr/client/__init__.py +3 -2
- flwr/client/app.py +432 -255
- flwr/client/client.py +1 -11
- flwr/client/client_app.py +74 -13
- flwr/client/clientapp/__init__.py +22 -0
- flwr/client/clientapp/app.py +259 -0
- flwr/client/clientapp/clientappio_servicer.py +244 -0
- flwr/client/clientapp/utils.py +115 -0
- flwr/client/dpfedavg_numpy_client.py +7 -8
- flwr/client/grpc_adapter_client/__init__.py +15 -0
- flwr/client/grpc_adapter_client/connection.py +98 -0
- flwr/client/grpc_client/connection.py +21 -7
- flwr/client/grpc_rere_client/__init__.py +1 -1
- flwr/client/grpc_rere_client/client_interceptor.py +176 -0
- flwr/client/grpc_rere_client/connection.py +163 -56
- flwr/client/grpc_rere_client/grpc_adapter.py +167 -0
- flwr/client/heartbeat.py +74 -0
- flwr/client/message_handler/__init__.py +1 -1
- flwr/client/message_handler/message_handler.py +10 -11
- flwr/client/mod/__init__.py +5 -5
- flwr/client/mod/centraldp_mods.py +4 -2
- flwr/client/mod/comms_mods.py +5 -4
- flwr/client/mod/localdp_mod.py +10 -5
- flwr/client/mod/secure_aggregation/__init__.py +1 -1
- flwr/client/mod/secure_aggregation/secaggplus_mod.py +26 -26
- flwr/client/mod/utils.py +2 -4
- flwr/client/nodestate/__init__.py +26 -0
- flwr/client/nodestate/in_memory_nodestate.py +38 -0
- flwr/client/nodestate/nodestate.py +31 -0
- flwr/client/nodestate/nodestate_factory.py +38 -0
- flwr/client/numpy_client.py +8 -31
- flwr/client/rest_client/__init__.py +1 -1
- flwr/client/rest_client/connection.py +199 -176
- flwr/client/run_info_store.py +112 -0
- flwr/client/supernode/__init__.py +24 -0
- flwr/client/supernode/app.py +321 -0
- flwr/client/typing.py +1 -0
- flwr/common/__init__.py +17 -11
- flwr/common/address.py +47 -3
- flwr/common/args.py +153 -0
- flwr/common/auth_plugin/__init__.py +24 -0
- flwr/common/auth_plugin/auth_plugin.py +121 -0
- flwr/common/config.py +243 -0
- flwr/common/constant.py +132 -1
- flwr/common/context.py +32 -2
- flwr/common/date.py +22 -4
- flwr/common/differential_privacy.py +2 -2
- flwr/common/dp.py +2 -4
- flwr/common/exit_handlers.py +3 -3
- flwr/common/grpc.py +164 -5
- flwr/common/logger.py +230 -12
- flwr/common/message.py +191 -106
- flwr/common/object_ref.py +179 -44
- flwr/common/pyproject.py +1 -0
- flwr/common/record/__init__.py +2 -1
- flwr/common/record/configsrecord.py +58 -18
- flwr/common/record/metricsrecord.py +57 -17
- flwr/common/record/parametersrecord.py +88 -20
- flwr/common/record/recordset.py +153 -30
- flwr/common/record/typeddict.py +30 -55
- flwr/common/recordset_compat.py +31 -12
- flwr/common/retry_invoker.py +123 -30
- flwr/common/secure_aggregation/__init__.py +1 -1
- flwr/common/secure_aggregation/crypto/__init__.py +1 -1
- flwr/common/secure_aggregation/crypto/shamir.py +11 -11
- flwr/common/secure_aggregation/crypto/symmetric_encryption.py +68 -4
- flwr/common/secure_aggregation/ndarrays_arithmetic.py +17 -17
- flwr/common/secure_aggregation/quantization.py +8 -8
- flwr/common/secure_aggregation/secaggplus_constants.py +1 -1
- flwr/common/secure_aggregation/secaggplus_utils.py +10 -12
- flwr/common/serde.py +298 -19
- flwr/common/telemetry.py +65 -29
- flwr/common/typing.py +120 -19
- flwr/common/version.py +17 -3
- flwr/proto/clientappio_pb2.py +45 -0
- flwr/proto/clientappio_pb2.pyi +132 -0
- flwr/proto/clientappio_pb2_grpc.py +135 -0
- flwr/proto/clientappio_pb2_grpc.pyi +53 -0
- flwr/proto/exec_pb2.py +62 -0
- flwr/proto/exec_pb2.pyi +212 -0
- flwr/proto/exec_pb2_grpc.py +237 -0
- flwr/proto/exec_pb2_grpc.pyi +93 -0
- flwr/proto/fab_pb2.py +31 -0
- flwr/proto/fab_pb2.pyi +65 -0
- flwr/proto/fab_pb2_grpc.py +4 -0
- flwr/proto/fab_pb2_grpc.pyi +4 -0
- flwr/proto/fleet_pb2.py +42 -23
- flwr/proto/fleet_pb2.pyi +123 -1
- flwr/proto/fleet_pb2_grpc.py +170 -0
- flwr/proto/fleet_pb2_grpc.pyi +61 -0
- flwr/proto/grpcadapter_pb2.py +32 -0
- flwr/proto/grpcadapter_pb2.pyi +43 -0
- flwr/proto/grpcadapter_pb2_grpc.py +66 -0
- flwr/proto/grpcadapter_pb2_grpc.pyi +24 -0
- flwr/proto/log_pb2.py +29 -0
- flwr/proto/log_pb2.pyi +39 -0
- flwr/proto/log_pb2_grpc.py +4 -0
- flwr/proto/log_pb2_grpc.pyi +4 -0
- flwr/proto/message_pb2.py +41 -0
- flwr/proto/message_pb2.pyi +128 -0
- flwr/proto/message_pb2_grpc.py +4 -0
- flwr/proto/message_pb2_grpc.pyi +4 -0
- flwr/proto/node_pb2.py +1 -1
- flwr/proto/recordset_pb2.py +35 -33
- flwr/proto/recordset_pb2.pyi +40 -14
- flwr/proto/run_pb2.py +64 -0
- flwr/proto/run_pb2.pyi +268 -0
- flwr/proto/run_pb2_grpc.py +4 -0
- flwr/proto/run_pb2_grpc.pyi +4 -0
- flwr/proto/serverappio_pb2.py +52 -0
- flwr/proto/{driver_pb2.pyi → serverappio_pb2.pyi} +62 -20
- flwr/proto/serverappio_pb2_grpc.py +410 -0
- flwr/proto/serverappio_pb2_grpc.pyi +160 -0
- flwr/proto/simulationio_pb2.py +38 -0
- flwr/proto/simulationio_pb2.pyi +65 -0
- flwr/proto/simulationio_pb2_grpc.py +239 -0
- flwr/proto/simulationio_pb2_grpc.pyi +94 -0
- flwr/proto/task_pb2.py +7 -8
- flwr/proto/task_pb2.pyi +8 -5
- flwr/proto/transport_pb2.py +8 -8
- flwr/proto/transport_pb2.pyi +9 -6
- flwr/server/__init__.py +2 -10
- flwr/server/app.py +579 -402
- flwr/server/client_manager.py +8 -6
- flwr/server/compat/app.py +6 -62
- flwr/server/compat/app_utils.py +14 -8
- flwr/server/compat/driver_client_proxy.py +25 -58
- flwr/server/compat/legacy_context.py +5 -4
- flwr/server/driver/__init__.py +2 -0
- flwr/server/driver/driver.py +36 -131
- flwr/server/driver/grpc_driver.py +217 -81
- flwr/server/driver/inmemory_driver.py +182 -0
- flwr/server/history.py +28 -29
- flwr/server/run_serverapp.py +15 -126
- flwr/server/server.py +50 -44
- flwr/server/server_app.py +59 -10
- flwr/server/serverapp/__init__.py +22 -0
- flwr/server/serverapp/app.py +256 -0
- flwr/server/serverapp_components.py +52 -0
- flwr/server/strategy/__init__.py +2 -2
- flwr/server/strategy/aggregate.py +37 -23
- flwr/server/strategy/bulyan.py +9 -9
- flwr/server/strategy/dp_adaptive_clipping.py +25 -25
- flwr/server/strategy/dp_fixed_clipping.py +23 -22
- flwr/server/strategy/dpfedavg_adaptive.py +8 -8
- flwr/server/strategy/dpfedavg_fixed.py +13 -12
- flwr/server/strategy/fault_tolerant_fedavg.py +11 -11
- flwr/server/strategy/fedadagrad.py +9 -9
- flwr/server/strategy/fedadam.py +20 -10
- flwr/server/strategy/fedavg.py +16 -16
- flwr/server/strategy/fedavg_android.py +17 -17
- flwr/server/strategy/fedavgm.py +9 -9
- flwr/server/strategy/fedmedian.py +5 -5
- flwr/server/strategy/fedopt.py +6 -6
- flwr/server/strategy/fedprox.py +7 -7
- flwr/server/strategy/fedtrimmedavg.py +8 -8
- flwr/server/strategy/fedxgb_bagging.py +12 -12
- flwr/server/strategy/fedxgb_cyclic.py +10 -10
- flwr/server/strategy/fedxgb_nn_avg.py +6 -6
- flwr/server/strategy/fedyogi.py +9 -9
- flwr/server/strategy/krum.py +9 -9
- flwr/server/strategy/qfedavg.py +16 -16
- flwr/server/strategy/strategy.py +10 -10
- flwr/server/superlink/driver/__init__.py +2 -2
- flwr/server/superlink/driver/serverappio_grpc.py +61 -0
- flwr/server/superlink/driver/serverappio_servicer.py +363 -0
- flwr/server/superlink/ffs/__init__.py +24 -0
- flwr/server/superlink/ffs/disk_ffs.py +108 -0
- flwr/server/superlink/ffs/ffs.py +79 -0
- flwr/server/superlink/ffs/ffs_factory.py +47 -0
- flwr/server/superlink/fleet/__init__.py +1 -1
- flwr/server/superlink/fleet/grpc_adapter/__init__.py +15 -0
- flwr/server/superlink/fleet/grpc_adapter/grpc_adapter_servicer.py +162 -0
- flwr/server/superlink/fleet/grpc_bidi/__init__.py +1 -1
- flwr/server/superlink/fleet/grpc_bidi/flower_service_servicer.py +4 -2
- flwr/server/superlink/fleet/grpc_bidi/grpc_bridge.py +3 -2
- flwr/server/superlink/fleet/grpc_bidi/grpc_client_proxy.py +1 -1
- flwr/server/superlink/fleet/grpc_bidi/grpc_server.py +5 -154
- flwr/server/superlink/fleet/grpc_rere/__init__.py +1 -1
- flwr/server/superlink/fleet/grpc_rere/fleet_servicer.py +120 -13
- flwr/server/superlink/fleet/grpc_rere/server_interceptor.py +228 -0
- flwr/server/superlink/fleet/message_handler/__init__.py +1 -1
- flwr/server/superlink/fleet/message_handler/message_handler.py +153 -9
- flwr/server/superlink/fleet/rest_rere/__init__.py +1 -1
- flwr/server/superlink/fleet/rest_rere/rest_api.py +119 -81
- flwr/server/superlink/fleet/vce/__init__.py +1 -0
- flwr/server/superlink/fleet/vce/backend/__init__.py +4 -4
- flwr/server/superlink/fleet/vce/backend/backend.py +8 -9
- flwr/server/superlink/fleet/vce/backend/raybackend.py +87 -68
- flwr/server/superlink/fleet/vce/vce_api.py +208 -146
- flwr/server/superlink/linkstate/__init__.py +28 -0
- flwr/server/superlink/linkstate/in_memory_linkstate.py +581 -0
- flwr/server/superlink/linkstate/linkstate.py +389 -0
- flwr/server/superlink/{state/state_factory.py → linkstate/linkstate_factory.py} +19 -10
- flwr/server/superlink/linkstate/sqlite_linkstate.py +1236 -0
- flwr/server/superlink/linkstate/utils.py +389 -0
- flwr/server/superlink/simulation/__init__.py +15 -0
- flwr/server/superlink/simulation/simulationio_grpc.py +65 -0
- flwr/server/superlink/simulation/simulationio_servicer.py +186 -0
- flwr/server/superlink/utils.py +65 -0
- flwr/server/typing.py +2 -0
- flwr/server/utils/__init__.py +1 -1
- flwr/server/utils/tensorboard.py +5 -5
- flwr/server/utils/validator.py +31 -11
- flwr/server/workflow/default_workflows.py +70 -26
- flwr/server/workflow/secure_aggregation/secagg_workflow.py +1 -0
- flwr/server/workflow/secure_aggregation/secaggplus_workflow.py +40 -27
- flwr/simulation/__init__.py +12 -5
- flwr/simulation/app.py +247 -315
- flwr/simulation/legacy_app.py +402 -0
- flwr/simulation/ray_transport/__init__.py +1 -1
- flwr/simulation/ray_transport/ray_actor.py +42 -67
- flwr/simulation/ray_transport/ray_client_proxy.py +37 -17
- flwr/simulation/ray_transport/utils.py +1 -0
- flwr/simulation/run_simulation.py +306 -163
- flwr/simulation/simulationio_connection.py +89 -0
- flwr/superexec/__init__.py +15 -0
- flwr/superexec/app.py +59 -0
- flwr/superexec/deployment.py +188 -0
- flwr/superexec/exec_grpc.py +80 -0
- flwr/superexec/exec_servicer.py +231 -0
- flwr/superexec/exec_user_auth_interceptor.py +101 -0
- flwr/superexec/executor.py +96 -0
- flwr/superexec/simulation.py +124 -0
- {flwr_nightly-1.8.0.dev20240314.dist-info → flwr_nightly-1.15.0.dev20250114.dist-info}/METADATA +33 -26
- flwr_nightly-1.15.0.dev20250114.dist-info/RECORD +328 -0
- flwr_nightly-1.15.0.dev20250114.dist-info/entry_points.txt +12 -0
- flwr/cli/flower_toml.py +0 -140
- flwr/cli/new/templates/app/flower.toml.tpl +0 -13
- flwr/cli/new/templates/app/requirements.numpy.txt.tpl +0 -2
- flwr/cli/new/templates/app/requirements.pytorch.txt.tpl +0 -4
- flwr/cli/new/templates/app/requirements.tensorflow.txt.tpl +0 -4
- flwr/client/node_state.py +0 -48
- flwr/client/node_state_tests.py +0 -65
- flwr/proto/driver_pb2.py +0 -44
- flwr/proto/driver_pb2_grpc.py +0 -169
- flwr/proto/driver_pb2_grpc.pyi +0 -66
- flwr/server/superlink/driver/driver_grpc.py +0 -54
- flwr/server/superlink/driver/driver_servicer.py +0 -129
- flwr/server/superlink/state/in_memory_state.py +0 -230
- flwr/server/superlink/state/sqlite_state.py +0 -630
- flwr/server/superlink/state/state.py +0 -154
- flwr_nightly-1.8.0.dev20240314.dist-info/RECORD +0 -211
- flwr_nightly-1.8.0.dev20240314.dist-info/entry_points.txt +0 -9
- {flwr_nightly-1.8.0.dev20240314.dist-info → flwr_nightly-1.15.0.dev20250114.dist-info}/LICENSE +0 -0
- {flwr_nightly-1.8.0.dev20240314.dist-info → flwr_nightly-1.15.0.dev20250114.dist-info}/WHEEL +0 -0
@@ -20,7 +20,7 @@ Paper (Andrew et al.): https://arxiv.org/abs/1905.03871
|
|
20
20
|
|
21
21
|
import math
|
22
22
|
from logging import INFO, WARNING
|
23
|
-
from typing import
|
23
|
+
from typing import Optional, Union
|
24
24
|
|
25
25
|
import numpy as np
|
26
26
|
|
@@ -88,7 +88,7 @@ class DifferentialPrivacyServerSideAdaptiveClipping(Strategy):
|
|
88
88
|
>>> )
|
89
89
|
"""
|
90
90
|
|
91
|
-
# pylint: disable=too-many-arguments,too-many-instance-attributes
|
91
|
+
# pylint: disable=too-many-arguments,too-many-instance-attributes,too-many-positional-arguments
|
92
92
|
def __init__(
|
93
93
|
self,
|
94
94
|
strategy: Strategy,
|
@@ -156,14 +156,14 @@ class DifferentialPrivacyServerSideAdaptiveClipping(Strategy):
|
|
156
156
|
|
157
157
|
def configure_fit(
|
158
158
|
self, server_round: int, parameters: Parameters, client_manager: ClientManager
|
159
|
-
) ->
|
159
|
+
) -> list[tuple[ClientProxy, FitIns]]:
|
160
160
|
"""Configure the next round of training."""
|
161
161
|
self.current_round_params = parameters_to_ndarrays(parameters)
|
162
162
|
return self.strategy.configure_fit(server_round, parameters, client_manager)
|
163
163
|
|
164
164
|
def configure_evaluate(
|
165
165
|
self, server_round: int, parameters: Parameters, client_manager: ClientManager
|
166
|
-
) ->
|
166
|
+
) -> list[tuple[ClientProxy, EvaluateIns]]:
|
167
167
|
"""Configure the next round of evaluation."""
|
168
168
|
return self.strategy.configure_evaluate(
|
169
169
|
server_round, parameters, client_manager
|
@@ -172,9 +172,9 @@ class DifferentialPrivacyServerSideAdaptiveClipping(Strategy):
|
|
172
172
|
def aggregate_fit(
|
173
173
|
self,
|
174
174
|
server_round: int,
|
175
|
-
results:
|
176
|
-
failures:
|
177
|
-
) ->
|
175
|
+
results: list[tuple[ClientProxy, FitRes]],
|
176
|
+
failures: list[Union[tuple[ClientProxy, FitRes], BaseException]],
|
177
|
+
) -> tuple[Optional[Parameters], dict[str, Scalar]]:
|
178
178
|
"""Aggregate training results and update clip norms."""
|
179
179
|
if failures:
|
180
180
|
return None, {}
|
@@ -200,7 +200,7 @@ class DifferentialPrivacyServerSideAdaptiveClipping(Strategy):
|
|
200
200
|
|
201
201
|
log(
|
202
202
|
INFO,
|
203
|
-
"aggregate_fit: parameters are clipped by value:
|
203
|
+
"aggregate_fit: parameters are clipped by value: %.4f.",
|
204
204
|
self.clipping_norm,
|
205
205
|
)
|
206
206
|
|
@@ -234,7 +234,7 @@ class DifferentialPrivacyServerSideAdaptiveClipping(Strategy):
|
|
234
234
|
)
|
235
235
|
log(
|
236
236
|
INFO,
|
237
|
-
"aggregate_fit: central DP noise with
|
237
|
+
"aggregate_fit: central DP noise with %.4f stdev added",
|
238
238
|
compute_stdv(
|
239
239
|
self.noise_multiplier, self.clipping_norm, self.num_sampled_clients
|
240
240
|
),
|
@@ -245,15 +245,15 @@ class DifferentialPrivacyServerSideAdaptiveClipping(Strategy):
|
|
245
245
|
def aggregate_evaluate(
|
246
246
|
self,
|
247
247
|
server_round: int,
|
248
|
-
results:
|
249
|
-
failures:
|
250
|
-
) ->
|
248
|
+
results: list[tuple[ClientProxy, EvaluateRes]],
|
249
|
+
failures: list[Union[tuple[ClientProxy, EvaluateRes], BaseException]],
|
250
|
+
) -> tuple[Optional[float], dict[str, Scalar]]:
|
251
251
|
"""Aggregate evaluation losses using the given strategy."""
|
252
252
|
return self.strategy.aggregate_evaluate(server_round, results, failures)
|
253
253
|
|
254
254
|
def evaluate(
|
255
255
|
self, server_round: int, parameters: Parameters
|
256
|
-
) -> Optional[
|
256
|
+
) -> Optional[tuple[float, dict[str, Scalar]]]:
|
257
257
|
"""Evaluate model parameters using an evaluation function from the strategy."""
|
258
258
|
return self.strategy.evaluate(server_round, parameters)
|
259
259
|
|
@@ -307,7 +307,7 @@ class DifferentialPrivacyClientSideAdaptiveClipping(Strategy):
|
|
307
307
|
>>> )
|
308
308
|
"""
|
309
309
|
|
310
|
-
# pylint: disable=too-many-arguments,too-many-instance-attributes
|
310
|
+
# pylint: disable=too-many-arguments,too-many-instance-attributes,too-many-positional-arguments
|
311
311
|
def __init__(
|
312
312
|
self,
|
313
313
|
strategy: Strategy,
|
@@ -372,7 +372,7 @@ class DifferentialPrivacyClientSideAdaptiveClipping(Strategy):
|
|
372
372
|
|
373
373
|
def configure_fit(
|
374
374
|
self, server_round: int, parameters: Parameters, client_manager: ClientManager
|
375
|
-
) ->
|
375
|
+
) -> list[tuple[ClientProxy, FitIns]]:
|
376
376
|
"""Configure the next round of training."""
|
377
377
|
additional_config = {KEY_CLIPPING_NORM: self.clipping_norm}
|
378
378
|
inner_strategy_config_result = self.strategy.configure_fit(
|
@@ -385,7 +385,7 @@ class DifferentialPrivacyClientSideAdaptiveClipping(Strategy):
|
|
385
385
|
|
386
386
|
def configure_evaluate(
|
387
387
|
self, server_round: int, parameters: Parameters, client_manager: ClientManager
|
388
|
-
) ->
|
388
|
+
) -> list[tuple[ClientProxy, EvaluateIns]]:
|
389
389
|
"""Configure the next round of evaluation."""
|
390
390
|
return self.strategy.configure_evaluate(
|
391
391
|
server_round, parameters, client_manager
|
@@ -394,9 +394,9 @@ class DifferentialPrivacyClientSideAdaptiveClipping(Strategy):
|
|
394
394
|
def aggregate_fit(
|
395
395
|
self,
|
396
396
|
server_round: int,
|
397
|
-
results:
|
398
|
-
failures:
|
399
|
-
) ->
|
397
|
+
results: list[tuple[ClientProxy, FitRes]],
|
398
|
+
failures: list[Union[tuple[ClientProxy, FitRes], BaseException]],
|
399
|
+
) -> tuple[Optional[Parameters], dict[str, Scalar]]:
|
400
400
|
"""Aggregate training results and update clip norms."""
|
401
401
|
if failures:
|
402
402
|
return None, {}
|
@@ -424,7 +424,7 @@ class DifferentialPrivacyClientSideAdaptiveClipping(Strategy):
|
|
424
424
|
)
|
425
425
|
log(
|
426
426
|
INFO,
|
427
|
-
"aggregate_fit: central DP noise with
|
427
|
+
"aggregate_fit: central DP noise with %.4f stdev added",
|
428
428
|
compute_stdv(
|
429
429
|
self.noise_multiplier, self.clipping_norm, self.num_sampled_clients
|
430
430
|
),
|
@@ -432,7 +432,7 @@ class DifferentialPrivacyClientSideAdaptiveClipping(Strategy):
|
|
432
432
|
|
433
433
|
return aggregated_params, metrics
|
434
434
|
|
435
|
-
def _update_clip_norm(self, results:
|
435
|
+
def _update_clip_norm(self, results: list[tuple[ClientProxy, FitRes]]) -> None:
|
436
436
|
# Calculate the number of clients which set the norm indicator bit
|
437
437
|
norm_bit_set_count = 0
|
438
438
|
for client_proxy, fit_res in results:
|
@@ -457,14 +457,14 @@ class DifferentialPrivacyClientSideAdaptiveClipping(Strategy):
|
|
457
457
|
def aggregate_evaluate(
|
458
458
|
self,
|
459
459
|
server_round: int,
|
460
|
-
results:
|
461
|
-
failures:
|
462
|
-
) ->
|
460
|
+
results: list[tuple[ClientProxy, EvaluateRes]],
|
461
|
+
failures: list[Union[tuple[ClientProxy, EvaluateRes], BaseException]],
|
462
|
+
) -> tuple[Optional[float], dict[str, Scalar]]:
|
463
463
|
"""Aggregate evaluation losses using the given strategy."""
|
464
464
|
return self.strategy.aggregate_evaluate(server_round, results, failures)
|
465
465
|
|
466
466
|
def evaluate(
|
467
467
|
self, server_round: int, parameters: Parameters
|
468
|
-
) -> Optional[
|
468
|
+
) -> Optional[tuple[float, dict[str, Scalar]]]:
|
469
469
|
"""Evaluate model parameters using an evaluation function from the strategy."""
|
470
470
|
return self.strategy.evaluate(server_round, parameters)
|
@@ -19,7 +19,7 @@ Papers: https://arxiv.org/abs/1712.07557, https://arxiv.org/abs/1710.06963
|
|
19
19
|
|
20
20
|
|
21
21
|
from logging import INFO, WARNING
|
22
|
-
from typing import
|
22
|
+
from typing import Optional, Union
|
23
23
|
|
24
24
|
from flwr.common import (
|
25
25
|
EvaluateIns,
|
@@ -117,14 +117,14 @@ class DifferentialPrivacyServerSideFixedClipping(Strategy):
|
|
117
117
|
|
118
118
|
def configure_fit(
|
119
119
|
self, server_round: int, parameters: Parameters, client_manager: ClientManager
|
120
|
-
) ->
|
120
|
+
) -> list[tuple[ClientProxy, FitIns]]:
|
121
121
|
"""Configure the next round of training."""
|
122
122
|
self.current_round_params = parameters_to_ndarrays(parameters)
|
123
123
|
return self.strategy.configure_fit(server_round, parameters, client_manager)
|
124
124
|
|
125
125
|
def configure_evaluate(
|
126
126
|
self, server_round: int, parameters: Parameters, client_manager: ClientManager
|
127
|
-
) ->
|
127
|
+
) -> list[tuple[ClientProxy, EvaluateIns]]:
|
128
128
|
"""Configure the next round of evaluation."""
|
129
129
|
return self.strategy.configure_evaluate(
|
130
130
|
server_round, parameters, client_manager
|
@@ -133,9 +133,9 @@ class DifferentialPrivacyServerSideFixedClipping(Strategy):
|
|
133
133
|
def aggregate_fit(
|
134
134
|
self,
|
135
135
|
server_round: int,
|
136
|
-
results:
|
137
|
-
failures:
|
138
|
-
) ->
|
136
|
+
results: list[tuple[ClientProxy, FitRes]],
|
137
|
+
failures: list[Union[tuple[ClientProxy, FitRes], BaseException]],
|
138
|
+
) -> tuple[Optional[Parameters], dict[str, Scalar]]:
|
139
139
|
"""Compute the updates, clip, and pass them for aggregation.
|
140
140
|
|
141
141
|
Afterward, add noise to the aggregated parameters.
|
@@ -158,7 +158,7 @@ class DifferentialPrivacyServerSideFixedClipping(Strategy):
|
|
158
158
|
)
|
159
159
|
log(
|
160
160
|
INFO,
|
161
|
-
"aggregate_fit: parameters are clipped by value:
|
161
|
+
"aggregate_fit: parameters are clipped by value: %.4f.",
|
162
162
|
self.clipping_norm,
|
163
163
|
)
|
164
164
|
# Convert back to parameters
|
@@ -180,7 +180,7 @@ class DifferentialPrivacyServerSideFixedClipping(Strategy):
|
|
180
180
|
|
181
181
|
log(
|
182
182
|
INFO,
|
183
|
-
"aggregate_fit: central DP noise with
|
183
|
+
"aggregate_fit: central DP noise with %.4f stdev added",
|
184
184
|
compute_stdv(
|
185
185
|
self.noise_multiplier, self.clipping_norm, self.num_sampled_clients
|
186
186
|
),
|
@@ -191,15 +191,15 @@ class DifferentialPrivacyServerSideFixedClipping(Strategy):
|
|
191
191
|
def aggregate_evaluate(
|
192
192
|
self,
|
193
193
|
server_round: int,
|
194
|
-
results:
|
195
|
-
failures:
|
196
|
-
) ->
|
194
|
+
results: list[tuple[ClientProxy, EvaluateRes]],
|
195
|
+
failures: list[Union[tuple[ClientProxy, EvaluateRes], BaseException]],
|
196
|
+
) -> tuple[Optional[float], dict[str, Scalar]]:
|
197
197
|
"""Aggregate evaluation losses using the given strategy."""
|
198
198
|
return self.strategy.aggregate_evaluate(server_round, results, failures)
|
199
199
|
|
200
200
|
def evaluate(
|
201
201
|
self, server_round: int, parameters: Parameters
|
202
|
-
) -> Optional[
|
202
|
+
) -> Optional[tuple[float, dict[str, Scalar]]]:
|
203
203
|
"""Evaluate model parameters using an evaluation function from the strategy."""
|
204
204
|
return self.strategy.evaluate(server_round, parameters)
|
205
205
|
|
@@ -285,7 +285,7 @@ class DifferentialPrivacyClientSideFixedClipping(Strategy):
|
|
285
285
|
|
286
286
|
def configure_fit(
|
287
287
|
self, server_round: int, parameters: Parameters, client_manager: ClientManager
|
288
|
-
) ->
|
288
|
+
) -> list[tuple[ClientProxy, FitIns]]:
|
289
289
|
"""Configure the next round of training."""
|
290
290
|
additional_config = {KEY_CLIPPING_NORM: self.clipping_norm}
|
291
291
|
inner_strategy_config_result = self.strategy.configure_fit(
|
@@ -298,7 +298,7 @@ class DifferentialPrivacyClientSideFixedClipping(Strategy):
|
|
298
298
|
|
299
299
|
def configure_evaluate(
|
300
300
|
self, server_round: int, parameters: Parameters, client_manager: ClientManager
|
301
|
-
) ->
|
301
|
+
) -> list[tuple[ClientProxy, EvaluateIns]]:
|
302
302
|
"""Configure the next round of evaluation."""
|
303
303
|
return self.strategy.configure_evaluate(
|
304
304
|
server_round, parameters, client_manager
|
@@ -307,9 +307,9 @@ class DifferentialPrivacyClientSideFixedClipping(Strategy):
|
|
307
307
|
def aggregate_fit(
|
308
308
|
self,
|
309
309
|
server_round: int,
|
310
|
-
results:
|
311
|
-
failures:
|
312
|
-
) ->
|
310
|
+
results: list[tuple[ClientProxy, FitRes]],
|
311
|
+
failures: list[Union[tuple[ClientProxy, FitRes], BaseException]],
|
312
|
+
) -> tuple[Optional[Parameters], dict[str, Scalar]]:
|
313
313
|
"""Add noise to the aggregated parameters."""
|
314
314
|
if failures:
|
315
315
|
return None, {}
|
@@ -337,24 +337,25 @@ class DifferentialPrivacyClientSideFixedClipping(Strategy):
|
|
337
337
|
)
|
338
338
|
log(
|
339
339
|
INFO,
|
340
|
-
"aggregate_fit: central DP noise with
|
340
|
+
"aggregate_fit: central DP noise with %.4f stdev added",
|
341
341
|
compute_stdv(
|
342
342
|
self.noise_multiplier, self.clipping_norm, self.num_sampled_clients
|
343
343
|
),
|
344
344
|
)
|
345
|
+
|
345
346
|
return aggregated_params, metrics
|
346
347
|
|
347
348
|
def aggregate_evaluate(
|
348
349
|
self,
|
349
350
|
server_round: int,
|
350
|
-
results:
|
351
|
-
failures:
|
352
|
-
) ->
|
351
|
+
results: list[tuple[ClientProxy, EvaluateRes]],
|
352
|
+
failures: list[Union[tuple[ClientProxy, EvaluateRes], BaseException]],
|
353
|
+
) -> tuple[Optional[float], dict[str, Scalar]]:
|
353
354
|
"""Aggregate evaluation losses using the given strategy."""
|
354
355
|
return self.strategy.aggregate_evaluate(server_round, results, failures)
|
355
356
|
|
356
357
|
def evaluate(
|
357
358
|
self, server_round: int, parameters: Parameters
|
358
|
-
) -> Optional[
|
359
|
+
) -> Optional[tuple[float, dict[str, Scalar]]]:
|
359
360
|
"""Evaluate model parameters using an evaluation function from the strategy."""
|
360
361
|
return self.strategy.evaluate(server_round, parameters)
|
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright
|
1
|
+
# Copyright 2022 Flower Labs GmbH. All Rights Reserved.
|
2
2
|
#
|
3
3
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
4
|
# you may not use this file except in compliance with the License.
|
@@ -19,7 +19,7 @@ Paper: arxiv.org/pdf/1905.03871.pdf
|
|
19
19
|
|
20
20
|
|
21
21
|
import math
|
22
|
-
from typing import
|
22
|
+
from typing import Optional, Union
|
23
23
|
|
24
24
|
import numpy as np
|
25
25
|
|
@@ -39,7 +39,7 @@ class DPFedAvgAdaptive(DPFedAvgFixed):
|
|
39
39
|
This class is deprecated and will be removed in a future release.
|
40
40
|
"""
|
41
41
|
|
42
|
-
# pylint: disable=too-many-arguments,too-many-instance-attributes
|
42
|
+
# pylint: disable=too-many-arguments,too-many-instance-attributes,too-many-positional-arguments
|
43
43
|
def __init__(
|
44
44
|
self,
|
45
45
|
strategy: Strategy,
|
@@ -80,7 +80,7 @@ class DPFedAvgAdaptive(DPFedAvgFixed):
|
|
80
80
|
|
81
81
|
def configure_fit(
|
82
82
|
self, server_round: int, parameters: Parameters, client_manager: ClientManager
|
83
|
-
) ->
|
83
|
+
) -> list[tuple[ClientProxy, FitIns]]:
|
84
84
|
"""Configure the next round of training."""
|
85
85
|
additional_config = {"dpfedavg_adaptive_clip_enabled": True}
|
86
86
|
|
@@ -93,7 +93,7 @@ class DPFedAvgAdaptive(DPFedAvgFixed):
|
|
93
93
|
|
94
94
|
return client_instructions
|
95
95
|
|
96
|
-
def _update_clip_norm(self, results:
|
96
|
+
def _update_clip_norm(self, results: list[tuple[ClientProxy, FitRes]]) -> None:
|
97
97
|
# Calculating number of clients which set the norm indicator bit
|
98
98
|
norm_bit_set_count = 0
|
99
99
|
for client_proxy, fit_res in results:
|
@@ -118,9 +118,9 @@ class DPFedAvgAdaptive(DPFedAvgFixed):
|
|
118
118
|
def aggregate_fit(
|
119
119
|
self,
|
120
120
|
server_round: int,
|
121
|
-
results:
|
122
|
-
failures:
|
123
|
-
) ->
|
121
|
+
results: list[tuple[ClientProxy, FitRes]],
|
122
|
+
failures: list[Union[tuple[ClientProxy, FitRes], BaseException]],
|
123
|
+
) -> tuple[Optional[Parameters], dict[str, Scalar]]:
|
124
124
|
"""Aggregate training results as in DPFedAvgFixed and update clip norms."""
|
125
125
|
if failures:
|
126
126
|
return None, {}
|
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright
|
1
|
+
# Copyright 2022 Flower Labs GmbH. All Rights Reserved.
|
2
2
|
#
|
3
3
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
4
|
# you may not use this file except in compliance with the License.
|
@@ -17,7 +17,8 @@
|
|
17
17
|
Paper: arxiv.org/pdf/1710.06963.pdf
|
18
18
|
"""
|
19
19
|
|
20
|
-
|
20
|
+
|
21
|
+
from typing import Optional, Union
|
21
22
|
|
22
23
|
from flwr.common import EvaluateIns, EvaluateRes, FitIns, FitRes, Parameters, Scalar
|
23
24
|
from flwr.common.dp import add_gaussian_noise
|
@@ -36,7 +37,7 @@ class DPFedAvgFixed(Strategy):
|
|
36
37
|
This class is deprecated and will be removed in a future release.
|
37
38
|
"""
|
38
39
|
|
39
|
-
# pylint: disable=too-many-arguments,too-many-instance-attributes
|
40
|
+
# pylint: disable=too-many-arguments,too-many-instance-attributes,too-many-positional-arguments
|
40
41
|
def __init__(
|
41
42
|
self,
|
42
43
|
strategy: Strategy,
|
@@ -79,7 +80,7 @@ class DPFedAvgFixed(Strategy):
|
|
79
80
|
|
80
81
|
def configure_fit(
|
81
82
|
self, server_round: int, parameters: Parameters, client_manager: ClientManager
|
82
|
-
) ->
|
83
|
+
) -> list[tuple[ClientProxy, FitIns]]:
|
83
84
|
"""Configure the next round of training incorporating Differential Privacy (DP).
|
84
85
|
|
85
86
|
Configuration of the next training round includes information related to DP,
|
@@ -119,7 +120,7 @@ class DPFedAvgFixed(Strategy):
|
|
119
120
|
|
120
121
|
def configure_evaluate(
|
121
122
|
self, server_round: int, parameters: Parameters, client_manager: ClientManager
|
122
|
-
) ->
|
123
|
+
) -> list[tuple[ClientProxy, EvaluateIns]]:
|
123
124
|
"""Configure the next round of evaluation using the specified strategy.
|
124
125
|
|
125
126
|
Parameters
|
@@ -147,9 +148,9 @@ class DPFedAvgFixed(Strategy):
|
|
147
148
|
def aggregate_fit(
|
148
149
|
self,
|
149
150
|
server_round: int,
|
150
|
-
results:
|
151
|
-
failures:
|
152
|
-
) ->
|
151
|
+
results: list[tuple[ClientProxy, FitRes]],
|
152
|
+
failures: list[Union[tuple[ClientProxy, FitRes], BaseException]],
|
153
|
+
) -> tuple[Optional[Parameters], dict[str, Scalar]]:
|
153
154
|
"""Aggregate training results using unweighted aggregation."""
|
154
155
|
if failures:
|
155
156
|
return None, {}
|
@@ -168,14 +169,14 @@ class DPFedAvgFixed(Strategy):
|
|
168
169
|
def aggregate_evaluate(
|
169
170
|
self,
|
170
171
|
server_round: int,
|
171
|
-
results:
|
172
|
-
failures:
|
173
|
-
) ->
|
172
|
+
results: list[tuple[ClientProxy, EvaluateRes]],
|
173
|
+
failures: list[Union[tuple[ClientProxy, EvaluateRes], BaseException]],
|
174
|
+
) -> tuple[Optional[float], dict[str, Scalar]]:
|
174
175
|
"""Aggregate evaluation losses using the given strategy."""
|
175
176
|
return self.strategy.aggregate_evaluate(server_round, results, failures)
|
176
177
|
|
177
178
|
def evaluate(
|
178
179
|
self, server_round: int, parameters: Parameters
|
179
|
-
) -> Optional[
|
180
|
+
) -> Optional[tuple[float, dict[str, Scalar]]]:
|
180
181
|
"""Evaluate model parameters using an evaluation function from the strategy."""
|
181
182
|
return self.strategy.evaluate(server_round, parameters)
|
@@ -16,7 +16,7 @@
|
|
16
16
|
|
17
17
|
|
18
18
|
from logging import WARNING
|
19
|
-
from typing import Callable,
|
19
|
+
from typing import Callable, Optional, Union
|
20
20
|
|
21
21
|
from flwr.common import (
|
22
22
|
EvaluateRes,
|
@@ -49,12 +49,12 @@ class FaultTolerantFedAvg(FedAvg):
|
|
49
49
|
min_available_clients: int = 1,
|
50
50
|
evaluate_fn: Optional[
|
51
51
|
Callable[
|
52
|
-
[int, NDArrays,
|
53
|
-
Optional[
|
52
|
+
[int, NDArrays, dict[str, Scalar]],
|
53
|
+
Optional[tuple[float, dict[str, Scalar]]],
|
54
54
|
]
|
55
55
|
] = None,
|
56
|
-
on_fit_config_fn: Optional[Callable[[int],
|
57
|
-
on_evaluate_config_fn: Optional[Callable[[int],
|
56
|
+
on_fit_config_fn: Optional[Callable[[int], dict[str, Scalar]]] = None,
|
57
|
+
on_evaluate_config_fn: Optional[Callable[[int], dict[str, Scalar]]] = None,
|
58
58
|
min_completion_rate_fit: float = 0.5,
|
59
59
|
min_completion_rate_evaluate: float = 0.5,
|
60
60
|
initial_parameters: Optional[Parameters] = None,
|
@@ -85,9 +85,9 @@ class FaultTolerantFedAvg(FedAvg):
|
|
85
85
|
def aggregate_fit(
|
86
86
|
self,
|
87
87
|
server_round: int,
|
88
|
-
results:
|
89
|
-
failures:
|
90
|
-
) ->
|
88
|
+
results: list[tuple[ClientProxy, FitRes]],
|
89
|
+
failures: list[Union[tuple[ClientProxy, FitRes], BaseException]],
|
90
|
+
) -> tuple[Optional[Parameters], dict[str, Scalar]]:
|
91
91
|
"""Aggregate fit results using weighted average."""
|
92
92
|
if not results:
|
93
93
|
return None, {}
|
@@ -117,9 +117,9 @@ class FaultTolerantFedAvg(FedAvg):
|
|
117
117
|
def aggregate_evaluate(
|
118
118
|
self,
|
119
119
|
server_round: int,
|
120
|
-
results:
|
121
|
-
failures:
|
122
|
-
) ->
|
120
|
+
results: list[tuple[ClientProxy, EvaluateRes]],
|
121
|
+
failures: list[Union[tuple[ClientProxy, EvaluateRes], BaseException]],
|
122
|
+
) -> tuple[Optional[float], dict[str, Scalar]]:
|
123
123
|
"""Aggregate evaluation losses using weighted average."""
|
124
124
|
if not results:
|
125
125
|
return None, {}
|
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright
|
1
|
+
# Copyright 2021 Flower Labs GmbH. All Rights Reserved.
|
2
2
|
#
|
3
3
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
4
|
# you may not use this file except in compliance with the License.
|
@@ -20,7 +20,7 @@ Paper: arxiv.org/abs/2003.00295
|
|
20
20
|
"""
|
21
21
|
|
22
22
|
|
23
|
-
from typing import Callable,
|
23
|
+
from typing import Callable, Optional, Union
|
24
24
|
|
25
25
|
import numpy as np
|
26
26
|
|
@@ -89,12 +89,12 @@ class FedAdagrad(FedOpt):
|
|
89
89
|
min_available_clients: int = 2,
|
90
90
|
evaluate_fn: Optional[
|
91
91
|
Callable[
|
92
|
-
[int, NDArrays,
|
93
|
-
Optional[
|
92
|
+
[int, NDArrays, dict[str, Scalar]],
|
93
|
+
Optional[tuple[float, dict[str, Scalar]]],
|
94
94
|
]
|
95
95
|
] = None,
|
96
|
-
on_fit_config_fn: Optional[Callable[[int],
|
97
|
-
on_evaluate_config_fn: Optional[Callable[[int],
|
96
|
+
on_fit_config_fn: Optional[Callable[[int], dict[str, Scalar]]] = None,
|
97
|
+
on_evaluate_config_fn: Optional[Callable[[int], dict[str, Scalar]]] = None,
|
98
98
|
fit_metrics_aggregation_fn: Optional[MetricsAggregationFn] = None,
|
99
99
|
evaluate_metrics_aggregation_fn: Optional[MetricsAggregationFn] = None,
|
100
100
|
accept_failures: bool = True,
|
@@ -131,9 +131,9 @@ class FedAdagrad(FedOpt):
|
|
131
131
|
def aggregate_fit(
|
132
132
|
self,
|
133
133
|
server_round: int,
|
134
|
-
results:
|
135
|
-
failures:
|
136
|
-
) ->
|
134
|
+
results: list[tuple[ClientProxy, FitRes]],
|
135
|
+
failures: list[Union[tuple[ClientProxy, FitRes], BaseException]],
|
136
|
+
) -> tuple[Optional[Parameters], dict[str, Scalar]]:
|
137
137
|
"""Aggregate fit results using weighted average."""
|
138
138
|
fedavg_parameters_aggregated, metrics_aggregated = super().aggregate_fit(
|
139
139
|
server_round=server_round, results=results, failures=failures
|
flwr/server/strategy/fedadam.py
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright
|
1
|
+
# Copyright 2021 Flower Labs GmbH. All Rights Reserved.
|
2
2
|
#
|
3
3
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
4
|
# you may not use this file except in compliance with the License.
|
@@ -20,7 +20,7 @@ Paper: arxiv.org/abs/2003.00295
|
|
20
20
|
"""
|
21
21
|
|
22
22
|
|
23
|
-
from typing import Callable,
|
23
|
+
from typing import Callable, Optional, Union
|
24
24
|
|
25
25
|
import numpy as np
|
26
26
|
|
@@ -93,12 +93,12 @@ class FedAdam(FedOpt):
|
|
93
93
|
min_available_clients: int = 2,
|
94
94
|
evaluate_fn: Optional[
|
95
95
|
Callable[
|
96
|
-
[int, NDArrays,
|
97
|
-
Optional[
|
96
|
+
[int, NDArrays, dict[str, Scalar]],
|
97
|
+
Optional[tuple[float, dict[str, Scalar]]],
|
98
98
|
]
|
99
99
|
] = None,
|
100
|
-
on_fit_config_fn: Optional[Callable[[int],
|
101
|
-
on_evaluate_config_fn: Optional[Callable[[int],
|
100
|
+
on_fit_config_fn: Optional[Callable[[int], dict[str, Scalar]]] = None,
|
101
|
+
on_evaluate_config_fn: Optional[Callable[[int], dict[str, Scalar]]] = None,
|
102
102
|
accept_failures: bool = True,
|
103
103
|
initial_parameters: Parameters,
|
104
104
|
fit_metrics_aggregation_fn: Optional[MetricsAggregationFn] = None,
|
@@ -137,9 +137,9 @@ class FedAdam(FedOpt):
|
|
137
137
|
def aggregate_fit(
|
138
138
|
self,
|
139
139
|
server_round: int,
|
140
|
-
results:
|
141
|
-
failures:
|
142
|
-
) ->
|
140
|
+
results: list[tuple[ClientProxy, FitRes]],
|
141
|
+
failures: list[Union[tuple[ClientProxy, FitRes], BaseException]],
|
142
|
+
) -> tuple[Optional[Parameters], dict[str, Scalar]]:
|
143
143
|
"""Aggregate fit results using weighted average."""
|
144
144
|
fedavg_parameters_aggregated, metrics_aggregated = super().aggregate_fit(
|
145
145
|
server_round=server_round, results=results, failures=failures
|
@@ -170,8 +170,18 @@ class FedAdam(FedOpt):
|
|
170
170
|
for x, y in zip(self.v_t, delta_t)
|
171
171
|
]
|
172
172
|
|
173
|
+
# Compute the bias-corrected learning rate, `eta_norm` for improving convergence
|
174
|
+
# in the early rounds of FL training. This `eta_norm` is `\alpha_t` in Kingma &
|
175
|
+
# Ba, 2014 (http://arxiv.org/abs/1412.6980) "Adam: A Method for Stochastic
|
176
|
+
# Optimization" in the formula line right before Section 2.1.
|
177
|
+
eta_norm = (
|
178
|
+
self.eta
|
179
|
+
* np.sqrt(1 - np.power(self.beta_2, server_round + 1.0))
|
180
|
+
/ (1 - np.power(self.beta_1, server_round + 1.0))
|
181
|
+
)
|
182
|
+
|
173
183
|
new_weights = [
|
174
|
-
x +
|
184
|
+
x + eta_norm * y / (np.sqrt(z) + self.tau)
|
175
185
|
for x, y, z in zip(self.current_weights, self.m_t, self.v_t)
|
176
186
|
]
|
177
187
|
|