flwr-nightly 1.8.0.dev20240315__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.dev20240315.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.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.dev20250114.dist-info}/LICENSE +0 -0
- {flwr_nightly-1.8.0.dev20240315.dist-info → flwr_nightly-1.15.0.dev20250114.dist-info}/WHEEL +0 -0
@@ -0,0 +1,256 @@
|
|
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
|
+
"""Flower ServerApp process."""
|
16
|
+
|
17
|
+
|
18
|
+
import argparse
|
19
|
+
import sys
|
20
|
+
from logging import DEBUG, ERROR, INFO
|
21
|
+
from pathlib import Path
|
22
|
+
from queue import Queue
|
23
|
+
from time import sleep
|
24
|
+
from typing import Optional
|
25
|
+
|
26
|
+
from flwr.cli.config_utils import get_fab_metadata
|
27
|
+
from flwr.cli.install import install_from_fab
|
28
|
+
from flwr.cli.utils import get_sha256_hash
|
29
|
+
from flwr.common.args import add_args_flwr_app_common
|
30
|
+
from flwr.common.config import (
|
31
|
+
get_flwr_dir,
|
32
|
+
get_fused_config_from_dir,
|
33
|
+
get_project_config,
|
34
|
+
get_project_dir,
|
35
|
+
)
|
36
|
+
from flwr.common.constant import (
|
37
|
+
SERVERAPPIO_API_DEFAULT_CLIENT_ADDRESS,
|
38
|
+
Status,
|
39
|
+
SubStatus,
|
40
|
+
)
|
41
|
+
from flwr.common.logger import (
|
42
|
+
log,
|
43
|
+
mirror_output_to_queue,
|
44
|
+
restore_output,
|
45
|
+
start_log_uploader,
|
46
|
+
stop_log_uploader,
|
47
|
+
)
|
48
|
+
from flwr.common.serde import (
|
49
|
+
context_from_proto,
|
50
|
+
context_to_proto,
|
51
|
+
fab_from_proto,
|
52
|
+
run_from_proto,
|
53
|
+
run_status_to_proto,
|
54
|
+
)
|
55
|
+
from flwr.common.telemetry import EventType, event
|
56
|
+
from flwr.common.typing import RunNotRunningException, RunStatus
|
57
|
+
from flwr.proto.run_pb2 import UpdateRunStatusRequest # pylint: disable=E0611
|
58
|
+
from flwr.proto.serverappio_pb2 import ( # pylint: disable=E0611
|
59
|
+
PullServerAppInputsRequest,
|
60
|
+
PullServerAppInputsResponse,
|
61
|
+
PushServerAppOutputsRequest,
|
62
|
+
)
|
63
|
+
from flwr.server.driver.grpc_driver import GrpcDriver
|
64
|
+
from flwr.server.run_serverapp import run as run_
|
65
|
+
|
66
|
+
|
67
|
+
def flwr_serverapp() -> None:
|
68
|
+
"""Run process-isolated Flower ServerApp."""
|
69
|
+
# Capture stdout/stderr
|
70
|
+
log_queue: Queue[Optional[str]] = Queue()
|
71
|
+
mirror_output_to_queue(log_queue)
|
72
|
+
|
73
|
+
args = _parse_args_run_flwr_serverapp().parse_args()
|
74
|
+
|
75
|
+
log(INFO, "Starting Flower ServerApp")
|
76
|
+
|
77
|
+
if not args.insecure:
|
78
|
+
log(
|
79
|
+
ERROR,
|
80
|
+
"`flwr-serverapp` does not support TLS yet. "
|
81
|
+
"Please use the '--insecure' flag.",
|
82
|
+
)
|
83
|
+
sys.exit(1)
|
84
|
+
|
85
|
+
log(
|
86
|
+
DEBUG,
|
87
|
+
"Starting isolated `ServerApp` connected to SuperLink's ServerAppIo API at %s",
|
88
|
+
args.serverappio_api_address,
|
89
|
+
)
|
90
|
+
run_serverapp(
|
91
|
+
serverappio_api_address=args.serverappio_api_address,
|
92
|
+
log_queue=log_queue,
|
93
|
+
run_once=args.run_once,
|
94
|
+
flwr_dir=args.flwr_dir,
|
95
|
+
certificates=None,
|
96
|
+
)
|
97
|
+
|
98
|
+
# Restore stdout/stderr
|
99
|
+
restore_output()
|
100
|
+
|
101
|
+
|
102
|
+
def run_serverapp( # pylint: disable=R0914, disable=W0212, disable=R0915
|
103
|
+
serverappio_api_address: str,
|
104
|
+
log_queue: Queue[Optional[str]],
|
105
|
+
run_once: bool,
|
106
|
+
flwr_dir: Optional[str] = None,
|
107
|
+
certificates: Optional[bytes] = None,
|
108
|
+
) -> None:
|
109
|
+
"""Run Flower ServerApp process."""
|
110
|
+
driver = GrpcDriver(
|
111
|
+
serverappio_service_address=serverappio_api_address,
|
112
|
+
root_certificates=certificates,
|
113
|
+
)
|
114
|
+
|
115
|
+
# Resolve directory where FABs are installed
|
116
|
+
flwr_dir_ = get_flwr_dir(flwr_dir)
|
117
|
+
log_uploader = None
|
118
|
+
success = True
|
119
|
+
hash_run_id = None
|
120
|
+
while True:
|
121
|
+
|
122
|
+
try:
|
123
|
+
# Pull ServerAppInputs from LinkState
|
124
|
+
req = PullServerAppInputsRequest()
|
125
|
+
res: PullServerAppInputsResponse = driver._stub.PullServerAppInputs(req)
|
126
|
+
if not res.HasField("run"):
|
127
|
+
sleep(3)
|
128
|
+
run_status = None
|
129
|
+
continue
|
130
|
+
|
131
|
+
context = context_from_proto(res.context)
|
132
|
+
run = run_from_proto(res.run)
|
133
|
+
fab = fab_from_proto(res.fab)
|
134
|
+
|
135
|
+
hash_run_id = get_sha256_hash(run.run_id)
|
136
|
+
|
137
|
+
driver.set_run(run.run_id)
|
138
|
+
|
139
|
+
# Start log uploader for this run
|
140
|
+
log_uploader = start_log_uploader(
|
141
|
+
log_queue=log_queue,
|
142
|
+
node_id=0,
|
143
|
+
run_id=run.run_id,
|
144
|
+
stub=driver._stub,
|
145
|
+
)
|
146
|
+
|
147
|
+
log(DEBUG, "ServerApp process starts FAB installation.")
|
148
|
+
install_from_fab(fab.content, flwr_dir=flwr_dir_, skip_prompt=True)
|
149
|
+
|
150
|
+
fab_id, fab_version = get_fab_metadata(fab.content)
|
151
|
+
|
152
|
+
app_path = str(
|
153
|
+
get_project_dir(fab_id, fab_version, fab.hash_str, flwr_dir_)
|
154
|
+
)
|
155
|
+
config = get_project_config(app_path)
|
156
|
+
|
157
|
+
# Obtain server app reference and the run config
|
158
|
+
server_app_attr = config["tool"]["flwr"]["app"]["components"]["serverapp"]
|
159
|
+
server_app_run_config = get_fused_config_from_dir(
|
160
|
+
Path(app_path), run.override_config
|
161
|
+
)
|
162
|
+
|
163
|
+
# Update run_config in context
|
164
|
+
context.run_config = server_app_run_config
|
165
|
+
|
166
|
+
log(
|
167
|
+
DEBUG,
|
168
|
+
"Flower will load ServerApp `%s` in %s",
|
169
|
+
server_app_attr,
|
170
|
+
app_path,
|
171
|
+
)
|
172
|
+
|
173
|
+
# Change status to Running
|
174
|
+
run_status_proto = run_status_to_proto(RunStatus(Status.RUNNING, "", ""))
|
175
|
+
driver._stub.UpdateRunStatus(
|
176
|
+
UpdateRunStatusRequest(run_id=run.run_id, run_status=run_status_proto)
|
177
|
+
)
|
178
|
+
|
179
|
+
event(
|
180
|
+
EventType.FLWR_SERVERAPP_RUN_ENTER,
|
181
|
+
event_details={"run-id-hash": hash_run_id},
|
182
|
+
)
|
183
|
+
|
184
|
+
# Load and run the ServerApp with the Driver
|
185
|
+
updated_context = run_(
|
186
|
+
driver=driver,
|
187
|
+
server_app_dir=app_path,
|
188
|
+
server_app_attr=server_app_attr,
|
189
|
+
context=context,
|
190
|
+
)
|
191
|
+
|
192
|
+
# Send resulting context
|
193
|
+
context_proto = context_to_proto(updated_context)
|
194
|
+
out_req = PushServerAppOutputsRequest(
|
195
|
+
run_id=run.run_id, context=context_proto
|
196
|
+
)
|
197
|
+
_ = driver._stub.PushServerAppOutputs(out_req)
|
198
|
+
|
199
|
+
run_status = RunStatus(Status.FINISHED, SubStatus.COMPLETED, "")
|
200
|
+
except RunNotRunningException:
|
201
|
+
log(INFO, "")
|
202
|
+
log(INFO, "Run ID %s stopped.", run.run_id)
|
203
|
+
log(INFO, "")
|
204
|
+
run_status = None
|
205
|
+
success = False
|
206
|
+
|
207
|
+
except Exception as ex: # pylint: disable=broad-exception-caught
|
208
|
+
exc_entity = "ServerApp"
|
209
|
+
log(ERROR, "%s raised an exception", exc_entity, exc_info=ex)
|
210
|
+
run_status = RunStatus(Status.FINISHED, SubStatus.FAILED, str(ex))
|
211
|
+
success = False
|
212
|
+
|
213
|
+
finally:
|
214
|
+
# Stop log uploader for this run and upload final logs
|
215
|
+
if log_uploader:
|
216
|
+
stop_log_uploader(log_queue, log_uploader)
|
217
|
+
log_uploader = None
|
218
|
+
|
219
|
+
# Update run status
|
220
|
+
if run_status:
|
221
|
+
run_status_proto = run_status_to_proto(run_status)
|
222
|
+
driver._stub.UpdateRunStatus(
|
223
|
+
UpdateRunStatusRequest(
|
224
|
+
run_id=run.run_id, run_status=run_status_proto
|
225
|
+
)
|
226
|
+
)
|
227
|
+
event(
|
228
|
+
EventType.FLWR_SERVERAPP_RUN_LEAVE,
|
229
|
+
event_details={"run-id-hash": hash_run_id, "success": success},
|
230
|
+
)
|
231
|
+
|
232
|
+
# Stop the loop if `flwr-serverapp` is expected to process a single run
|
233
|
+
if run_once:
|
234
|
+
break
|
235
|
+
|
236
|
+
|
237
|
+
def _parse_args_run_flwr_serverapp() -> argparse.ArgumentParser:
|
238
|
+
"""Parse flwr-serverapp command line arguments."""
|
239
|
+
parser = argparse.ArgumentParser(
|
240
|
+
description="Run a Flower ServerApp",
|
241
|
+
)
|
242
|
+
parser.add_argument(
|
243
|
+
"--serverappio-api-address",
|
244
|
+
default=SERVERAPPIO_API_DEFAULT_CLIENT_ADDRESS,
|
245
|
+
type=str,
|
246
|
+
help="Address of SuperLink's ServerAppIo API (IPv4, IPv6, or a domain name)."
|
247
|
+
f"By default, it is set to {SERVERAPPIO_API_DEFAULT_CLIENT_ADDRESS}.",
|
248
|
+
)
|
249
|
+
parser.add_argument(
|
250
|
+
"--run-once",
|
251
|
+
action="store_true",
|
252
|
+
help="When set, this process will start a single ServerApp for a pending Run. "
|
253
|
+
"If there is no pending Run, the process will exit.",
|
254
|
+
)
|
255
|
+
add_args_flwr_app_common(parser=parser)
|
256
|
+
return parser
|
@@ -0,0 +1,52 @@
|
|
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
|
+
"""ServerAppComponents for the ServerApp."""
|
16
|
+
|
17
|
+
|
18
|
+
from dataclasses import dataclass
|
19
|
+
from typing import Optional
|
20
|
+
|
21
|
+
from .client_manager import ClientManager
|
22
|
+
from .server import Server
|
23
|
+
from .server_config import ServerConfig
|
24
|
+
from .strategy import Strategy
|
25
|
+
|
26
|
+
|
27
|
+
@dataclass
|
28
|
+
class ServerAppComponents: # pylint: disable=too-many-instance-attributes
|
29
|
+
"""Components to construct a ServerApp.
|
30
|
+
|
31
|
+
Parameters
|
32
|
+
----------
|
33
|
+
server : Optional[Server] (default: None)
|
34
|
+
A server implementation, either `flwr.server.Server` or a subclass
|
35
|
+
thereof. If no instance is provided, one will be created internally.
|
36
|
+
config : Optional[ServerConfig] (default: None)
|
37
|
+
Currently supported values are `num_rounds` (int, default: 1) and
|
38
|
+
`round_timeout` in seconds (float, default: None).
|
39
|
+
strategy : Optional[Strategy] (default: None)
|
40
|
+
An implementation of the abstract base class
|
41
|
+
`flwr.server.strategy.Strategy`. If no strategy is provided, then
|
42
|
+
`flwr.server.strategy.FedAvg` will be used.
|
43
|
+
client_manager : Optional[ClientManager] (default: None)
|
44
|
+
An implementation of the class `flwr.server.ClientManager`. If no
|
45
|
+
implementation is provided, then `flwr.server.SimpleClientManager`
|
46
|
+
will be used.
|
47
|
+
"""
|
48
|
+
|
49
|
+
server: Optional[Server] = None
|
50
|
+
config: Optional[ServerConfig] = None
|
51
|
+
strategy: Optional[Strategy] = None
|
52
|
+
client_manager: Optional[ClientManager] = None
|
flwr/server/strategy/__init__.py
CHANGED
@@ -53,9 +53,10 @@ __all__ = [
|
|
53
53
|
"DPFedAvgAdaptive",
|
54
54
|
"DPFedAvgFixed",
|
55
55
|
"DifferentialPrivacyClientSideAdaptiveClipping",
|
56
|
-
"DifferentialPrivacyServerSideAdaptiveClipping",
|
57
56
|
"DifferentialPrivacyClientSideFixedClipping",
|
57
|
+
"DifferentialPrivacyServerSideAdaptiveClipping",
|
58
58
|
"DifferentialPrivacyServerSideFixedClipping",
|
59
|
+
"FaultTolerantFedAvg",
|
59
60
|
"FedAdagrad",
|
60
61
|
"FedAdam",
|
61
62
|
"FedAvg",
|
@@ -69,7 +70,6 @@ __all__ = [
|
|
69
70
|
"FedXgbCyclic",
|
70
71
|
"FedXgbNnAvg",
|
71
72
|
"FedYogi",
|
72
|
-
"FaultTolerantFedAvg",
|
73
73
|
"Krum",
|
74
74
|
"QFedAvg",
|
75
75
|
"Strategy",
|
@@ -15,8 +15,8 @@
|
|
15
15
|
"""Aggregation functions for strategy implementations."""
|
16
16
|
# mypy: disallow_untyped_calls=False
|
17
17
|
|
18
|
-
from functools import reduce
|
19
|
-
from typing import Any, Callable,
|
18
|
+
from functools import partial, reduce
|
19
|
+
from typing import Any, Callable, Union
|
20
20
|
|
21
21
|
import numpy as np
|
22
22
|
|
@@ -24,7 +24,7 @@ from flwr.common import FitRes, NDArray, NDArrays, parameters_to_ndarrays
|
|
24
24
|
from flwr.server.client_proxy import ClientProxy
|
25
25
|
|
26
26
|
|
27
|
-
def aggregate(results:
|
27
|
+
def aggregate(results: list[tuple[NDArrays, int]]) -> NDArrays:
|
28
28
|
"""Compute weighted average."""
|
29
29
|
# Calculate the total number of examples used during training
|
30
30
|
num_examples_total = sum(num_examples for (_, num_examples) in results)
|
@@ -42,32 +42,46 @@ def aggregate(results: List[Tuple[NDArrays, int]]) -> NDArrays:
|
|
42
42
|
return weights_prime
|
43
43
|
|
44
44
|
|
45
|
-
def aggregate_inplace(results:
|
45
|
+
def aggregate_inplace(results: list[tuple[ClientProxy, FitRes]]) -> NDArrays:
|
46
46
|
"""Compute in-place weighted average."""
|
47
47
|
# Count total examples
|
48
48
|
num_examples_total = sum(fit_res.num_examples for (_, fit_res) in results)
|
49
49
|
|
50
50
|
# Compute scaling factors for each result
|
51
|
-
scaling_factors =
|
52
|
-
fit_res.num_examples / num_examples_total for _, fit_res in results
|
53
|
-
|
51
|
+
scaling_factors = np.asarray(
|
52
|
+
[fit_res.num_examples / num_examples_total for _, fit_res in results]
|
53
|
+
)
|
54
|
+
|
55
|
+
def _try_inplace(
|
56
|
+
x: NDArray, y: Union[NDArray, np.float64], np_binary_op: np.ufunc
|
57
|
+
) -> NDArray:
|
58
|
+
return ( # type: ignore[no-any-return]
|
59
|
+
np_binary_op(x, y, out=x)
|
60
|
+
if np.can_cast(y, x.dtype, casting="same_kind")
|
61
|
+
else np_binary_op(x, np.array(y, x.dtype), out=x)
|
62
|
+
)
|
54
63
|
|
55
64
|
# Let's do in-place aggregation
|
56
65
|
# Get first result, then add up each other
|
57
66
|
params = [
|
58
|
-
scaling_factors[0]
|
67
|
+
_try_inplace(x, scaling_factors[0], np_binary_op=np.multiply)
|
68
|
+
for x in parameters_to_ndarrays(results[0][1].parameters)
|
59
69
|
]
|
60
|
-
|
70
|
+
|
71
|
+
for i, (_, fit_res) in enumerate(results[1:], start=1):
|
61
72
|
res = (
|
62
|
-
scaling_factors[i
|
73
|
+
_try_inplace(x, scaling_factors[i], np_binary_op=np.multiply)
|
63
74
|
for x in parameters_to_ndarrays(fit_res.parameters)
|
64
75
|
)
|
65
|
-
params = [
|
76
|
+
params = [
|
77
|
+
reduce(partial(_try_inplace, np_binary_op=np.add), layer_updates)
|
78
|
+
for layer_updates in zip(params, res)
|
79
|
+
]
|
66
80
|
|
67
81
|
return params
|
68
82
|
|
69
83
|
|
70
|
-
def aggregate_median(results:
|
84
|
+
def aggregate_median(results: list[tuple[NDArrays, int]]) -> NDArrays:
|
71
85
|
"""Compute median."""
|
72
86
|
# Create a list of weights and ignore the number of examples
|
73
87
|
weights = [weights for weights, _ in results]
|
@@ -80,7 +94,7 @@ def aggregate_median(results: List[Tuple[NDArrays, int]]) -> NDArrays:
|
|
80
94
|
|
81
95
|
|
82
96
|
def aggregate_krum(
|
83
|
-
results:
|
97
|
+
results: list[tuple[NDArrays, int]], num_malicious: int, to_keep: int
|
84
98
|
) -> NDArrays:
|
85
99
|
"""Choose one parameter vector according to the Krum function.
|
86
100
|
|
@@ -119,7 +133,7 @@ def aggregate_krum(
|
|
119
133
|
|
120
134
|
# pylint: disable=too-many-locals
|
121
135
|
def aggregate_bulyan(
|
122
|
-
results:
|
136
|
+
results: list[tuple[NDArrays, int]],
|
123
137
|
num_malicious: int,
|
124
138
|
aggregation_rule: Callable, # type: ignore
|
125
139
|
**aggregation_rule_kwargs: Any,
|
@@ -128,7 +142,7 @@ def aggregate_bulyan(
|
|
128
142
|
|
129
143
|
Parameters
|
130
144
|
----------
|
131
|
-
results:
|
145
|
+
results: list[tuple[NDArrays, int]]
|
132
146
|
Weights and number of samples for each of the client.
|
133
147
|
num_malicious: int
|
134
148
|
The maximum number of malicious clients.
|
@@ -155,7 +169,7 @@ def aggregate_bulyan(
|
|
155
169
|
"It is needed to ensure that the method reduces the attacker's leeway to "
|
156
170
|
"the one proved in the paper."
|
157
171
|
)
|
158
|
-
selected_models_set:
|
172
|
+
selected_models_set: list[tuple[NDArrays, int]] = []
|
159
173
|
|
160
174
|
theta = len(results) - 2 * num_malicious
|
161
175
|
beta = theta - 2 * num_malicious
|
@@ -200,7 +214,7 @@ def aggregate_bulyan(
|
|
200
214
|
return parameters_aggregated
|
201
215
|
|
202
216
|
|
203
|
-
def weighted_loss_avg(results:
|
217
|
+
def weighted_loss_avg(results: list[tuple[int, float]]) -> float:
|
204
218
|
"""Aggregate evaluation results obtained from multiple clients."""
|
205
219
|
num_total_evaluation_examples = sum(num_examples for (num_examples, _) in results)
|
206
220
|
weighted_losses = [num_examples * loss for num_examples, loss in results]
|
@@ -208,7 +222,7 @@ def weighted_loss_avg(results: List[Tuple[int, float]]) -> float:
|
|
208
222
|
|
209
223
|
|
210
224
|
def aggregate_qffl(
|
211
|
-
parameters: NDArrays, deltas:
|
225
|
+
parameters: NDArrays, deltas: list[NDArrays], hs_fll: list[NDArrays]
|
212
226
|
) -> NDArrays:
|
213
227
|
"""Compute weighted average based on Q-FFL paper."""
|
214
228
|
demominator: float = np.sum(np.asarray(hs_fll))
|
@@ -225,7 +239,7 @@ def aggregate_qffl(
|
|
225
239
|
return new_parameters
|
226
240
|
|
227
241
|
|
228
|
-
def _compute_distances(weights:
|
242
|
+
def _compute_distances(weights: list[NDArrays]) -> NDArray:
|
229
243
|
"""Compute distances between vectors.
|
230
244
|
|
231
245
|
Input: weights - list of weights vectors
|
@@ -265,7 +279,7 @@ def _trim_mean(array: NDArray, proportiontocut: float) -> NDArray:
|
|
265
279
|
|
266
280
|
|
267
281
|
def aggregate_trimmed_avg(
|
268
|
-
results:
|
282
|
+
results: list[tuple[NDArrays, int]], proportiontocut: float
|
269
283
|
) -> NDArrays:
|
270
284
|
"""Compute trimmed average."""
|
271
285
|
# Create a list of weights and ignore the number of examples
|
@@ -290,7 +304,7 @@ def _check_weights_equality(weights1: NDArrays, weights2: NDArrays) -> bool:
|
|
290
304
|
|
291
305
|
|
292
306
|
def _find_reference_weights(
|
293
|
-
reference_weights: NDArrays, list_of_weights:
|
307
|
+
reference_weights: NDArrays, list_of_weights: list[NDArrays]
|
294
308
|
) -> int:
|
295
309
|
"""Find the reference weights by looping through the `list_of_weights`.
|
296
310
|
|
@@ -320,7 +334,7 @@ def _find_reference_weights(
|
|
320
334
|
|
321
335
|
|
322
336
|
def _aggregate_n_closest_weights(
|
323
|
-
reference_weights: NDArrays, results:
|
337
|
+
reference_weights: NDArrays, results: list[tuple[NDArrays, int]], beta_closest: int
|
324
338
|
) -> NDArrays:
|
325
339
|
"""Calculate element-wise mean of the `N` closest values.
|
326
340
|
|
@@ -332,7 +346,7 @@ def _aggregate_n_closest_weights(
|
|
332
346
|
----------
|
333
347
|
reference_weights: NDArrays
|
334
348
|
The weights from which the distances will be computed
|
335
|
-
results:
|
349
|
+
results: list[tuple[NDArrays, int]]
|
336
350
|
The weights from models
|
337
351
|
beta_closest: int
|
338
352
|
The number of the closest distance weights that will be averaged
|
flwr/server/strategy/bulyan.py
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright
|
1
|
+
# Copyright 2023 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/abs/1802.07927
|
|
19
19
|
|
20
20
|
|
21
21
|
from logging import WARNING
|
22
|
-
from typing import Any, Callable,
|
22
|
+
from typing import Any, Callable, Optional, Union
|
23
23
|
|
24
24
|
from flwr.common import (
|
25
25
|
FitRes,
|
@@ -86,12 +86,12 @@ class Bulyan(FedAvg):
|
|
86
86
|
num_malicious_clients: int = 0,
|
87
87
|
evaluate_fn: Optional[
|
88
88
|
Callable[
|
89
|
-
[int, NDArrays,
|
90
|
-
Optional[
|
89
|
+
[int, NDArrays, dict[str, Scalar]],
|
90
|
+
Optional[tuple[float, dict[str, Scalar]]],
|
91
91
|
]
|
92
92
|
] = None,
|
93
|
-
on_fit_config_fn: Optional[Callable[[int],
|
94
|
-
on_evaluate_config_fn: Optional[Callable[[int],
|
93
|
+
on_fit_config_fn: Optional[Callable[[int], dict[str, Scalar]]] = None,
|
94
|
+
on_evaluate_config_fn: Optional[Callable[[int], dict[str, Scalar]]] = None,
|
95
95
|
accept_failures: bool = True,
|
96
96
|
initial_parameters: Optional[Parameters] = None,
|
97
97
|
fit_metrics_aggregation_fn: Optional[MetricsAggregationFn] = None,
|
@@ -125,9 +125,9 @@ class Bulyan(FedAvg):
|
|
125
125
|
def aggregate_fit(
|
126
126
|
self,
|
127
127
|
server_round: int,
|
128
|
-
results:
|
129
|
-
failures:
|
130
|
-
) ->
|
128
|
+
results: list[tuple[ClientProxy, FitRes]],
|
129
|
+
failures: list[Union[tuple[ClientProxy, FitRes], BaseException]],
|
130
|
+
) -> tuple[Optional[Parameters], dict[str, Scalar]]:
|
131
131
|
"""Aggregate fit results using Bulyan."""
|
132
132
|
if not results:
|
133
133
|
return None, {}
|