flwr-nightly 1.10.0.dev20240612__py3-none-any.whl → 1.10.0.dev20240614__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of flwr-nightly might be problematic. Click here for more details.
- flwr/cli/build.py +3 -1
- flwr/cli/config_utils.py +53 -3
- flwr/cli/install.py +35 -20
- flwr/cli/run/run.py +38 -1
- flwr/client/app.py +18 -10
- flwr/client/supernode/app.py +141 -38
- flwr/common/config.py +28 -0
- flwr/common/constant.py +2 -0
- flwr/common/telemetry.py +4 -0
- flwr/proto/exec_pb2.py +30 -0
- flwr/proto/exec_pb2.pyi +32 -0
- flwr/proto/exec_pb2_grpc.py +67 -0
- flwr/proto/exec_pb2_grpc.pyi +27 -0
- flwr/server/app.py +15 -18
- flwr/simulation/run_simulation.py +22 -0
- flwr/superexec/__init__.py +21 -0
- flwr/superexec/app.py +178 -0
- flwr/superexec/exec_grpc.py +51 -0
- flwr/superexec/exec_servicer.py +54 -0
- flwr/superexec/executor.py +54 -0
- {flwr_nightly-1.10.0.dev20240612.dist-info → flwr_nightly-1.10.0.dev20240614.dist-info}/METADATA +1 -1
- {flwr_nightly-1.10.0.dev20240612.dist-info → flwr_nightly-1.10.0.dev20240614.dist-info}/RECORD +25 -15
- {flwr_nightly-1.10.0.dev20240612.dist-info → flwr_nightly-1.10.0.dev20240614.dist-info}/entry_points.txt +1 -0
- {flwr_nightly-1.10.0.dev20240612.dist-info → flwr_nightly-1.10.0.dev20240614.dist-info}/LICENSE +0 -0
- {flwr_nightly-1.10.0.dev20240612.dist-info → flwr_nightly-1.10.0.dev20240614.dist-info}/WHEEL +0 -0
flwr/proto/exec_pb2.pyi
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"""
|
|
2
|
+
@generated by mypy-protobuf. Do not edit manually!
|
|
3
|
+
isort:skip_file
|
|
4
|
+
"""
|
|
5
|
+
import builtins
|
|
6
|
+
import google.protobuf.descriptor
|
|
7
|
+
import google.protobuf.message
|
|
8
|
+
import typing_extensions
|
|
9
|
+
|
|
10
|
+
DESCRIPTOR: google.protobuf.descriptor.FileDescriptor
|
|
11
|
+
|
|
12
|
+
class StartRunRequest(google.protobuf.message.Message):
|
|
13
|
+
DESCRIPTOR: google.protobuf.descriptor.Descriptor
|
|
14
|
+
FAB_FILE_FIELD_NUMBER: builtins.int
|
|
15
|
+
fab_file: builtins.bytes
|
|
16
|
+
def __init__(self,
|
|
17
|
+
*,
|
|
18
|
+
fab_file: builtins.bytes = ...,
|
|
19
|
+
) -> None: ...
|
|
20
|
+
def ClearField(self, field_name: typing_extensions.Literal["fab_file",b"fab_file"]) -> None: ...
|
|
21
|
+
global___StartRunRequest = StartRunRequest
|
|
22
|
+
|
|
23
|
+
class StartRunResponse(google.protobuf.message.Message):
|
|
24
|
+
DESCRIPTOR: google.protobuf.descriptor.Descriptor
|
|
25
|
+
RUN_ID_FIELD_NUMBER: builtins.int
|
|
26
|
+
run_id: builtins.int
|
|
27
|
+
def __init__(self,
|
|
28
|
+
*,
|
|
29
|
+
run_id: builtins.int = ...,
|
|
30
|
+
) -> None: ...
|
|
31
|
+
def ClearField(self, field_name: typing_extensions.Literal["run_id",b"run_id"]) -> None: ...
|
|
32
|
+
global___StartRunResponse = StartRunResponse
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
# Generated by the gRPC Python protocol compiler plugin. DO NOT EDIT!
|
|
2
|
+
"""Client and server classes corresponding to protobuf-defined services."""
|
|
3
|
+
import grpc
|
|
4
|
+
|
|
5
|
+
from flwr.proto import exec_pb2 as flwr_dot_proto_dot_exec__pb2
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class ExecStub(object):
|
|
9
|
+
"""Missing associated documentation comment in .proto file."""
|
|
10
|
+
|
|
11
|
+
def __init__(self, channel):
|
|
12
|
+
"""Constructor.
|
|
13
|
+
|
|
14
|
+
Args:
|
|
15
|
+
channel: A grpc.Channel.
|
|
16
|
+
"""
|
|
17
|
+
self.StartRun = channel.unary_unary(
|
|
18
|
+
'/flwr.proto.Exec/StartRun',
|
|
19
|
+
request_serializer=flwr_dot_proto_dot_exec__pb2.StartRunRequest.SerializeToString,
|
|
20
|
+
response_deserializer=flwr_dot_proto_dot_exec__pb2.StartRunResponse.FromString,
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
class ExecServicer(object):
|
|
25
|
+
"""Missing associated documentation comment in .proto file."""
|
|
26
|
+
|
|
27
|
+
def StartRun(self, request, context):
|
|
28
|
+
"""Start run upon request
|
|
29
|
+
"""
|
|
30
|
+
context.set_code(grpc.StatusCode.UNIMPLEMENTED)
|
|
31
|
+
context.set_details('Method not implemented!')
|
|
32
|
+
raise NotImplementedError('Method not implemented!')
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def add_ExecServicer_to_server(servicer, server):
|
|
36
|
+
rpc_method_handlers = {
|
|
37
|
+
'StartRun': grpc.unary_unary_rpc_method_handler(
|
|
38
|
+
servicer.StartRun,
|
|
39
|
+
request_deserializer=flwr_dot_proto_dot_exec__pb2.StartRunRequest.FromString,
|
|
40
|
+
response_serializer=flwr_dot_proto_dot_exec__pb2.StartRunResponse.SerializeToString,
|
|
41
|
+
),
|
|
42
|
+
}
|
|
43
|
+
generic_handler = grpc.method_handlers_generic_handler(
|
|
44
|
+
'flwr.proto.Exec', rpc_method_handlers)
|
|
45
|
+
server.add_generic_rpc_handlers((generic_handler,))
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
# This class is part of an EXPERIMENTAL API.
|
|
49
|
+
class Exec(object):
|
|
50
|
+
"""Missing associated documentation comment in .proto file."""
|
|
51
|
+
|
|
52
|
+
@staticmethod
|
|
53
|
+
def StartRun(request,
|
|
54
|
+
target,
|
|
55
|
+
options=(),
|
|
56
|
+
channel_credentials=None,
|
|
57
|
+
call_credentials=None,
|
|
58
|
+
insecure=False,
|
|
59
|
+
compression=None,
|
|
60
|
+
wait_for_ready=None,
|
|
61
|
+
timeout=None,
|
|
62
|
+
metadata=None):
|
|
63
|
+
return grpc.experimental.unary_unary(request, target, '/flwr.proto.Exec/StartRun',
|
|
64
|
+
flwr_dot_proto_dot_exec__pb2.StartRunRequest.SerializeToString,
|
|
65
|
+
flwr_dot_proto_dot_exec__pb2.StartRunResponse.FromString,
|
|
66
|
+
options, channel_credentials,
|
|
67
|
+
insecure, call_credentials, compression, wait_for_ready, timeout, metadata)
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"""
|
|
2
|
+
@generated by mypy-protobuf. Do not edit manually!
|
|
3
|
+
isort:skip_file
|
|
4
|
+
"""
|
|
5
|
+
import abc
|
|
6
|
+
import flwr.proto.exec_pb2
|
|
7
|
+
import grpc
|
|
8
|
+
|
|
9
|
+
class ExecStub:
|
|
10
|
+
def __init__(self, channel: grpc.Channel) -> None: ...
|
|
11
|
+
StartRun: grpc.UnaryUnaryMultiCallable[
|
|
12
|
+
flwr.proto.exec_pb2.StartRunRequest,
|
|
13
|
+
flwr.proto.exec_pb2.StartRunResponse]
|
|
14
|
+
"""Start run upon request"""
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class ExecServicer(metaclass=abc.ABCMeta):
|
|
18
|
+
@abc.abstractmethod
|
|
19
|
+
def StartRun(self,
|
|
20
|
+
request: flwr.proto.exec_pb2.StartRunRequest,
|
|
21
|
+
context: grpc.ServicerContext,
|
|
22
|
+
) -> flwr.proto.exec_pb2.StartRunResponse:
|
|
23
|
+
"""Start run upon request"""
|
|
24
|
+
pass
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def add_ExecServicer_to_server(servicer: ExecServicer, server: grpc.Server) -> None: ...
|
flwr/server/app.py
CHANGED
|
@@ -200,15 +200,7 @@ def run_superlink() -> None:
|
|
|
200
200
|
args = _parse_args_run_superlink().parse_args()
|
|
201
201
|
|
|
202
202
|
# Parse IP address
|
|
203
|
-
|
|
204
|
-
if not parsed_driver_address:
|
|
205
|
-
sys.exit(f"Driver IP address ({args.driver_api_address}) cannot be parsed.")
|
|
206
|
-
driver_host, driver_port, driver_is_v6 = parsed_driver_address
|
|
207
|
-
driver_address = (
|
|
208
|
-
f"[{driver_host}]:{driver_port}"
|
|
209
|
-
if driver_is_v6
|
|
210
|
-
else f"{driver_host}:{driver_port}"
|
|
211
|
-
)
|
|
203
|
+
driver_address, _, _ = _format_address(args.driver_api_address)
|
|
212
204
|
|
|
213
205
|
# Obtain certificates
|
|
214
206
|
certificates = _try_obtain_certificates(args)
|
|
@@ -231,13 +223,8 @@ def run_superlink() -> None:
|
|
|
231
223
|
if args.fleet_api_type == TRANSPORT_TYPE_GRPC_RERE
|
|
232
224
|
else ADDRESS_FLEET_API_REST
|
|
233
225
|
)
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
sys.exit(f"Fleet IP address ({args.fleet_api_address}) cannot be parsed.")
|
|
237
|
-
fleet_host, fleet_port, fleet_is_v6 = parsed_fleet_address
|
|
238
|
-
fleet_address = (
|
|
239
|
-
f"[{fleet_host}]:{fleet_port}" if fleet_is_v6 else f"{fleet_host}:{fleet_port}"
|
|
240
|
-
)
|
|
226
|
+
|
|
227
|
+
fleet_address, host, port = _format_address(args.fleet_api_address)
|
|
241
228
|
|
|
242
229
|
num_workers = args.fleet_api_num_workers
|
|
243
230
|
if num_workers != 1:
|
|
@@ -267,8 +254,8 @@ def run_superlink() -> None:
|
|
|
267
254
|
fleet_thread = threading.Thread(
|
|
268
255
|
target=_run_fleet_api_rest,
|
|
269
256
|
args=(
|
|
270
|
-
|
|
271
|
-
|
|
257
|
+
host,
|
|
258
|
+
port,
|
|
272
259
|
ssl_keyfile,
|
|
273
260
|
ssl_certfile,
|
|
274
261
|
state_factory,
|
|
@@ -325,6 +312,16 @@ def run_superlink() -> None:
|
|
|
325
312
|
driver_server.wait_for_termination(timeout=1)
|
|
326
313
|
|
|
327
314
|
|
|
315
|
+
def _format_address(address: str) -> Tuple[str, str, int]:
|
|
316
|
+
parsed_address = parse_address(address)
|
|
317
|
+
if not parsed_address:
|
|
318
|
+
sys.exit(
|
|
319
|
+
f"Address ({address}) cannot be parsed (expected: URL or IPv4 or IPv6)."
|
|
320
|
+
)
|
|
321
|
+
host, port, is_v6 = parsed_address
|
|
322
|
+
return (f"[{host}]:{port}" if is_v6 else f"{host}:{port}", host, port)
|
|
323
|
+
|
|
324
|
+
|
|
328
325
|
def _try_setup_client_authentication(
|
|
329
326
|
args: argparse.Namespace,
|
|
330
327
|
certificates: Optional[Tuple[bytes, bytes, bytes]],
|
|
@@ -53,6 +53,7 @@ def run_simulation_from_cli() -> None:
|
|
|
53
53
|
backend_name=args.backend,
|
|
54
54
|
backend_config=backend_config_dict,
|
|
55
55
|
app_dir=args.app_dir,
|
|
56
|
+
run_id=args.run_id,
|
|
56
57
|
enable_tf_gpu_growth=args.enable_tf_gpu_growth,
|
|
57
58
|
verbose_logging=args.verbose,
|
|
58
59
|
)
|
|
@@ -168,6 +169,13 @@ def run_serverapp_th(
|
|
|
168
169
|
return serverapp_th
|
|
169
170
|
|
|
170
171
|
|
|
172
|
+
def _init_run_id(driver: InMemoryDriver, state: StateFactory, run_id: int) -> None:
|
|
173
|
+
"""Create a run with a given `run_id`."""
|
|
174
|
+
log(DEBUG, "Pre-registering run with id %s", run_id)
|
|
175
|
+
state.state().run_ids[run_id] = ("", "") # type: ignore
|
|
176
|
+
driver.run_id = run_id
|
|
177
|
+
|
|
178
|
+
|
|
171
179
|
# pylint: disable=too-many-locals
|
|
172
180
|
def _main_loop(
|
|
173
181
|
num_supernodes: int,
|
|
@@ -175,6 +183,7 @@ def _main_loop(
|
|
|
175
183
|
backend_config_stream: str,
|
|
176
184
|
app_dir: str,
|
|
177
185
|
enable_tf_gpu_growth: bool,
|
|
186
|
+
run_id: Optional[int] = None,
|
|
178
187
|
client_app: Optional[ClientApp] = None,
|
|
179
188
|
client_app_attr: Optional[str] = None,
|
|
180
189
|
server_app: Optional[ServerApp] = None,
|
|
@@ -195,6 +204,9 @@ def _main_loop(
|
|
|
195
204
|
# Initialize Driver
|
|
196
205
|
driver = InMemoryDriver(state_factory)
|
|
197
206
|
|
|
207
|
+
if run_id:
|
|
208
|
+
_init_run_id(driver, state_factory, run_id)
|
|
209
|
+
|
|
198
210
|
# Get and run ServerApp thread
|
|
199
211
|
serverapp_th = run_serverapp_th(
|
|
200
212
|
server_app_attr=server_app_attr,
|
|
@@ -244,6 +256,7 @@ def _run_simulation(
|
|
|
244
256
|
client_app_attr: Optional[str] = None,
|
|
245
257
|
server_app_attr: Optional[str] = None,
|
|
246
258
|
app_dir: str = "",
|
|
259
|
+
run_id: Optional[int] = None,
|
|
247
260
|
enable_tf_gpu_growth: bool = False,
|
|
248
261
|
verbose_logging: bool = False,
|
|
249
262
|
) -> None:
|
|
@@ -283,6 +296,9 @@ def _run_simulation(
|
|
|
283
296
|
Add specified directory to the PYTHONPATH and load `ClientApp` from there.
|
|
284
297
|
(Default: current working directory.)
|
|
285
298
|
|
|
299
|
+
run_id : Optional[int]
|
|
300
|
+
An integer specifying the ID of the run started when running this function.
|
|
301
|
+
|
|
286
302
|
enable_tf_gpu_growth : bool (default: False)
|
|
287
303
|
A boolean to indicate whether to enable GPU growth on the main thread. This is
|
|
288
304
|
desirable if you make use of a TensorFlow model on your `ServerApp` while
|
|
@@ -322,6 +338,7 @@ def _run_simulation(
|
|
|
322
338
|
backend_config_stream,
|
|
323
339
|
app_dir,
|
|
324
340
|
enable_tf_gpu_growth,
|
|
341
|
+
run_id,
|
|
325
342
|
client_app,
|
|
326
343
|
client_app_attr,
|
|
327
344
|
server_app,
|
|
@@ -413,5 +430,10 @@ def _parse_args_run_simulation() -> argparse.ArgumentParser:
|
|
|
413
430
|
"ClientApp and ServerApp from there."
|
|
414
431
|
" Default: current working directory.",
|
|
415
432
|
)
|
|
433
|
+
parser.add_argument(
|
|
434
|
+
"--run-id",
|
|
435
|
+
type=int,
|
|
436
|
+
help="Sets the ID of the run started by the Simulation Engine.",
|
|
437
|
+
)
|
|
416
438
|
|
|
417
439
|
return parser
|
|
@@ -0,0 +1,21 @@
|
|
|
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 SuperExec service."""
|
|
16
|
+
|
|
17
|
+
from .app import run_superexec as run_superexec
|
|
18
|
+
|
|
19
|
+
__all__ = [
|
|
20
|
+
"run_superexec",
|
|
21
|
+
]
|
flwr/superexec/app.py
ADDED
|
@@ -0,0 +1,178 @@
|
|
|
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 SuperExec app."""
|
|
16
|
+
|
|
17
|
+
import argparse
|
|
18
|
+
import sys
|
|
19
|
+
from logging import INFO, WARN
|
|
20
|
+
from pathlib import Path
|
|
21
|
+
from typing import Optional, Tuple
|
|
22
|
+
|
|
23
|
+
import grpc
|
|
24
|
+
|
|
25
|
+
from flwr.common import EventType, event, log
|
|
26
|
+
from flwr.common.address import parse_address
|
|
27
|
+
from flwr.common.constant import SUPEREXEC_DEFAULT_ADDRESS
|
|
28
|
+
from flwr.common.exit_handlers import register_exit_handlers
|
|
29
|
+
from flwr.common.object_ref import load_app, validate
|
|
30
|
+
|
|
31
|
+
from .exec_grpc import run_superexec_api_grpc
|
|
32
|
+
from .executor import Executor
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def run_superexec() -> None:
|
|
36
|
+
"""Run Flower SuperExec."""
|
|
37
|
+
log(INFO, "Starting Flower SuperExec")
|
|
38
|
+
|
|
39
|
+
event(EventType.RUN_SUPEREXEC_ENTER)
|
|
40
|
+
|
|
41
|
+
args = _parse_args_run_superexec().parse_args()
|
|
42
|
+
|
|
43
|
+
# Parse IP address
|
|
44
|
+
parsed_address = parse_address(args.address)
|
|
45
|
+
if not parsed_address:
|
|
46
|
+
sys.exit(f"SuperExec IP address ({args.address}) cannot be parsed.")
|
|
47
|
+
host, port, is_v6 = parsed_address
|
|
48
|
+
address = f"[{host}]:{port}" if is_v6 else f"{host}:{port}"
|
|
49
|
+
|
|
50
|
+
# Obtain certificates
|
|
51
|
+
certificates = _try_obtain_certificates(args)
|
|
52
|
+
|
|
53
|
+
# Start SuperExec API
|
|
54
|
+
superexec_server: grpc.Server = run_superexec_api_grpc(
|
|
55
|
+
address=address,
|
|
56
|
+
executor=_load_executor(args),
|
|
57
|
+
certificates=certificates,
|
|
58
|
+
)
|
|
59
|
+
|
|
60
|
+
grpc_servers = [superexec_server]
|
|
61
|
+
|
|
62
|
+
# Graceful shutdown
|
|
63
|
+
register_exit_handlers(
|
|
64
|
+
event_type=EventType.RUN_SUPEREXEC_LEAVE,
|
|
65
|
+
grpc_servers=grpc_servers,
|
|
66
|
+
bckg_threads=None,
|
|
67
|
+
)
|
|
68
|
+
|
|
69
|
+
superexec_server.wait_for_termination()
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def _parse_args_run_superexec() -> argparse.ArgumentParser:
|
|
73
|
+
"""Parse command line arguments for SuperExec."""
|
|
74
|
+
parser = argparse.ArgumentParser(
|
|
75
|
+
description="Start a Flower SuperExec",
|
|
76
|
+
)
|
|
77
|
+
parser.add_argument(
|
|
78
|
+
"executor",
|
|
79
|
+
help="For example: `deployment:exec` or `project.package.module:wrapper.exec`.",
|
|
80
|
+
)
|
|
81
|
+
parser.add_argument(
|
|
82
|
+
"--address",
|
|
83
|
+
help="SuperExec (gRPC) server address (IPv4, IPv6, or a domain name)",
|
|
84
|
+
default=SUPEREXEC_DEFAULT_ADDRESS,
|
|
85
|
+
)
|
|
86
|
+
parser.add_argument(
|
|
87
|
+
"--executor-dir",
|
|
88
|
+
help="The directory for the executor.",
|
|
89
|
+
default=".",
|
|
90
|
+
)
|
|
91
|
+
parser.add_argument(
|
|
92
|
+
"--insecure",
|
|
93
|
+
action="store_true",
|
|
94
|
+
help="Run the SuperExec without HTTPS, regardless of whether certificate "
|
|
95
|
+
"paths are provided. By default, the server runs with HTTPS enabled. "
|
|
96
|
+
"Use this flag only if you understand the risks.",
|
|
97
|
+
)
|
|
98
|
+
parser.add_argument(
|
|
99
|
+
"--ssl-certfile",
|
|
100
|
+
help="SuperExec server SSL certificate file (as a path str) "
|
|
101
|
+
"to create a secure connection.",
|
|
102
|
+
type=str,
|
|
103
|
+
default=None,
|
|
104
|
+
)
|
|
105
|
+
parser.add_argument(
|
|
106
|
+
"--ssl-keyfile",
|
|
107
|
+
help="SuperExec server SSL private key file (as a path str) "
|
|
108
|
+
"to create a secure connection.",
|
|
109
|
+
type=str,
|
|
110
|
+
)
|
|
111
|
+
parser.add_argument(
|
|
112
|
+
"--ssl-ca-certfile",
|
|
113
|
+
help="SuperExec server SSL CA certificate file (as a path str) "
|
|
114
|
+
"to create a secure connection.",
|
|
115
|
+
type=str,
|
|
116
|
+
)
|
|
117
|
+
return parser
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
def _try_obtain_certificates(
|
|
121
|
+
args: argparse.Namespace,
|
|
122
|
+
) -> Optional[Tuple[bytes, bytes, bytes]]:
|
|
123
|
+
# Obtain certificates
|
|
124
|
+
if args.insecure:
|
|
125
|
+
log(WARN, "Option `--insecure` was set. Starting insecure HTTP server.")
|
|
126
|
+
return None
|
|
127
|
+
# Check if certificates are provided
|
|
128
|
+
if args.ssl_certfile and args.ssl_keyfile and args.ssl_ca_certfile:
|
|
129
|
+
if not Path.is_file(args.ssl_ca_certfile):
|
|
130
|
+
sys.exit("Path argument `--ssl-ca-certfile` does not point to a file.")
|
|
131
|
+
if not Path.is_file(args.ssl_certfile):
|
|
132
|
+
sys.exit("Path argument `--ssl-certfile` does not point to a file.")
|
|
133
|
+
if not Path.is_file(args.ssl_keyfile):
|
|
134
|
+
sys.exit("Path argument `--ssl-keyfile` does not point to a file.")
|
|
135
|
+
certificates = (
|
|
136
|
+
Path(args.ssl_ca_certfile).read_bytes(), # CA certificate
|
|
137
|
+
Path(args.ssl_certfile).read_bytes(), # server certificate
|
|
138
|
+
Path(args.ssl_keyfile).read_bytes(), # server private key
|
|
139
|
+
)
|
|
140
|
+
return certificates
|
|
141
|
+
if args.ssl_certfile or args.ssl_keyfile or args.ssl_ca_certfile:
|
|
142
|
+
sys.exit(
|
|
143
|
+
"You need to provide valid file paths to `--ssl-certfile`, "
|
|
144
|
+
"`--ssl-keyfile`, and `—-ssl-ca-certfile` to create a secure "
|
|
145
|
+
"connection in SuperExec server (gRPC-rere)."
|
|
146
|
+
)
|
|
147
|
+
sys.exit(
|
|
148
|
+
"Certificates are required unless running in insecure mode. "
|
|
149
|
+
"Please provide certificate paths to `--ssl-certfile`, "
|
|
150
|
+
"`--ssl-keyfile`, and `—-ssl-ca-certfile` or run the server "
|
|
151
|
+
"in insecure mode using '--insecure' if you understand the risks."
|
|
152
|
+
)
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
def _load_executor(
|
|
156
|
+
args: argparse.Namespace,
|
|
157
|
+
) -> Executor:
|
|
158
|
+
"""Get the executor plugin."""
|
|
159
|
+
if args.executor_dir is not None:
|
|
160
|
+
sys.path.insert(0, args.executor_dir)
|
|
161
|
+
|
|
162
|
+
executor_ref: str = args.executor
|
|
163
|
+
valid, error_msg = validate(executor_ref)
|
|
164
|
+
if not valid and error_msg:
|
|
165
|
+
raise LoadExecutorError(error_msg) from None
|
|
166
|
+
|
|
167
|
+
executor = load_app(executor_ref, LoadExecutorError)
|
|
168
|
+
|
|
169
|
+
if not isinstance(executor, Executor):
|
|
170
|
+
raise LoadExecutorError(
|
|
171
|
+
f"Attribute {executor_ref} is not of type {Executor}",
|
|
172
|
+
) from None
|
|
173
|
+
|
|
174
|
+
return executor
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
class LoadExecutorError(Exception):
|
|
178
|
+
"""Error when trying to load `Executor`."""
|
|
@@ -0,0 +1,51 @@
|
|
|
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
|
+
"""SuperExec gRPC API."""
|
|
16
|
+
|
|
17
|
+
from logging import INFO
|
|
18
|
+
from typing import Optional, Tuple
|
|
19
|
+
|
|
20
|
+
import grpc
|
|
21
|
+
|
|
22
|
+
from flwr.common import GRPC_MAX_MESSAGE_LENGTH
|
|
23
|
+
from flwr.common.logger import log
|
|
24
|
+
from flwr.proto.exec_pb2_grpc import add_ExecServicer_to_server
|
|
25
|
+
from flwr.server.superlink.fleet.grpc_bidi.grpc_server import generic_create_grpc_server
|
|
26
|
+
|
|
27
|
+
from .exec_servicer import ExecServicer
|
|
28
|
+
from .executor import Executor
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def run_superexec_api_grpc(
|
|
32
|
+
address: str,
|
|
33
|
+
executor: Executor,
|
|
34
|
+
certificates: Optional[Tuple[bytes, bytes, bytes]],
|
|
35
|
+
) -> grpc.Server:
|
|
36
|
+
"""Run SuperExec API (gRPC, request-response)."""
|
|
37
|
+
exec_servicer: grpc.Server = ExecServicer(
|
|
38
|
+
executor=executor,
|
|
39
|
+
)
|
|
40
|
+
superexec_add_servicer_to_server_fn = add_ExecServicer_to_server
|
|
41
|
+
superexec_grpc_server = generic_create_grpc_server(
|
|
42
|
+
servicer_and_add_fn=(exec_servicer, superexec_add_servicer_to_server_fn),
|
|
43
|
+
server_address=address,
|
|
44
|
+
max_message_length=GRPC_MAX_MESSAGE_LENGTH,
|
|
45
|
+
certificates=certificates,
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
log(INFO, "Flower ECE: Starting SuperExec API (gRPC-rere) on %s", address)
|
|
49
|
+
superexec_grpc_server.start()
|
|
50
|
+
|
|
51
|
+
return superexec_grpc_server
|
|
@@ -0,0 +1,54 @@
|
|
|
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
|
+
"""SuperExec API servicer."""
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
from logging import ERROR, INFO
|
|
19
|
+
from typing import Dict
|
|
20
|
+
|
|
21
|
+
import grpc
|
|
22
|
+
|
|
23
|
+
from flwr.common.logger import log
|
|
24
|
+
from flwr.proto import exec_pb2_grpc # pylint: disable=E0611
|
|
25
|
+
from flwr.proto.exec_pb2 import ( # pylint: disable=E0611
|
|
26
|
+
StartRunRequest,
|
|
27
|
+
StartRunResponse,
|
|
28
|
+
)
|
|
29
|
+
|
|
30
|
+
from .executor import Executor, RunTracker
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
class ExecServicer(exec_pb2_grpc.ExecServicer):
|
|
34
|
+
"""SuperExec API servicer."""
|
|
35
|
+
|
|
36
|
+
def __init__(self, executor: Executor) -> None:
|
|
37
|
+
self.executor = executor
|
|
38
|
+
self.runs: Dict[int, RunTracker] = {}
|
|
39
|
+
|
|
40
|
+
def StartRun(
|
|
41
|
+
self, request: StartRunRequest, context: grpc.ServicerContext
|
|
42
|
+
) -> StartRunResponse:
|
|
43
|
+
"""Create run ID."""
|
|
44
|
+
log(INFO, "ExecServicer.StartRun")
|
|
45
|
+
|
|
46
|
+
run = self.executor.start_run(request.fab_file)
|
|
47
|
+
|
|
48
|
+
if run is None:
|
|
49
|
+
log(ERROR, "Executor failed to start run")
|
|
50
|
+
return StartRunResponse()
|
|
51
|
+
|
|
52
|
+
self.runs[run.run_id] = run
|
|
53
|
+
|
|
54
|
+
return StartRunResponse(run_id=run.run_id)
|
|
@@ -0,0 +1,54 @@
|
|
|
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
|
+
"""Execute and monitor a Flower run."""
|
|
16
|
+
|
|
17
|
+
from abc import ABC, abstractmethod
|
|
18
|
+
from dataclasses import dataclass
|
|
19
|
+
from subprocess import Popen
|
|
20
|
+
from typing import Optional
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
@dataclass
|
|
24
|
+
class RunTracker:
|
|
25
|
+
"""Track a Flower run (composed of a run_id and the associated process)."""
|
|
26
|
+
|
|
27
|
+
run_id: int
|
|
28
|
+
proc: Popen # type: ignore
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
class Executor(ABC):
|
|
32
|
+
"""Execute and monitor a Flower run."""
|
|
33
|
+
|
|
34
|
+
@abstractmethod
|
|
35
|
+
def start_run(
|
|
36
|
+
self,
|
|
37
|
+
fab_file: bytes,
|
|
38
|
+
) -> Optional[RunTracker]:
|
|
39
|
+
"""Start a run using the given Flower FAB ID and version.
|
|
40
|
+
|
|
41
|
+
This method creates a new run on the SuperLink, returns its run_id
|
|
42
|
+
and also starts the run execution.
|
|
43
|
+
|
|
44
|
+
Parameters
|
|
45
|
+
----------
|
|
46
|
+
fab_file : bytes
|
|
47
|
+
The Flower App Bundle file bytes.
|
|
48
|
+
|
|
49
|
+
Returns
|
|
50
|
+
-------
|
|
51
|
+
run_id : Optional[RunTracker]
|
|
52
|
+
The run_id and the associated process of the run created by the SuperLink,
|
|
53
|
+
or `None` if it fails.
|
|
54
|
+
"""
|