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
flwr/server/strategy/qfedavg.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.
|
@@ -19,7 +19,7 @@ Paper: openreview.net/pdf?id=ByexElSYDr
|
|
19
19
|
|
20
20
|
|
21
21
|
from logging import WARNING
|
22
|
-
from typing import Callable,
|
22
|
+
from typing import Callable, Optional, Union
|
23
23
|
|
24
24
|
import numpy as np
|
25
25
|
|
@@ -60,12 +60,12 @@ class QFedAvg(FedAvg):
|
|
60
60
|
min_available_clients: int = 1,
|
61
61
|
evaluate_fn: Optional[
|
62
62
|
Callable[
|
63
|
-
[int, NDArrays,
|
64
|
-
Optional[
|
63
|
+
[int, NDArrays, dict[str, Scalar]],
|
64
|
+
Optional[tuple[float, dict[str, Scalar]]],
|
65
65
|
]
|
66
66
|
] = None,
|
67
|
-
on_fit_config_fn: Optional[Callable[[int],
|
68
|
-
on_evaluate_config_fn: Optional[Callable[[int],
|
67
|
+
on_fit_config_fn: Optional[Callable[[int], dict[str, Scalar]]] = None,
|
68
|
+
on_evaluate_config_fn: Optional[Callable[[int], dict[str, Scalar]]] = None,
|
69
69
|
accept_failures: bool = True,
|
70
70
|
initial_parameters: Optional[Parameters] = None,
|
71
71
|
fit_metrics_aggregation_fn: Optional[MetricsAggregationFn] = None,
|
@@ -95,19 +95,19 @@ class QFedAvg(FedAvg):
|
|
95
95
|
rep += f"q_param={self.q_param}, pre_weights={self.pre_weights})"
|
96
96
|
return rep
|
97
97
|
|
98
|
-
def num_fit_clients(self, num_available_clients: int) ->
|
98
|
+
def num_fit_clients(self, num_available_clients: int) -> tuple[int, int]:
|
99
99
|
"""Return the sample size and the required number of available clients."""
|
100
100
|
num_clients = int(num_available_clients * self.fraction_fit)
|
101
101
|
return max(num_clients, self.min_fit_clients), self.min_available_clients
|
102
102
|
|
103
|
-
def num_evaluation_clients(self, num_available_clients: int) ->
|
103
|
+
def num_evaluation_clients(self, num_available_clients: int) -> tuple[int, int]:
|
104
104
|
"""Use a fraction of available clients for evaluation."""
|
105
105
|
num_clients = int(num_available_clients * self.fraction_evaluate)
|
106
106
|
return max(num_clients, self.min_evaluate_clients), self.min_available_clients
|
107
107
|
|
108
108
|
def configure_fit(
|
109
109
|
self, server_round: int, parameters: Parameters, client_manager: ClientManager
|
110
|
-
) ->
|
110
|
+
) -> list[tuple[ClientProxy, FitIns]]:
|
111
111
|
"""Configure the next round of training."""
|
112
112
|
weights = parameters_to_ndarrays(parameters)
|
113
113
|
self.pre_weights = weights
|
@@ -131,7 +131,7 @@ class QFedAvg(FedAvg):
|
|
131
131
|
|
132
132
|
def configure_evaluate(
|
133
133
|
self, server_round: int, parameters: Parameters, client_manager: ClientManager
|
134
|
-
) ->
|
134
|
+
) -> list[tuple[ClientProxy, EvaluateIns]]:
|
135
135
|
"""Configure the next round of evaluation."""
|
136
136
|
# Do not configure federated evaluation if fraction_evaluate is 0
|
137
137
|
if self.fraction_evaluate == 0.0:
|
@@ -158,9 +158,9 @@ class QFedAvg(FedAvg):
|
|
158
158
|
def aggregate_fit(
|
159
159
|
self,
|
160
160
|
server_round: int,
|
161
|
-
results:
|
162
|
-
failures:
|
163
|
-
) ->
|
161
|
+
results: list[tuple[ClientProxy, FitRes]],
|
162
|
+
failures: list[Union[tuple[ClientProxy, FitRes], BaseException]],
|
163
|
+
) -> tuple[Optional[Parameters], dict[str, Scalar]]:
|
164
164
|
"""Aggregate fit results using weighted average."""
|
165
165
|
if not results:
|
166
166
|
return None, {}
|
@@ -229,9 +229,9 @@ class QFedAvg(FedAvg):
|
|
229
229
|
def aggregate_evaluate(
|
230
230
|
self,
|
231
231
|
server_round: int,
|
232
|
-
results:
|
233
|
-
failures:
|
234
|
-
) ->
|
232
|
+
results: list[tuple[ClientProxy, EvaluateRes]],
|
233
|
+
failures: list[Union[tuple[ClientProxy, EvaluateRes], BaseException]],
|
234
|
+
) -> tuple[Optional[float], dict[str, Scalar]]:
|
235
235
|
"""Aggregate evaluation losses using weighted average."""
|
236
236
|
if not results:
|
237
237
|
return None, {}
|
flwr/server/strategy/strategy.py
CHANGED
@@ -16,7 +16,7 @@
|
|
16
16
|
|
17
17
|
|
18
18
|
from abc import ABC, abstractmethod
|
19
|
-
from typing import
|
19
|
+
from typing import Optional, Union
|
20
20
|
|
21
21
|
from flwr.common import EvaluateIns, EvaluateRes, FitIns, FitRes, Parameters, Scalar
|
22
22
|
from flwr.server.client_manager import ClientManager
|
@@ -47,7 +47,7 @@ class Strategy(ABC):
|
|
47
47
|
@abstractmethod
|
48
48
|
def configure_fit(
|
49
49
|
self, server_round: int, parameters: Parameters, client_manager: ClientManager
|
50
|
-
) ->
|
50
|
+
) -> list[tuple[ClientProxy, FitIns]]:
|
51
51
|
"""Configure the next round of training.
|
52
52
|
|
53
53
|
Parameters
|
@@ -72,9 +72,9 @@ class Strategy(ABC):
|
|
72
72
|
def aggregate_fit(
|
73
73
|
self,
|
74
74
|
server_round: int,
|
75
|
-
results:
|
76
|
-
failures:
|
77
|
-
) ->
|
75
|
+
results: list[tuple[ClientProxy, FitRes]],
|
76
|
+
failures: list[Union[tuple[ClientProxy, FitRes], BaseException]],
|
77
|
+
) -> tuple[Optional[Parameters], dict[str, Scalar]]:
|
78
78
|
"""Aggregate training results.
|
79
79
|
|
80
80
|
Parameters
|
@@ -108,7 +108,7 @@ class Strategy(ABC):
|
|
108
108
|
@abstractmethod
|
109
109
|
def configure_evaluate(
|
110
110
|
self, server_round: int, parameters: Parameters, client_manager: ClientManager
|
111
|
-
) ->
|
111
|
+
) -> list[tuple[ClientProxy, EvaluateIns]]:
|
112
112
|
"""Configure the next round of evaluation.
|
113
113
|
|
114
114
|
Parameters
|
@@ -134,9 +134,9 @@ class Strategy(ABC):
|
|
134
134
|
def aggregate_evaluate(
|
135
135
|
self,
|
136
136
|
server_round: int,
|
137
|
-
results:
|
138
|
-
failures:
|
139
|
-
) ->
|
137
|
+
results: list[tuple[ClientProxy, EvaluateRes]],
|
138
|
+
failures: list[Union[tuple[ClientProxy, EvaluateRes], BaseException]],
|
139
|
+
) -> tuple[Optional[float], dict[str, Scalar]]:
|
140
140
|
"""Aggregate evaluation results.
|
141
141
|
|
142
142
|
Parameters
|
@@ -164,7 +164,7 @@ class Strategy(ABC):
|
|
164
164
|
@abstractmethod
|
165
165
|
def evaluate(
|
166
166
|
self, server_round: int, parameters: Parameters
|
167
|
-
) -> Optional[
|
167
|
+
) -> Optional[tuple[float, dict[str, Scalar]]]:
|
168
168
|
"""Evaluate the current model parameters.
|
169
169
|
|
170
170
|
This function can be used to perform centralized (i.e., server-side) evaluation
|
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright
|
1
|
+
# Copyright 2024 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.
|
@@ -12,4 +12,4 @@
|
|
12
12
|
# See the License for the specific language governing permissions and
|
13
13
|
# limitations under the License.
|
14
14
|
# ==============================================================================
|
15
|
-
"""Flower
|
15
|
+
"""Flower ServerAppIo service."""
|
@@ -0,0 +1,61 @@
|
|
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
|
+
"""ServerAppIo gRPC API."""
|
16
|
+
|
17
|
+
|
18
|
+
from logging import INFO
|
19
|
+
from typing import Optional
|
20
|
+
|
21
|
+
import grpc
|
22
|
+
|
23
|
+
from flwr.common import GRPC_MAX_MESSAGE_LENGTH
|
24
|
+
from flwr.common.grpc import generic_create_grpc_server
|
25
|
+
from flwr.common.logger import log
|
26
|
+
from flwr.proto.serverappio_pb2_grpc import ( # pylint: disable=E0611
|
27
|
+
add_ServerAppIoServicer_to_server,
|
28
|
+
)
|
29
|
+
from flwr.server.superlink.ffs.ffs_factory import FfsFactory
|
30
|
+
from flwr.server.superlink.linkstate import LinkStateFactory
|
31
|
+
|
32
|
+
from .serverappio_servicer import ServerAppIoServicer
|
33
|
+
|
34
|
+
|
35
|
+
def run_serverappio_api_grpc(
|
36
|
+
address: str,
|
37
|
+
state_factory: LinkStateFactory,
|
38
|
+
ffs_factory: FfsFactory,
|
39
|
+
certificates: Optional[tuple[bytes, bytes, bytes]],
|
40
|
+
) -> grpc.Server:
|
41
|
+
"""Run ServerAppIo API (gRPC, request-response)."""
|
42
|
+
# Create ServerAppIo API gRPC server
|
43
|
+
serverappio_servicer: grpc.Server = ServerAppIoServicer(
|
44
|
+
state_factory=state_factory,
|
45
|
+
ffs_factory=ffs_factory,
|
46
|
+
)
|
47
|
+
serverappio_add_servicer_to_server_fn = add_ServerAppIoServicer_to_server
|
48
|
+
serverappio_grpc_server = generic_create_grpc_server(
|
49
|
+
servicer_and_add_fn=(
|
50
|
+
serverappio_servicer,
|
51
|
+
serverappio_add_servicer_to_server_fn,
|
52
|
+
),
|
53
|
+
server_address=address,
|
54
|
+
max_message_length=GRPC_MAX_MESSAGE_LENGTH,
|
55
|
+
certificates=certificates,
|
56
|
+
)
|
57
|
+
|
58
|
+
log(INFO, "Flower ECE: Starting ServerAppIo API (gRPC-rere) on %s", address)
|
59
|
+
serverappio_grpc_server.start()
|
60
|
+
|
61
|
+
return serverappio_grpc_server
|
@@ -0,0 +1,363 @@
|
|
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
|
+
"""ServerAppIo API servicer."""
|
16
|
+
|
17
|
+
|
18
|
+
import threading
|
19
|
+
import time
|
20
|
+
from logging import DEBUG, INFO
|
21
|
+
from typing import Optional
|
22
|
+
from uuid import UUID
|
23
|
+
|
24
|
+
import grpc
|
25
|
+
|
26
|
+
from flwr.common import ConfigsRecord
|
27
|
+
from flwr.common.constant import Status
|
28
|
+
from flwr.common.logger import log
|
29
|
+
from flwr.common.serde import (
|
30
|
+
context_from_proto,
|
31
|
+
context_to_proto,
|
32
|
+
fab_from_proto,
|
33
|
+
fab_to_proto,
|
34
|
+
run_status_from_proto,
|
35
|
+
run_status_to_proto,
|
36
|
+
run_to_proto,
|
37
|
+
user_config_from_proto,
|
38
|
+
)
|
39
|
+
from flwr.common.typing import Fab, RunStatus
|
40
|
+
from flwr.proto import serverappio_pb2_grpc # pylint: disable=E0611
|
41
|
+
from flwr.proto.fab_pb2 import GetFabRequest, GetFabResponse # pylint: disable=E0611
|
42
|
+
from flwr.proto.log_pb2 import ( # pylint: disable=E0611
|
43
|
+
PushLogsRequest,
|
44
|
+
PushLogsResponse,
|
45
|
+
)
|
46
|
+
from flwr.proto.node_pb2 import Node # pylint: disable=E0611
|
47
|
+
from flwr.proto.run_pb2 import ( # pylint: disable=E0611
|
48
|
+
CreateRunRequest,
|
49
|
+
CreateRunResponse,
|
50
|
+
GetRunRequest,
|
51
|
+
GetRunResponse,
|
52
|
+
GetRunStatusRequest,
|
53
|
+
GetRunStatusResponse,
|
54
|
+
UpdateRunStatusRequest,
|
55
|
+
UpdateRunStatusResponse,
|
56
|
+
)
|
57
|
+
from flwr.proto.serverappio_pb2 import ( # pylint: disable=E0611
|
58
|
+
GetNodesRequest,
|
59
|
+
GetNodesResponse,
|
60
|
+
PullServerAppInputsRequest,
|
61
|
+
PullServerAppInputsResponse,
|
62
|
+
PullTaskResRequest,
|
63
|
+
PullTaskResResponse,
|
64
|
+
PushServerAppOutputsRequest,
|
65
|
+
PushServerAppOutputsResponse,
|
66
|
+
PushTaskInsRequest,
|
67
|
+
PushTaskInsResponse,
|
68
|
+
)
|
69
|
+
from flwr.proto.task_pb2 import TaskRes # pylint: disable=E0611
|
70
|
+
from flwr.server.superlink.ffs.ffs import Ffs
|
71
|
+
from flwr.server.superlink.ffs.ffs_factory import FfsFactory
|
72
|
+
from flwr.server.superlink.linkstate import LinkState, LinkStateFactory
|
73
|
+
from flwr.server.superlink.utils import abort_if
|
74
|
+
from flwr.server.utils.validator import validate_task_ins_or_res
|
75
|
+
|
76
|
+
|
77
|
+
class ServerAppIoServicer(serverappio_pb2_grpc.ServerAppIoServicer):
|
78
|
+
"""ServerAppIo API servicer."""
|
79
|
+
|
80
|
+
def __init__(
|
81
|
+
self, state_factory: LinkStateFactory, ffs_factory: FfsFactory
|
82
|
+
) -> None:
|
83
|
+
self.state_factory = state_factory
|
84
|
+
self.ffs_factory = ffs_factory
|
85
|
+
self.lock = threading.RLock()
|
86
|
+
|
87
|
+
def GetNodes(
|
88
|
+
self, request: GetNodesRequest, context: grpc.ServicerContext
|
89
|
+
) -> GetNodesResponse:
|
90
|
+
"""Get available nodes."""
|
91
|
+
log(DEBUG, "ServerAppIoServicer.GetNodes")
|
92
|
+
|
93
|
+
# Init state
|
94
|
+
state: LinkState = self.state_factory.state()
|
95
|
+
|
96
|
+
# Abort if the run is not running
|
97
|
+
abort_if(
|
98
|
+
request.run_id,
|
99
|
+
[Status.PENDING, Status.STARTING, Status.FINISHED],
|
100
|
+
state,
|
101
|
+
context,
|
102
|
+
)
|
103
|
+
|
104
|
+
all_ids: set[int] = state.get_nodes(request.run_id)
|
105
|
+
nodes: list[Node] = [
|
106
|
+
Node(node_id=node_id, anonymous=False) for node_id in all_ids
|
107
|
+
]
|
108
|
+
return GetNodesResponse(nodes=nodes)
|
109
|
+
|
110
|
+
def CreateRun(
|
111
|
+
self, request: CreateRunRequest, context: grpc.ServicerContext
|
112
|
+
) -> CreateRunResponse:
|
113
|
+
"""Create run ID."""
|
114
|
+
log(DEBUG, "ServerAppIoServicer.CreateRun")
|
115
|
+
state: LinkState = self.state_factory.state()
|
116
|
+
if request.HasField("fab"):
|
117
|
+
fab = fab_from_proto(request.fab)
|
118
|
+
ffs: Ffs = self.ffs_factory.ffs()
|
119
|
+
fab_hash = ffs.put(fab.content, {})
|
120
|
+
_raise_if(
|
121
|
+
validation_error=fab_hash != fab.hash_str,
|
122
|
+
request_name="CreateRun",
|
123
|
+
detail=f"FAB ({fab.hash_str}) hash from request doesn't match contents",
|
124
|
+
)
|
125
|
+
else:
|
126
|
+
fab_hash = ""
|
127
|
+
run_id = state.create_run(
|
128
|
+
request.fab_id,
|
129
|
+
request.fab_version,
|
130
|
+
fab_hash,
|
131
|
+
user_config_from_proto(request.override_config),
|
132
|
+
ConfigsRecord(),
|
133
|
+
)
|
134
|
+
return CreateRunResponse(run_id=run_id)
|
135
|
+
|
136
|
+
def PushTaskIns(
|
137
|
+
self, request: PushTaskInsRequest, context: grpc.ServicerContext
|
138
|
+
) -> PushTaskInsResponse:
|
139
|
+
"""Push a set of TaskIns."""
|
140
|
+
log(DEBUG, "ServerAppIoServicer.PushTaskIns")
|
141
|
+
|
142
|
+
# Init state
|
143
|
+
state: LinkState = self.state_factory.state()
|
144
|
+
|
145
|
+
# Abort if the run is not running
|
146
|
+
abort_if(
|
147
|
+
request.run_id,
|
148
|
+
[Status.PENDING, Status.STARTING, Status.FINISHED],
|
149
|
+
state,
|
150
|
+
context,
|
151
|
+
)
|
152
|
+
|
153
|
+
# Set pushed_at (timestamp in seconds)
|
154
|
+
pushed_at = time.time()
|
155
|
+
for task_ins in request.task_ins_list:
|
156
|
+
task_ins.task.pushed_at = pushed_at
|
157
|
+
|
158
|
+
# Validate request
|
159
|
+
_raise_if(
|
160
|
+
validation_error=len(request.task_ins_list) == 0,
|
161
|
+
request_name="PushTaskIns",
|
162
|
+
detail="`task_ins_list` must not be empty",
|
163
|
+
)
|
164
|
+
for task_ins in request.task_ins_list:
|
165
|
+
validation_errors = validate_task_ins_or_res(task_ins)
|
166
|
+
_raise_if(
|
167
|
+
validation_error=bool(validation_errors),
|
168
|
+
request_name="PushTaskIns",
|
169
|
+
detail=", ".join(validation_errors),
|
170
|
+
)
|
171
|
+
_raise_if(
|
172
|
+
validation_error=request.run_id != task_ins.run_id,
|
173
|
+
request_name="PushTaskIns",
|
174
|
+
detail="`task_ins` has mismatched `run_id`",
|
175
|
+
)
|
176
|
+
|
177
|
+
# Store each TaskIns
|
178
|
+
task_ids: list[Optional[UUID]] = []
|
179
|
+
for task_ins in request.task_ins_list:
|
180
|
+
task_id: Optional[UUID] = state.store_task_ins(task_ins=task_ins)
|
181
|
+
task_ids.append(task_id)
|
182
|
+
|
183
|
+
return PushTaskInsResponse(
|
184
|
+
task_ids=[str(task_id) if task_id else "" for task_id in task_ids]
|
185
|
+
)
|
186
|
+
|
187
|
+
def PullTaskRes(
|
188
|
+
self, request: PullTaskResRequest, context: grpc.ServicerContext
|
189
|
+
) -> PullTaskResResponse:
|
190
|
+
"""Pull a set of TaskRes."""
|
191
|
+
log(DEBUG, "ServerAppIoServicer.PullTaskRes")
|
192
|
+
|
193
|
+
# Init state
|
194
|
+
state: LinkState = self.state_factory.state()
|
195
|
+
|
196
|
+
# Abort if the run is not running
|
197
|
+
abort_if(
|
198
|
+
request.run_id,
|
199
|
+
[Status.PENDING, Status.STARTING, Status.FINISHED],
|
200
|
+
state,
|
201
|
+
context,
|
202
|
+
)
|
203
|
+
|
204
|
+
# Convert each task_id str to UUID
|
205
|
+
task_ids: set[UUID] = {UUID(task_id) for task_id in request.task_ids}
|
206
|
+
|
207
|
+
# Read from state
|
208
|
+
task_res_list: list[TaskRes] = state.get_task_res(task_ids=task_ids)
|
209
|
+
|
210
|
+
# Validate request
|
211
|
+
for task_res in task_res_list:
|
212
|
+
_raise_if(
|
213
|
+
validation_error=request.run_id != task_res.run_id,
|
214
|
+
request_name="PullTaskRes",
|
215
|
+
detail="`task_res` has mismatched `run_id`",
|
216
|
+
)
|
217
|
+
|
218
|
+
# Delete the TaskIns/TaskRes pairs if TaskRes is found
|
219
|
+
task_ins_ids_to_delete = {
|
220
|
+
UUID(task_res.task.ancestry[0]) for task_res in task_res_list
|
221
|
+
}
|
222
|
+
state.delete_tasks(task_ins_ids=task_ins_ids_to_delete)
|
223
|
+
|
224
|
+
return PullTaskResResponse(task_res_list=task_res_list)
|
225
|
+
|
226
|
+
def GetRun(
|
227
|
+
self, request: GetRunRequest, context: grpc.ServicerContext
|
228
|
+
) -> GetRunResponse:
|
229
|
+
"""Get run information."""
|
230
|
+
log(DEBUG, "ServerAppIoServicer.GetRun")
|
231
|
+
|
232
|
+
# Init state
|
233
|
+
state: LinkState = self.state_factory.state()
|
234
|
+
|
235
|
+
# Retrieve run information
|
236
|
+
run = state.get_run(request.run_id)
|
237
|
+
|
238
|
+
if run is None:
|
239
|
+
return GetRunResponse()
|
240
|
+
|
241
|
+
return GetRunResponse(run=run_to_proto(run))
|
242
|
+
|
243
|
+
def GetFab(
|
244
|
+
self, request: GetFabRequest, context: grpc.ServicerContext
|
245
|
+
) -> GetFabResponse:
|
246
|
+
"""Get FAB from Ffs."""
|
247
|
+
log(DEBUG, "ServerAppIoServicer.GetFab")
|
248
|
+
|
249
|
+
ffs: Ffs = self.ffs_factory.ffs()
|
250
|
+
if result := ffs.get(request.hash_str):
|
251
|
+
fab = Fab(request.hash_str, result[0])
|
252
|
+
return GetFabResponse(fab=fab_to_proto(fab))
|
253
|
+
|
254
|
+
raise ValueError(f"Found no FAB with hash: {request.hash_str}")
|
255
|
+
|
256
|
+
def PullServerAppInputs(
|
257
|
+
self, request: PullServerAppInputsRequest, context: grpc.ServicerContext
|
258
|
+
) -> PullServerAppInputsResponse:
|
259
|
+
"""Pull ServerApp process inputs."""
|
260
|
+
log(DEBUG, "ServerAppIoServicer.PullServerAppInputs")
|
261
|
+
# Init access to LinkState and Ffs
|
262
|
+
state = self.state_factory.state()
|
263
|
+
ffs = self.ffs_factory.ffs()
|
264
|
+
|
265
|
+
# Lock access to LinkState, preventing obtaining the same pending run_id
|
266
|
+
with self.lock:
|
267
|
+
# Attempt getting the run_id of a pending run
|
268
|
+
run_id = state.get_pending_run_id()
|
269
|
+
# If there's no pending run, return an empty response
|
270
|
+
if run_id is None:
|
271
|
+
return PullServerAppInputsResponse()
|
272
|
+
|
273
|
+
# Retrieve Context, Run and Fab for the run_id
|
274
|
+
serverapp_ctxt = state.get_serverapp_context(run_id)
|
275
|
+
run = state.get_run(run_id)
|
276
|
+
fab = None
|
277
|
+
if run and run.fab_hash:
|
278
|
+
if result := ffs.get(run.fab_hash):
|
279
|
+
fab = Fab(run.fab_hash, result[0])
|
280
|
+
if run and fab and serverapp_ctxt:
|
281
|
+
# Update run status to STARTING
|
282
|
+
if state.update_run_status(run_id, RunStatus(Status.STARTING, "", "")):
|
283
|
+
log(INFO, "Starting run %d", run_id)
|
284
|
+
return PullServerAppInputsResponse(
|
285
|
+
context=context_to_proto(serverapp_ctxt),
|
286
|
+
run=run_to_proto(run),
|
287
|
+
fab=fab_to_proto(fab),
|
288
|
+
)
|
289
|
+
|
290
|
+
# Raise an exception if the Run or Fab is not found,
|
291
|
+
# or if the status cannot be updated to STARTING
|
292
|
+
raise RuntimeError(f"Failed to start run {run_id}")
|
293
|
+
|
294
|
+
def PushServerAppOutputs(
|
295
|
+
self, request: PushServerAppOutputsRequest, context: grpc.ServicerContext
|
296
|
+
) -> PushServerAppOutputsResponse:
|
297
|
+
"""Push ServerApp process outputs."""
|
298
|
+
log(DEBUG, "ServerAppIoServicer.PushServerAppOutputs")
|
299
|
+
|
300
|
+
# Init state
|
301
|
+
state = self.state_factory.state()
|
302
|
+
|
303
|
+
# Abort if the run is not running
|
304
|
+
abort_if(
|
305
|
+
request.run_id,
|
306
|
+
[Status.PENDING, Status.STARTING, Status.FINISHED],
|
307
|
+
state,
|
308
|
+
context,
|
309
|
+
)
|
310
|
+
|
311
|
+
state.set_serverapp_context(request.run_id, context_from_proto(request.context))
|
312
|
+
return PushServerAppOutputsResponse()
|
313
|
+
|
314
|
+
def UpdateRunStatus(
|
315
|
+
self, request: UpdateRunStatusRequest, context: grpc.ServicerContext
|
316
|
+
) -> UpdateRunStatusResponse:
|
317
|
+
"""Update the status of a run."""
|
318
|
+
log(DEBUG, "ServerAppIoServicer.UpdateRunStatus")
|
319
|
+
|
320
|
+
# Init state
|
321
|
+
state = self.state_factory.state()
|
322
|
+
|
323
|
+
# Abort if the run is finished
|
324
|
+
abort_if(request.run_id, [Status.FINISHED], state, context)
|
325
|
+
|
326
|
+
# Update the run status
|
327
|
+
state.update_run_status(
|
328
|
+
run_id=request.run_id, new_status=run_status_from_proto(request.run_status)
|
329
|
+
)
|
330
|
+
return UpdateRunStatusResponse()
|
331
|
+
|
332
|
+
def PushLogs(
|
333
|
+
self, request: PushLogsRequest, context: grpc.ServicerContext
|
334
|
+
) -> PushLogsResponse:
|
335
|
+
"""Push logs."""
|
336
|
+
log(DEBUG, "ServerAppIoServicer.PushLogs")
|
337
|
+
state = self.state_factory.state()
|
338
|
+
|
339
|
+
# Add logs to LinkState
|
340
|
+
merged_logs = "".join(request.logs)
|
341
|
+
state.add_serverapp_log(request.run_id, merged_logs)
|
342
|
+
return PushLogsResponse()
|
343
|
+
|
344
|
+
def GetRunStatus(
|
345
|
+
self, request: GetRunStatusRequest, context: grpc.ServicerContext
|
346
|
+
) -> GetRunStatusResponse:
|
347
|
+
"""Get the status of a run."""
|
348
|
+
log(DEBUG, "ServerAppIoServicer.GetRunStatus")
|
349
|
+
state = self.state_factory.state()
|
350
|
+
|
351
|
+
# Get run status from LinkState
|
352
|
+
run_statuses = state.get_run_status(set(request.run_ids))
|
353
|
+
run_status_dict = {
|
354
|
+
run_id: run_status_to_proto(run_status)
|
355
|
+
for run_id, run_status in run_statuses.items()
|
356
|
+
}
|
357
|
+
return GetRunStatusResponse(run_status_dict=run_status_dict)
|
358
|
+
|
359
|
+
|
360
|
+
def _raise_if(validation_error: bool, request_name: str, detail: str) -> None:
|
361
|
+
"""Raise a `ValueError` with a detailed message if a validation error occurs."""
|
362
|
+
if validation_error:
|
363
|
+
raise ValueError(f"Malformed {request_name}: {detail}")
|
@@ -0,0 +1,24 @@
|
|
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 File Storage for large objects."""
|
16
|
+
|
17
|
+
|
18
|
+
from .disk_ffs import DiskFfs as DiskFfs
|
19
|
+
from .ffs import Ffs as Ffs
|
20
|
+
|
21
|
+
__all__ = [
|
22
|
+
"DiskFfs",
|
23
|
+
"Ffs",
|
24
|
+
]
|