flwr-nightly 1.8.0.dev20240315__py3-none-any.whl → 1.15.0.dev20250115__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 +135 -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 +304 -23
- 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 +2 -2
- flwr/proto/node_pb2.pyi +1 -4
- 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 -9
- flwr/server/compat/driver_client_proxy.py +25 -59
- 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 +220 -81
- flwr/server/driver/inmemory_driver.py +183 -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 +361 -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 +156 -13
- 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 +569 -0
- flwr/server/superlink/linkstate/linkstate.py +376 -0
- flwr/server/superlink/{state/state_factory.py → linkstate/linkstate_factory.py} +19 -10
- flwr/server/superlink/linkstate/sqlite_linkstate.py +1196 -0
- flwr/server/superlink/linkstate/utils.py +399 -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 +40 -45
- 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 +404 -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.dev20240315.dist-info → flwr_nightly-1.15.0.dev20250115.dist-info}/METADATA +33 -26
- flwr_nightly-1.15.0.dev20250115.dist-info/RECORD +328 -0
- flwr_nightly-1.15.0.dev20250115.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.dev20240315.dist-info/RECORD +0 -211
- flwr_nightly-1.8.0.dev20240315.dist-info/entry_points.txt +0 -9
- {flwr_nightly-1.8.0.dev20240315.dist-info → flwr_nightly-1.15.0.dev20250115.dist-info}/LICENSE +0 -0
- {flwr_nightly-1.8.0.dev20240315.dist-info → flwr_nightly-1.15.0.dev20250115.dist-info}/WHEEL +0 -0
@@ -0,0 +1,65 @@
|
|
1
|
+
# Copyright 2024 Flower Labs GmbH. All Rights Reserved.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
# ==============================================================================
|
15
|
+
"""SuperLink utilities."""
|
16
|
+
|
17
|
+
|
18
|
+
from typing import Union
|
19
|
+
|
20
|
+
import grpc
|
21
|
+
|
22
|
+
from flwr.common.constant import Status, SubStatus
|
23
|
+
from flwr.common.typing import RunStatus
|
24
|
+
from flwr.server.superlink.linkstate import LinkState
|
25
|
+
|
26
|
+
_STATUS_TO_MSG = {
|
27
|
+
Status.PENDING: "Run is pending.",
|
28
|
+
Status.STARTING: "Run is starting.",
|
29
|
+
Status.RUNNING: "Run is running.",
|
30
|
+
Status.FINISHED: "Run is finished.",
|
31
|
+
}
|
32
|
+
|
33
|
+
|
34
|
+
def check_abort(
|
35
|
+
run_id: int,
|
36
|
+
abort_status_list: list[str],
|
37
|
+
state: LinkState,
|
38
|
+
) -> Union[str, None]:
|
39
|
+
"""Check if the status of the provided `run_id` is in `abort_status_list`."""
|
40
|
+
run_status: RunStatus = state.get_run_status({run_id})[run_id]
|
41
|
+
|
42
|
+
if run_status.status in abort_status_list:
|
43
|
+
msg = _STATUS_TO_MSG[run_status.status]
|
44
|
+
if run_status.sub_status == SubStatus.STOPPED:
|
45
|
+
msg += " Stopped by user."
|
46
|
+
return msg
|
47
|
+
|
48
|
+
return None
|
49
|
+
|
50
|
+
|
51
|
+
def abort_grpc_context(msg: Union[str, None], context: grpc.ServicerContext) -> None:
|
52
|
+
"""Abort context with statuscode PERMISSION_DENIED if `msg` is not None."""
|
53
|
+
if msg is not None:
|
54
|
+
context.abort(grpc.StatusCode.PERMISSION_DENIED, msg)
|
55
|
+
|
56
|
+
|
57
|
+
def abort_if(
|
58
|
+
run_id: int,
|
59
|
+
abort_status_list: list[str],
|
60
|
+
state: LinkState,
|
61
|
+
context: grpc.ServicerContext,
|
62
|
+
) -> None:
|
63
|
+
"""Abort context if status of the provided `run_id` is in `abort_status_list`."""
|
64
|
+
msg = check_abort(run_id, abort_status_list, state)
|
65
|
+
abort_grpc_context(msg, context)
|
flwr/server/typing.py
CHANGED
@@ -20,6 +20,8 @@ from typing import Callable
|
|
20
20
|
from flwr.common import Context
|
21
21
|
|
22
22
|
from .driver import Driver
|
23
|
+
from .serverapp_components import ServerAppComponents
|
23
24
|
|
24
25
|
ServerAppCallable = Callable[[Driver, Context], None]
|
25
26
|
Workflow = Callable[[Driver, Context], None]
|
27
|
+
ServerFn = Callable[[Context], ServerAppComponents]
|
flwr/server/utils/__init__.py
CHANGED
flwr/server/utils/tensorboard.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.
|
@@ -18,7 +18,7 @@
|
|
18
18
|
import os
|
19
19
|
from datetime import datetime
|
20
20
|
from logging import WARN
|
21
|
-
from typing import Callable,
|
21
|
+
from typing import Callable, Optional, Union, cast
|
22
22
|
|
23
23
|
from flwr.common import EvaluateRes, Scalar
|
24
24
|
from flwr.common.logger import log
|
@@ -92,9 +92,9 @@ def tensorboard(logdir: str) -> Callable[[Strategy], Strategy]:
|
|
92
92
|
def aggregate_evaluate(
|
93
93
|
self,
|
94
94
|
server_round: int,
|
95
|
-
results:
|
96
|
-
failures:
|
97
|
-
) ->
|
95
|
+
results: list[tuple[ClientProxy, EvaluateRes]],
|
96
|
+
failures: list[Union[tuple[ClientProxy, EvaluateRes], BaseException]],
|
97
|
+
) -> tuple[Optional[float], dict[str, Scalar]]:
|
98
98
|
"""Hooks into aggregate_evaluate for TensorBoard logging purpose."""
|
99
99
|
# Execute decorated function and extract results for logging
|
100
100
|
# They will be returned at the end of this function but also
|
flwr/server/utils/validator.py
CHANGED
@@ -15,13 +15,15 @@
|
|
15
15
|
"""Validators."""
|
16
16
|
|
17
17
|
|
18
|
-
|
18
|
+
import time
|
19
|
+
from typing import Union
|
19
20
|
|
21
|
+
from flwr.common.constant import SUPERLINK_NODE_ID
|
20
22
|
from flwr.proto.task_pb2 import TaskIns, TaskRes # pylint: disable=E0611
|
21
23
|
|
22
24
|
|
23
25
|
# pylint: disable-next=too-many-branches,too-many-statements
|
24
|
-
def validate_task_ins_or_res(tasks_ins_res: Union[TaskIns, TaskRes]) ->
|
26
|
+
def validate_task_ins_or_res(tasks_ins_res: Union[TaskIns, TaskRes]) -> list[str]:
|
25
27
|
"""Validate a TaskIns or TaskRes."""
|
26
28
|
validation_errors = []
|
27
29
|
|
@@ -31,43 +33,49 @@ def validate_task_ins_or_res(tasks_ins_res: Union[TaskIns, TaskRes]) -> List[str
|
|
31
33
|
if not tasks_ins_res.HasField("task"):
|
32
34
|
validation_errors.append("`task` does not set field `task`")
|
33
35
|
|
34
|
-
# Created/delivered/TTL
|
35
|
-
if
|
36
|
-
|
36
|
+
# Created/delivered/TTL/Pushed
|
37
|
+
if (
|
38
|
+
tasks_ins_res.task.created_at < 1711497600.0
|
39
|
+
): # unix timestamp of 27 March 2024 00h:00m:00s UTC
|
40
|
+
validation_errors.append(
|
41
|
+
"`created_at` must be a float that records the unix timestamp "
|
42
|
+
"in seconds when the message was created."
|
43
|
+
)
|
37
44
|
if tasks_ins_res.task.delivered_at != "":
|
38
45
|
validation_errors.append("`delivered_at` must be an empty str")
|
39
|
-
if tasks_ins_res.task.ttl
|
40
|
-
validation_errors.append("`ttl` must be
|
46
|
+
if tasks_ins_res.task.ttl <= 0:
|
47
|
+
validation_errors.append("`ttl` must be higher than zero")
|
48
|
+
if tasks_ins_res.task.pushed_at < 1711497600.0:
|
49
|
+
# unix timestamp of 27 March 2024 00h:00m:00s UTC
|
50
|
+
validation_errors.append("`pushed_at` is not a recent timestamp")
|
51
|
+
|
52
|
+
# Verify TTL and created_at time
|
53
|
+
current_time = time.time()
|
54
|
+
if tasks_ins_res.task.created_at + tasks_ins_res.task.ttl <= current_time:
|
55
|
+
validation_errors.append("Task TTL has expired")
|
41
56
|
|
42
57
|
# TaskIns specific
|
43
58
|
if isinstance(tasks_ins_res, TaskIns):
|
44
59
|
# Task producer
|
45
60
|
if not tasks_ins_res.task.HasField("producer"):
|
46
61
|
validation_errors.append("`producer` does not set field `producer`")
|
47
|
-
if tasks_ins_res.task.producer.node_id !=
|
48
|
-
validation_errors.append("`producer.node_id` is not
|
49
|
-
if not tasks_ins_res.task.producer.anonymous:
|
50
|
-
validation_errors.append("`producer` is not anonymous")
|
62
|
+
if tasks_ins_res.task.producer.node_id != SUPERLINK_NODE_ID:
|
63
|
+
validation_errors.append(f"`producer.node_id` is not {SUPERLINK_NODE_ID}")
|
51
64
|
|
52
65
|
# Task consumer
|
53
66
|
if not tasks_ins_res.task.HasField("consumer"):
|
54
67
|
validation_errors.append("`consumer` does not set field `consumer`")
|
55
|
-
if
|
56
|
-
|
57
|
-
and tasks_ins_res.task.consumer.node_id != 0
|
58
|
-
):
|
59
|
-
validation_errors.append("anonymous consumers MUST NOT set a `node_id`")
|
60
|
-
if (
|
61
|
-
not tasks_ins_res.task.consumer.anonymous
|
62
|
-
and tasks_ins_res.task.consumer.node_id == 0
|
63
|
-
):
|
64
|
-
validation_errors.append("non-anonymous consumer MUST provide a `node_id`")
|
68
|
+
if tasks_ins_res.task.consumer.node_id == SUPERLINK_NODE_ID:
|
69
|
+
validation_errors.append("consumer MUST provide a valid `node_id`")
|
65
70
|
|
66
71
|
# Content check
|
67
72
|
if tasks_ins_res.task.task_type == "":
|
68
73
|
validation_errors.append("`task_type` MUST be set")
|
69
|
-
if not
|
70
|
-
|
74
|
+
if not (
|
75
|
+
tasks_ins_res.task.HasField("recordset")
|
76
|
+
^ tasks_ins_res.task.HasField("error")
|
77
|
+
):
|
78
|
+
validation_errors.append("Either `recordset` or `error` MUST be set")
|
71
79
|
|
72
80
|
# Ancestors
|
73
81
|
if len(tasks_ins_res.task.ancestry) != 0:
|
@@ -78,36 +86,23 @@ def validate_task_ins_or_res(tasks_ins_res: Union[TaskIns, TaskRes]) -> List[str
|
|
78
86
|
# Task producer
|
79
87
|
if not tasks_ins_res.task.HasField("producer"):
|
80
88
|
validation_errors.append("`producer` does not set field `producer`")
|
81
|
-
if
|
82
|
-
|
83
|
-
and tasks_ins_res.task.producer.node_id != 0
|
84
|
-
):
|
85
|
-
validation_errors.append("anonymous producers MUST NOT set a `node_id`")
|
86
|
-
if (
|
87
|
-
not tasks_ins_res.task.producer.anonymous
|
88
|
-
and tasks_ins_res.task.producer.node_id == 0
|
89
|
-
):
|
90
|
-
validation_errors.append("non-anonymous producer MUST provide a `node_id`")
|
89
|
+
if tasks_ins_res.task.producer.node_id == SUPERLINK_NODE_ID:
|
90
|
+
validation_errors.append("producer MUST provide a valid `node_id`")
|
91
91
|
|
92
92
|
# Task consumer
|
93
93
|
if not tasks_ins_res.task.HasField("consumer"):
|
94
94
|
validation_errors.append("`consumer` does not set field `consumer`")
|
95
|
-
if
|
96
|
-
|
97
|
-
and tasks_ins_res.task.consumer.node_id != 0
|
98
|
-
):
|
99
|
-
validation_errors.append("anonymous consumers MUST NOT set a `node_id`")
|
100
|
-
if (
|
101
|
-
not tasks_ins_res.task.consumer.anonymous
|
102
|
-
and tasks_ins_res.task.consumer.node_id == 0
|
103
|
-
):
|
104
|
-
validation_errors.append("non-anonymous consumer MUST provide a `node_id`")
|
95
|
+
if tasks_ins_res.task.consumer.node_id != SUPERLINK_NODE_ID:
|
96
|
+
validation_errors.append(f"consumer is not {SUPERLINK_NODE_ID}")
|
105
97
|
|
106
98
|
# Content check
|
107
99
|
if tasks_ins_res.task.task_type == "":
|
108
100
|
validation_errors.append("`task_type` MUST be set")
|
109
|
-
if not
|
110
|
-
|
101
|
+
if not (
|
102
|
+
tasks_ins_res.task.HasField("recordset")
|
103
|
+
^ tasks_ins_res.task.HasField("error")
|
104
|
+
):
|
105
|
+
validation_errors.append("Either `recordset` or `error` MUST be set")
|
111
106
|
|
112
107
|
# Ancestors
|
113
108
|
if len(tasks_ins_res.task.ancestry) == 0:
|
@@ -17,13 +17,23 @@
|
|
17
17
|
|
18
18
|
import io
|
19
19
|
import timeit
|
20
|
-
from logging import INFO
|
21
|
-
from typing import Optional, cast
|
20
|
+
from logging import INFO, WARN
|
21
|
+
from typing import Optional, Union, cast
|
22
22
|
|
23
23
|
import flwr.common.recordset_compat as compat
|
24
|
-
from flwr.common import
|
24
|
+
from flwr.common import (
|
25
|
+
Code,
|
26
|
+
ConfigsRecord,
|
27
|
+
Context,
|
28
|
+
EvaluateRes,
|
29
|
+
FitRes,
|
30
|
+
GetParametersIns,
|
31
|
+
ParametersRecord,
|
32
|
+
log,
|
33
|
+
)
|
25
34
|
from flwr.common.constant import MessageType, MessageTypeLegacy
|
26
35
|
|
36
|
+
from ..client_proxy import ClientProxy
|
27
37
|
from ..compat.app_utils import start_update_client_manager_thread
|
28
38
|
from ..compat.legacy_context import LegacyContext
|
29
39
|
from ..driver import Driver
|
@@ -88,7 +98,12 @@ class DefaultWorkflow:
|
|
88
98
|
hist = context.history
|
89
99
|
log(INFO, "")
|
90
100
|
log(INFO, "[SUMMARY]")
|
91
|
-
log(
|
101
|
+
log(
|
102
|
+
INFO,
|
103
|
+
"Run finished %s round(s) in %.2fs",
|
104
|
+
context.config.num_rounds,
|
105
|
+
elapsed,
|
106
|
+
)
|
92
107
|
for idx, line in enumerate(io.StringIO(str(hist))):
|
93
108
|
if idx == 0:
|
94
109
|
log(INFO, "%s", line.strip("\n"))
|
@@ -127,18 +142,32 @@ def default_init_params_workflow(driver: Driver, context: Context) -> None:
|
|
127
142
|
message_type=MessageTypeLegacy.GET_PARAMETERS,
|
128
143
|
dst_node_id=random_client.node_id,
|
129
144
|
group_id="0",
|
130
|
-
ttl="",
|
131
145
|
)
|
132
146
|
]
|
133
147
|
)
|
134
|
-
log(INFO, "Received initial parameters from one random client")
|
135
148
|
msg = list(messages)[0]
|
136
|
-
|
149
|
+
|
150
|
+
if (
|
151
|
+
msg.has_content()
|
152
|
+
and compat._extract_status_from_recordset( # pylint: disable=W0212
|
153
|
+
"getparametersres", msg.content
|
154
|
+
).code
|
155
|
+
== Code.OK
|
156
|
+
):
|
157
|
+
log(INFO, "Received initial parameters from one random client")
|
158
|
+
paramsrecord = next(iter(msg.content.parameters_records.values()))
|
159
|
+
else:
|
160
|
+
log(
|
161
|
+
WARN,
|
162
|
+
"Failed to receive initial parameters from the client."
|
163
|
+
" Empty initial parameters will be used.",
|
164
|
+
)
|
165
|
+
paramsrecord = ParametersRecord()
|
137
166
|
|
138
167
|
context.state.parameters_records[MAIN_PARAMS_RECORD] = paramsrecord
|
139
168
|
|
140
169
|
# Evaluate initial parameters
|
141
|
-
log(INFO, "
|
170
|
+
log(INFO, "Starting evaluation of initial global parameters")
|
142
171
|
parameters = compat.parametersrecord_to_parameters(paramsrecord, keep_input=True)
|
143
172
|
res = context.strategy.evaluate(0, parameters=parameters)
|
144
173
|
if res is not None:
|
@@ -150,6 +179,8 @@ def default_init_params_workflow(driver: Driver, context: Context) -> None:
|
|
150
179
|
)
|
151
180
|
context.history.add_loss_centralized(server_round=0, loss=res[0])
|
152
181
|
context.history.add_metrics_centralized(server_round=0, metrics=res[1])
|
182
|
+
else:
|
183
|
+
log(INFO, "Evaluation returned no results (`None`)")
|
153
184
|
|
154
185
|
|
155
186
|
def default_centralized_evaluation_workflow(_: Driver, context: Context) -> None:
|
@@ -226,7 +257,6 @@ def default_fit_workflow( # pylint: disable=R0914
|
|
226
257
|
message_type=MessageType.TRAIN,
|
227
258
|
dst_node_id=proxy.node_id,
|
228
259
|
group_id=str(current_round),
|
229
|
-
ttl="",
|
230
260
|
)
|
231
261
|
for proxy, fitins in client_instructions
|
232
262
|
]
|
@@ -246,14 +276,20 @@ def default_fit_workflow( # pylint: disable=R0914
|
|
246
276
|
)
|
247
277
|
|
248
278
|
# Aggregate training results
|
249
|
-
results = [
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
279
|
+
results: list[tuple[ClientProxy, FitRes]] = []
|
280
|
+
failures: list[Union[tuple[ClientProxy, FitRes], BaseException]] = []
|
281
|
+
for msg in messages:
|
282
|
+
if msg.has_content():
|
283
|
+
proxy = node_id_to_proxy[msg.metadata.src_node_id]
|
284
|
+
fitres = compat.recordset_to_fitres(msg.content, False)
|
285
|
+
if fitres.status.code == Code.OK:
|
286
|
+
results.append((proxy, fitres))
|
287
|
+
else:
|
288
|
+
failures.append((proxy, fitres))
|
289
|
+
else:
|
290
|
+
failures.append(Exception(msg.error))
|
291
|
+
|
292
|
+
aggregated_result = context.strategy.aggregate_fit(current_round, results, failures)
|
257
293
|
parameters_aggregated, metrics_aggregated = aggregated_result
|
258
294
|
|
259
295
|
# Update the parameters and write history
|
@@ -267,6 +303,7 @@ def default_fit_workflow( # pylint: disable=R0914
|
|
267
303
|
)
|
268
304
|
|
269
305
|
|
306
|
+
# pylint: disable-next=R0914
|
270
307
|
def default_evaluate_workflow(driver: Driver, context: Context) -> None:
|
271
308
|
"""Execute the default workflow for a single evaluate round."""
|
272
309
|
if not isinstance(context, LegacyContext):
|
@@ -306,7 +343,6 @@ def default_evaluate_workflow(driver: Driver, context: Context) -> None:
|
|
306
343
|
message_type=MessageType.EVALUATE,
|
307
344
|
dst_node_id=proxy.node_id,
|
308
345
|
group_id=str(current_round),
|
309
|
-
ttl="",
|
310
346
|
)
|
311
347
|
for proxy, evalins in client_instructions
|
312
348
|
]
|
@@ -326,14 +362,22 @@ def default_evaluate_workflow(driver: Driver, context: Context) -> None:
|
|
326
362
|
)
|
327
363
|
|
328
364
|
# Aggregate the evaluation results
|
329
|
-
results = [
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
365
|
+
results: list[tuple[ClientProxy, EvaluateRes]] = []
|
366
|
+
failures: list[Union[tuple[ClientProxy, EvaluateRes], BaseException]] = []
|
367
|
+
for msg in messages:
|
368
|
+
if msg.has_content():
|
369
|
+
proxy = node_id_to_proxy[msg.metadata.src_node_id]
|
370
|
+
evalres = compat.recordset_to_evaluateres(msg.content)
|
371
|
+
if evalres.status.code == Code.OK:
|
372
|
+
results.append((proxy, evalres))
|
373
|
+
else:
|
374
|
+
failures.append((proxy, evalres))
|
375
|
+
else:
|
376
|
+
failures.append(Exception(msg.error))
|
377
|
+
|
378
|
+
aggregated_result = context.strategy.aggregate_evaluate(
|
379
|
+
current_round, results, failures
|
380
|
+
)
|
337
381
|
|
338
382
|
loss_aggregated, metrics_aggregated = aggregated_result
|
339
383
|
|
@@ -35,6 +35,7 @@ class SecAggWorkflow(SecAggPlusWorkflow):
|
|
35
35
|
contributions to compute the weighted average of model parameters.
|
36
36
|
|
37
37
|
The protocol involves four main stages:
|
38
|
+
|
38
39
|
- 'setup': Send SecAgg configuration to clients and collect their public keys.
|
39
40
|
- 'share keys': Broadcast public keys among clients and collect encrypted secret
|
40
41
|
key shares.
|
@@ -18,7 +18,7 @@
|
|
18
18
|
import random
|
19
19
|
from dataclasses import dataclass, field
|
20
20
|
from logging import DEBUG, ERROR, INFO, WARN
|
21
|
-
from typing import
|
21
|
+
from typing import Optional, Union, cast
|
22
22
|
|
23
23
|
import flwr.common.recordset_compat as compat
|
24
24
|
from flwr.common import (
|
@@ -65,22 +65,23 @@ from ..constant import Key as WorkflowKey
|
|
65
65
|
class WorkflowState: # pylint: disable=R0902
|
66
66
|
"""The state of the SecAgg+ protocol."""
|
67
67
|
|
68
|
-
nid_to_proxies:
|
69
|
-
nid_to_fitins:
|
70
|
-
sampled_node_ids:
|
71
|
-
active_node_ids:
|
68
|
+
nid_to_proxies: dict[int, ClientProxy] = field(default_factory=dict)
|
69
|
+
nid_to_fitins: dict[int, RecordSet] = field(default_factory=dict)
|
70
|
+
sampled_node_ids: set[int] = field(default_factory=set)
|
71
|
+
active_node_ids: set[int] = field(default_factory=set)
|
72
72
|
num_shares: int = 0
|
73
73
|
threshold: int = 0
|
74
74
|
clipping_range: float = 0.0
|
75
75
|
quantization_range: int = 0
|
76
76
|
mod_range: int = 0
|
77
77
|
max_weight: float = 0.0
|
78
|
-
nid_to_neighbours:
|
79
|
-
nid_to_publickeys:
|
80
|
-
forward_srcs:
|
81
|
-
forward_ciphertexts:
|
78
|
+
nid_to_neighbours: dict[int, set[int]] = field(default_factory=dict)
|
79
|
+
nid_to_publickeys: dict[int, list[bytes]] = field(default_factory=dict)
|
80
|
+
forward_srcs: dict[int, list[int]] = field(default_factory=dict)
|
81
|
+
forward_ciphertexts: dict[int, list[bytes]] = field(default_factory=dict)
|
82
82
|
aggregate_ndarrays: NDArrays = field(default_factory=list)
|
83
|
-
legacy_results:
|
83
|
+
legacy_results: list[tuple[ClientProxy, FitRes]] = field(default_factory=list)
|
84
|
+
failures: list[Exception] = field(default_factory=list)
|
84
85
|
|
85
86
|
|
86
87
|
class SecAggPlusWorkflow:
|
@@ -98,6 +99,7 @@ class SecAggPlusWorkflow:
|
|
98
99
|
contributions to compute the weighted average of model parameters.
|
99
100
|
|
100
101
|
The protocol involves four main stages:
|
102
|
+
|
101
103
|
- 'setup': Send SecAgg+ configuration to clients and collect their public keys.
|
102
104
|
- 'share keys': Broadcast public keys among clients and collect encrypted secret
|
103
105
|
key shares.
|
@@ -373,7 +375,6 @@ class SecAggPlusWorkflow:
|
|
373
375
|
message_type=MessageType.TRAIN,
|
374
376
|
dst_node_id=nid,
|
375
377
|
group_id=str(cfg[WorkflowKey.CURRENT_ROUND]),
|
376
|
-
ttl="",
|
377
378
|
)
|
378
379
|
|
379
380
|
log(
|
@@ -395,6 +396,7 @@ class SecAggPlusWorkflow:
|
|
395
396
|
|
396
397
|
for msg in msgs:
|
397
398
|
if msg.has_error():
|
399
|
+
state.failures.append(Exception(msg.error))
|
398
400
|
continue
|
399
401
|
key_dict = msg.content.configs_records[RECORD_KEY_CONFIGS]
|
400
402
|
node_id = msg.metadata.src_node_id
|
@@ -421,7 +423,6 @@ class SecAggPlusWorkflow:
|
|
421
423
|
message_type=MessageType.TRAIN,
|
422
424
|
dst_node_id=nid,
|
423
425
|
group_id=str(cfg[WorkflowKey.CURRENT_ROUND]),
|
424
|
-
ttl="",
|
425
426
|
)
|
426
427
|
|
427
428
|
# Broadcast public keys to clients and receive secret key shares
|
@@ -443,20 +444,23 @@ class SecAggPlusWorkflow:
|
|
443
444
|
)
|
444
445
|
|
445
446
|
# Build forward packet list dictionary
|
446
|
-
srcs:
|
447
|
-
dsts:
|
448
|
-
ciphertexts:
|
449
|
-
fwd_ciphertexts:
|
447
|
+
srcs: list[int] = []
|
448
|
+
dsts: list[int] = []
|
449
|
+
ciphertexts: list[bytes] = []
|
450
|
+
fwd_ciphertexts: dict[int, list[bytes]] = {
|
450
451
|
nid: [] for nid in state.active_node_ids
|
451
452
|
} # dest node ID -> list of ciphertexts
|
452
|
-
fwd_srcs:
|
453
|
+
fwd_srcs: dict[int, list[int]] = {
|
453
454
|
nid: [] for nid in state.active_node_ids
|
454
455
|
} # dest node ID -> list of src node IDs
|
455
456
|
for msg in msgs:
|
457
|
+
if msg.has_error():
|
458
|
+
state.failures.append(Exception(msg.error))
|
459
|
+
continue
|
456
460
|
node_id = msg.metadata.src_node_id
|
457
461
|
res_dict = msg.content.configs_records[RECORD_KEY_CONFIGS]
|
458
|
-
dst_lst = cast(
|
459
|
-
ctxt_lst = cast(
|
462
|
+
dst_lst = cast(list[int], res_dict[Key.DESTINATION_LIST])
|
463
|
+
ctxt_lst = cast(list[bytes], res_dict[Key.CIPHERTEXT_LIST])
|
460
464
|
srcs += [node_id] * len(dst_lst)
|
461
465
|
dsts += dst_lst
|
462
466
|
ciphertexts += ctxt_lst
|
@@ -492,7 +496,6 @@ class SecAggPlusWorkflow:
|
|
492
496
|
message_type=MessageType.TRAIN,
|
493
497
|
dst_node_id=nid,
|
494
498
|
group_id=str(cfg[WorkflowKey.CURRENT_ROUND]),
|
495
|
-
ttl="",
|
496
499
|
)
|
497
500
|
|
498
501
|
log(
|
@@ -518,8 +521,11 @@ class SecAggPlusWorkflow:
|
|
518
521
|
# Sum collected masked vectors and compute active/dead node IDs
|
519
522
|
masked_vector = None
|
520
523
|
for msg in msgs:
|
524
|
+
if msg.has_error():
|
525
|
+
state.failures.append(Exception(msg.error))
|
526
|
+
continue
|
521
527
|
res_dict = msg.content.configs_records[RECORD_KEY_CONFIGS]
|
522
|
-
bytes_list = cast(
|
528
|
+
bytes_list = cast(list[bytes], res_dict[Key.MASKED_PARAMETERS])
|
523
529
|
client_masked_vec = [bytes_to_ndarray(b) for b in bytes_list]
|
524
530
|
if masked_vector is None:
|
525
531
|
masked_vector = client_masked_vec
|
@@ -531,6 +537,9 @@ class SecAggPlusWorkflow:
|
|
531
537
|
|
532
538
|
# Backward compatibility with Strategy
|
533
539
|
for msg in msgs:
|
540
|
+
if msg.has_error():
|
541
|
+
state.failures.append(Exception(msg.error))
|
542
|
+
continue
|
534
543
|
fitres = compat.recordset_to_fitres(msg.content, True)
|
535
544
|
proxy = state.nid_to_proxies[msg.metadata.src_node_id]
|
536
545
|
state.legacy_results.append((proxy, fitres))
|
@@ -563,7 +572,6 @@ class SecAggPlusWorkflow:
|
|
563
572
|
message_type=MessageType.TRAIN,
|
564
573
|
dst_node_id=nid,
|
565
574
|
group_id=str(current_round),
|
566
|
-
ttl="",
|
567
575
|
)
|
568
576
|
|
569
577
|
log(
|
@@ -584,13 +592,16 @@ class SecAggPlusWorkflow:
|
|
584
592
|
)
|
585
593
|
|
586
594
|
# Build collected shares dict
|
587
|
-
collected_shares_dict:
|
595
|
+
collected_shares_dict: dict[int, list[bytes]] = {}
|
588
596
|
for nid in state.sampled_node_ids:
|
589
597
|
collected_shares_dict[nid] = []
|
590
598
|
for msg in msgs:
|
599
|
+
if msg.has_error():
|
600
|
+
state.failures.append(Exception(msg.error))
|
601
|
+
continue
|
591
602
|
res_dict = msg.content.configs_records[RECORD_KEY_CONFIGS]
|
592
|
-
nids = cast(
|
593
|
-
shares = cast(
|
603
|
+
nids = cast(list[int], res_dict[Key.NODE_ID_LIST])
|
604
|
+
shares = cast(list[bytes], res_dict[Key.SHARE_LIST])
|
594
605
|
for owner_nid, share in zip(nids, shares):
|
595
606
|
collected_shares_dict[owner_nid].append(share)
|
596
607
|
|
@@ -656,9 +667,11 @@ class SecAggPlusWorkflow:
|
|
656
667
|
INFO,
|
657
668
|
"aggregate_fit: received %s results and %s failures",
|
658
669
|
len(results),
|
659
|
-
|
670
|
+
len(state.failures),
|
671
|
+
)
|
672
|
+
aggregated_result = context.strategy.aggregate_fit(
|
673
|
+
current_round, results, state.failures # type: ignore
|
660
674
|
)
|
661
|
-
aggregated_result = context.strategy.aggregate_fit(current_round, results, [])
|
662
675
|
parameters_aggregated, metrics_aggregated = aggregated_result
|
663
676
|
|
664
677
|
# Update the parameters and write history
|
flwr/simulation/__init__.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.
|
@@ -17,18 +17,20 @@
|
|
17
17
|
|
18
18
|
import importlib
|
19
19
|
|
20
|
-
from flwr.simulation.
|
20
|
+
from flwr.simulation.app import run_simulation_process
|
21
|
+
from flwr.simulation.run_simulation import run_simulation
|
22
|
+
from flwr.simulation.simulationio_connection import SimulationIoConnection
|
21
23
|
|
22
24
|
is_ray_installed = importlib.util.find_spec("ray") is not None
|
23
25
|
|
24
26
|
if is_ray_installed:
|
25
|
-
from flwr.simulation.
|
27
|
+
from flwr.simulation.legacy_app import start_simulation
|
26
28
|
else:
|
27
29
|
RAY_IMPORT_ERROR: str = """Unable to import module `ray`.
|
28
30
|
|
29
31
|
To install the necessary dependencies, install `flwr` with the `simulation` extra:
|
30
32
|
|
31
|
-
pip install -U flwr[
|
33
|
+
pip install -U "flwr[simulation]"
|
32
34
|
"""
|
33
35
|
|
34
36
|
def start_simulation(*args, **kwargs): # type: ignore
|
@@ -36,4 +38,9 @@ To install the necessary dependencies, install `flwr` with the `simulation` extr
|
|
36
38
|
raise ImportError(RAY_IMPORT_ERROR)
|
37
39
|
|
38
40
|
|
39
|
-
__all__ = [
|
41
|
+
__all__ = [
|
42
|
+
"SimulationIoConnection",
|
43
|
+
"run_simulation",
|
44
|
+
"run_simulation_process",
|
45
|
+
"start_simulation",
|
46
|
+
]
|