flwr-nightly 1.14.0.dev20241204__py3-none-any.whl → 1.14.0.dev20241216__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/app.py +5 -0
- flwr/cli/build.py +1 -0
- flwr/cli/cli_user_auth_interceptor.py +86 -0
- flwr/cli/config_utils.py +19 -2
- flwr/cli/example.py +1 -0
- flwr/cli/install.py +1 -0
- flwr/cli/log.py +11 -31
- flwr/cli/login/__init__.py +22 -0
- flwr/cli/login/login.py +81 -0
- flwr/cli/ls.py +25 -55
- flwr/cli/new/__init__.py +1 -0
- flwr/cli/new/new.py +2 -1
- flwr/cli/new/templates/app/pyproject.flowertune.toml.tpl +2 -2
- flwr/cli/new/templates/app/pyproject.mlx.toml.tpl +1 -2
- flwr/cli/run/__init__.py +1 -0
- flwr/cli/run/run.py +17 -39
- flwr/cli/stop.py +129 -0
- flwr/cli/utils.py +96 -1
- flwr/client/app.py +14 -3
- flwr/client/client.py +1 -0
- flwr/client/clientapp/app.py +4 -1
- flwr/client/clientapp/utils.py +1 -0
- flwr/client/grpc_adapter_client/connection.py +1 -1
- flwr/client/grpc_client/connection.py +1 -1
- flwr/client/grpc_rere_client/connection.py +13 -7
- flwr/client/message_handler/message_handler.py +1 -0
- flwr/client/mod/comms_mods.py +1 -0
- flwr/client/mod/localdp_mod.py +1 -1
- flwr/client/nodestate/__init__.py +1 -0
- flwr/client/nodestate/nodestate.py +1 -0
- flwr/client/nodestate/nodestate_factory.py +1 -0
- flwr/client/rest_client/connection.py +3 -3
- flwr/client/supernode/app.py +1 -0
- flwr/common/address.py +1 -0
- flwr/common/args.py +1 -0
- flwr/common/auth_plugin/__init__.py +24 -0
- flwr/common/auth_plugin/auth_plugin.py +111 -0
- flwr/common/config.py +3 -1
- flwr/common/constant.py +6 -1
- flwr/common/logger.py +17 -1
- flwr/common/message.py +1 -0
- flwr/common/object_ref.py +57 -54
- flwr/common/pyproject.py +1 -0
- flwr/common/record/__init__.py +1 -0
- flwr/common/record/parametersrecord.py +1 -0
- flwr/common/retry_invoker.py +77 -0
- flwr/common/secure_aggregation/secaggplus_utils.py +2 -2
- flwr/common/telemetry.py +2 -1
- flwr/common/typing.py +12 -0
- flwr/common/version.py +1 -0
- flwr/proto/exec_pb2.py +27 -3
- flwr/proto/exec_pb2.pyi +103 -0
- flwr/proto/exec_pb2_grpc.py +102 -0
- flwr/proto/exec_pb2_grpc.pyi +39 -0
- flwr/proto/fab_pb2.py +4 -4
- flwr/proto/fab_pb2.pyi +4 -1
- flwr/proto/serverappio_pb2.py +18 -18
- flwr/proto/serverappio_pb2.pyi +8 -2
- flwr/proto/serverappio_pb2_grpc.py +34 -0
- flwr/proto/serverappio_pb2_grpc.pyi +13 -0
- flwr/proto/simulationio_pb2.py +2 -2
- flwr/proto/simulationio_pb2_grpc.py +34 -0
- flwr/proto/simulationio_pb2_grpc.pyi +13 -0
- flwr/server/app.py +52 -1
- flwr/server/compat/app_utils.py +7 -1
- flwr/server/driver/grpc_driver.py +11 -63
- flwr/server/driver/inmemory_driver.py +5 -1
- flwr/server/serverapp/app.py +9 -2
- flwr/server/strategy/dpfedavg_fixed.py +1 -0
- flwr/server/superlink/driver/serverappio_grpc.py +1 -0
- flwr/server/superlink/driver/serverappio_servicer.py +72 -22
- flwr/server/superlink/ffs/disk_ffs.py +1 -0
- flwr/server/superlink/fleet/grpc_adapter/grpc_adapter_servicer.py +1 -0
- flwr/server/superlink/fleet/grpc_bidi/flower_service_servicer.py +1 -0
- flwr/server/superlink/fleet/grpc_rere/fleet_servicer.py +32 -12
- flwr/server/superlink/fleet/message_handler/message_handler.py +32 -5
- flwr/server/superlink/fleet/rest_rere/rest_api.py +4 -1
- flwr/server/superlink/fleet/vce/__init__.py +1 -0
- flwr/server/superlink/fleet/vce/backend/__init__.py +1 -0
- flwr/server/superlink/fleet/vce/backend/raybackend.py +1 -0
- flwr/server/superlink/linkstate/in_memory_linkstate.py +14 -30
- flwr/server/superlink/linkstate/linkstate.py +13 -2
- flwr/server/superlink/linkstate/sqlite_linkstate.py +24 -44
- flwr/server/superlink/simulation/simulationio_servicer.py +20 -0
- flwr/server/superlink/utils.py +65 -0
- flwr/simulation/app.py +1 -0
- flwr/simulation/ray_transport/ray_actor.py +1 -0
- flwr/simulation/ray_transport/utils.py +1 -0
- flwr/simulation/run_simulation.py +1 -15
- flwr/simulation/simulationio_connection.py +3 -0
- flwr/superexec/app.py +1 -0
- flwr/superexec/deployment.py +1 -0
- flwr/superexec/exec_grpc.py +19 -1
- flwr/superexec/exec_servicer.py +76 -2
- flwr/superexec/exec_user_auth_interceptor.py +101 -0
- flwr/superexec/executor.py +1 -0
- {flwr_nightly-1.14.0.dev20241204.dist-info → flwr_nightly-1.14.0.dev20241216.dist-info}/METADATA +8 -7
- {flwr_nightly-1.14.0.dev20241204.dist-info → flwr_nightly-1.14.0.dev20241216.dist-info}/RECORD +101 -93
- {flwr_nightly-1.14.0.dev20241204.dist-info → flwr_nightly-1.14.0.dev20241216.dist-info}/LICENSE +0 -0
- {flwr_nightly-1.14.0.dev20241204.dist-info → flwr_nightly-1.14.0.dev20241216.dist-info}/WHEEL +0 -0
- {flwr_nightly-1.14.0.dev20241204.dist-info → flwr_nightly-1.14.0.dev20241216.dist-info}/entry_points.txt +0 -0
flwr/cli/app.py
CHANGED
|
@@ -14,15 +14,18 @@
|
|
|
14
14
|
# ==============================================================================
|
|
15
15
|
"""Flower command line interface."""
|
|
16
16
|
|
|
17
|
+
|
|
17
18
|
import typer
|
|
18
19
|
from typer.main import get_command
|
|
19
20
|
|
|
20
21
|
from .build import build
|
|
21
22
|
from .install import install
|
|
22
23
|
from .log import log
|
|
24
|
+
from .login import login
|
|
23
25
|
from .ls import ls
|
|
24
26
|
from .new import new
|
|
25
27
|
from .run import run
|
|
28
|
+
from .stop import stop
|
|
26
29
|
|
|
27
30
|
app = typer.Typer(
|
|
28
31
|
help=typer.style(
|
|
@@ -39,6 +42,8 @@ app.command()(build)
|
|
|
39
42
|
app.command()(install)
|
|
40
43
|
app.command()(log)
|
|
41
44
|
app.command()(ls)
|
|
45
|
+
app.command()(stop)
|
|
46
|
+
app.command()(login)
|
|
42
47
|
|
|
43
48
|
typer_click_object = get_command(app)
|
|
44
49
|
|
flwr/cli/build.py
CHANGED
|
@@ -0,0 +1,86 @@
|
|
|
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 run interceptor."""
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
from typing import Any, Callable, Union
|
|
19
|
+
|
|
20
|
+
import grpc
|
|
21
|
+
|
|
22
|
+
from flwr.common.auth_plugin import CliAuthPlugin
|
|
23
|
+
from flwr.proto.exec_pb2 import ( # pylint: disable=E0611
|
|
24
|
+
StartRunRequest,
|
|
25
|
+
StreamLogsRequest,
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
Request = Union[
|
|
29
|
+
StartRunRequest,
|
|
30
|
+
StreamLogsRequest,
|
|
31
|
+
]
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
class CliUserAuthInterceptor(
|
|
35
|
+
grpc.UnaryUnaryClientInterceptor, grpc.UnaryStreamClientInterceptor # type: ignore
|
|
36
|
+
):
|
|
37
|
+
"""CLI interceptor for user authentication."""
|
|
38
|
+
|
|
39
|
+
def __init__(self, auth_plugin: CliAuthPlugin):
|
|
40
|
+
self.auth_plugin = auth_plugin
|
|
41
|
+
|
|
42
|
+
def _authenticated_call(
|
|
43
|
+
self,
|
|
44
|
+
continuation: Callable[[Any, Any], Any],
|
|
45
|
+
client_call_details: grpc.ClientCallDetails,
|
|
46
|
+
request: Request,
|
|
47
|
+
) -> grpc.Call:
|
|
48
|
+
"""Send and receive tokens via metadata."""
|
|
49
|
+
new_metadata = self.auth_plugin.write_tokens_to_metadata(
|
|
50
|
+
client_call_details.metadata or []
|
|
51
|
+
)
|
|
52
|
+
|
|
53
|
+
details = client_call_details._replace(metadata=new_metadata)
|
|
54
|
+
|
|
55
|
+
response = continuation(details, request)
|
|
56
|
+
if response.initial_metadata():
|
|
57
|
+
retrieved_metadata = dict(response.initial_metadata())
|
|
58
|
+
self.auth_plugin.store_tokens(retrieved_metadata)
|
|
59
|
+
|
|
60
|
+
return response
|
|
61
|
+
|
|
62
|
+
def intercept_unary_unary(
|
|
63
|
+
self,
|
|
64
|
+
continuation: Callable[[Any, Any], Any],
|
|
65
|
+
client_call_details: grpc.ClientCallDetails,
|
|
66
|
+
request: Request,
|
|
67
|
+
) -> grpc.Call:
|
|
68
|
+
"""Intercept a unary-unary call for user authentication.
|
|
69
|
+
|
|
70
|
+
This method intercepts a unary-unary RPC call initiated from the CLI and adds
|
|
71
|
+
the required authentication tokens to the RPC metadata.
|
|
72
|
+
"""
|
|
73
|
+
return self._authenticated_call(continuation, client_call_details, request)
|
|
74
|
+
|
|
75
|
+
def intercept_unary_stream(
|
|
76
|
+
self,
|
|
77
|
+
continuation: Callable[[Any, Any], Any],
|
|
78
|
+
client_call_details: grpc.ClientCallDetails,
|
|
79
|
+
request: Request,
|
|
80
|
+
) -> grpc.Call:
|
|
81
|
+
"""Intercept a unary-stream call for user authentication.
|
|
82
|
+
|
|
83
|
+
This method intercepts a unary-stream RPC call initiated from the CLI and adds
|
|
84
|
+
the required authentication tokens to the RPC metadata.
|
|
85
|
+
"""
|
|
86
|
+
return self._authenticated_call(continuation, client_call_details, request)
|
flwr/cli/config_utils.py
CHANGED
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
# ==============================================================================
|
|
15
15
|
"""Utility to validate the `pyproject.toml` file."""
|
|
16
16
|
|
|
17
|
+
|
|
17
18
|
import zipfile
|
|
18
19
|
from io import BytesIO
|
|
19
20
|
from pathlib import Path
|
|
@@ -230,10 +231,14 @@ def load_from_string(toml_content: str) -> Optional[dict[str, Any]]:
|
|
|
230
231
|
return None
|
|
231
232
|
|
|
232
233
|
|
|
233
|
-
def
|
|
234
|
+
def process_loaded_project_config(
|
|
234
235
|
config: Union[dict[str, Any], None], errors: list[str], warnings: list[str]
|
|
235
236
|
) -> dict[str, Any]:
|
|
236
|
-
"""
|
|
237
|
+
"""Process and return the loaded project configuration.
|
|
238
|
+
|
|
239
|
+
This function handles errors and warnings from the `load_and_validate` function,
|
|
240
|
+
exits on critical issues, and returns the validated configuration.
|
|
241
|
+
"""
|
|
237
242
|
if config is None:
|
|
238
243
|
typer.secho(
|
|
239
244
|
"Project configuration could not be loaded.\n"
|
|
@@ -324,3 +329,15 @@ def validate_certificate_in_federation_config(
|
|
|
324
329
|
raise typer.Exit(code=1)
|
|
325
330
|
|
|
326
331
|
return insecure, root_certificates_bytes
|
|
332
|
+
|
|
333
|
+
|
|
334
|
+
def exit_if_no_address(federation_config: dict[str, Any], cmd: str) -> None:
|
|
335
|
+
"""Exit if the provided federation_config has no "address" key."""
|
|
336
|
+
if "address" not in federation_config:
|
|
337
|
+
typer.secho(
|
|
338
|
+
f"❌ `flwr {cmd}` currently works with a SuperLink. Ensure that the correct"
|
|
339
|
+
"SuperLink (Exec API) address is provided in `pyproject.toml`.",
|
|
340
|
+
fg=typer.colors.RED,
|
|
341
|
+
bold=True,
|
|
342
|
+
)
|
|
343
|
+
raise typer.Exit(code=1)
|
flwr/cli/example.py
CHANGED
flwr/cli/install.py
CHANGED
flwr/cli/log.py
CHANGED
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
# ==============================================================================
|
|
15
15
|
"""Flower command line interface `log` command."""
|
|
16
16
|
|
|
17
|
+
|
|
17
18
|
import time
|
|
18
19
|
from logging import DEBUG, ERROR, INFO
|
|
19
20
|
from pathlib import Path
|
|
@@ -23,17 +24,18 @@ import grpc
|
|
|
23
24
|
import typer
|
|
24
25
|
|
|
25
26
|
from flwr.cli.config_utils import (
|
|
27
|
+
exit_if_no_address,
|
|
26
28
|
load_and_validate,
|
|
27
|
-
|
|
29
|
+
process_loaded_project_config,
|
|
28
30
|
validate_federation_in_project_config,
|
|
29
|
-
validate_project_config,
|
|
30
31
|
)
|
|
31
32
|
from flwr.common.constant import CONN_RECONNECT_INTERVAL, CONN_REFRESH_PERIOD
|
|
32
|
-
from flwr.common.grpc import GRPC_MAX_MESSAGE_LENGTH, create_channel
|
|
33
33
|
from flwr.common.logger import log as logger
|
|
34
34
|
from flwr.proto.exec_pb2 import StreamLogsRequest # pylint: disable=E0611
|
|
35
35
|
from flwr.proto.exec_pb2_grpc import ExecStub
|
|
36
36
|
|
|
37
|
+
from .utils import init_channel, try_obtain_cli_auth_plugin
|
|
38
|
+
|
|
37
39
|
|
|
38
40
|
def start_stream(
|
|
39
41
|
run_id: int, channel: grpc.Channel, refresh_period: int = CONN_REFRESH_PERIOD
|
|
@@ -126,11 +128,6 @@ def print_logs(run_id: int, channel: grpc.Channel, timeout: int) -> None:
|
|
|
126
128
|
logger(DEBUG, "Channel closed")
|
|
127
129
|
|
|
128
130
|
|
|
129
|
-
def on_channel_state_change(channel_connectivity: str) -> None:
|
|
130
|
-
"""Log channel connectivity."""
|
|
131
|
-
logger(DEBUG, channel_connectivity)
|
|
132
|
-
|
|
133
|
-
|
|
134
131
|
def log(
|
|
135
132
|
run_id: Annotated[
|
|
136
133
|
int,
|
|
@@ -157,41 +154,24 @@ def log(
|
|
|
157
154
|
|
|
158
155
|
pyproject_path = app / "pyproject.toml" if app else None
|
|
159
156
|
config, errors, warnings = load_and_validate(path=pyproject_path)
|
|
160
|
-
config =
|
|
157
|
+
config = process_loaded_project_config(config, errors, warnings)
|
|
161
158
|
federation, federation_config = validate_federation_in_project_config(
|
|
162
159
|
federation, config
|
|
163
160
|
)
|
|
161
|
+
exit_if_no_address(federation_config, "log")
|
|
164
162
|
|
|
165
|
-
|
|
166
|
-
typer.secho(
|
|
167
|
-
"❌ `flwr log` currently works with Exec API. Ensure that the correct"
|
|
168
|
-
"Exec API address is provided in the `pyproject.toml`.",
|
|
169
|
-
fg=typer.colors.RED,
|
|
170
|
-
bold=True,
|
|
171
|
-
)
|
|
172
|
-
raise typer.Exit(code=1)
|
|
173
|
-
|
|
174
|
-
_log_with_exec_api(app, federation_config, run_id, stream)
|
|
163
|
+
_log_with_exec_api(app, federation, federation_config, run_id, stream)
|
|
175
164
|
|
|
176
165
|
|
|
177
166
|
def _log_with_exec_api(
|
|
178
167
|
app: Path,
|
|
168
|
+
federation: str,
|
|
179
169
|
federation_config: dict[str, Any],
|
|
180
170
|
run_id: int,
|
|
181
171
|
stream: bool,
|
|
182
172
|
) -> None:
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
app, federation_config
|
|
186
|
-
)
|
|
187
|
-
channel = create_channel(
|
|
188
|
-
server_address=federation_config["address"],
|
|
189
|
-
insecure=insecure,
|
|
190
|
-
root_certificates=root_certificates_bytes,
|
|
191
|
-
max_message_length=GRPC_MAX_MESSAGE_LENGTH,
|
|
192
|
-
interceptors=None,
|
|
193
|
-
)
|
|
194
|
-
channel.subscribe(on_channel_state_change)
|
|
173
|
+
auth_plugin = try_obtain_cli_auth_plugin(app, federation)
|
|
174
|
+
channel = init_channel(app, federation_config, auth_plugin)
|
|
195
175
|
|
|
196
176
|
if stream:
|
|
197
177
|
start_stream(run_id, channel, CONN_REFRESH_PERIOD)
|
|
@@ -0,0 +1,22 @@
|
|
|
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 command line interface `login` command."""
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
from .login import login as login
|
|
19
|
+
|
|
20
|
+
__all__ = [
|
|
21
|
+
"login",
|
|
22
|
+
]
|
flwr/cli/login/login.py
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
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 command line interface `login` command."""
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
from pathlib import Path
|
|
19
|
+
from typing import Annotated, Optional
|
|
20
|
+
|
|
21
|
+
import typer
|
|
22
|
+
|
|
23
|
+
from flwr.cli.config_utils import (
|
|
24
|
+
exit_if_no_address,
|
|
25
|
+
load_and_validate,
|
|
26
|
+
process_loaded_project_config,
|
|
27
|
+
validate_federation_in_project_config,
|
|
28
|
+
)
|
|
29
|
+
from flwr.common.constant import AUTH_TYPE
|
|
30
|
+
from flwr.proto.exec_pb2 import ( # pylint: disable=E0611
|
|
31
|
+
GetLoginDetailsRequest,
|
|
32
|
+
GetLoginDetailsResponse,
|
|
33
|
+
)
|
|
34
|
+
from flwr.proto.exec_pb2_grpc import ExecStub
|
|
35
|
+
|
|
36
|
+
from ..utils import init_channel, try_obtain_cli_auth_plugin
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def login( # pylint: disable=R0914
|
|
40
|
+
app: Annotated[
|
|
41
|
+
Path,
|
|
42
|
+
typer.Argument(help="Path of the Flower App to run."),
|
|
43
|
+
] = Path("."),
|
|
44
|
+
federation: Annotated[
|
|
45
|
+
Optional[str],
|
|
46
|
+
typer.Argument(help="Name of the federation to login into."),
|
|
47
|
+
] = None,
|
|
48
|
+
) -> None:
|
|
49
|
+
"""Login to Flower SuperLink."""
|
|
50
|
+
typer.secho("Loading project configuration... ", fg=typer.colors.BLUE)
|
|
51
|
+
|
|
52
|
+
pyproject_path = app / "pyproject.toml" if app else None
|
|
53
|
+
config, errors, warnings = load_and_validate(path=pyproject_path)
|
|
54
|
+
|
|
55
|
+
config = process_loaded_project_config(config, errors, warnings)
|
|
56
|
+
federation, federation_config = validate_federation_in_project_config(
|
|
57
|
+
federation, config
|
|
58
|
+
)
|
|
59
|
+
exit_if_no_address(federation_config, "login")
|
|
60
|
+
channel = init_channel(app, federation_config, None)
|
|
61
|
+
stub = ExecStub(channel)
|
|
62
|
+
|
|
63
|
+
login_request = GetLoginDetailsRequest()
|
|
64
|
+
login_response: GetLoginDetailsResponse = stub.GetLoginDetails(login_request)
|
|
65
|
+
|
|
66
|
+
# Get the auth plugin
|
|
67
|
+
auth_type = login_response.login_details.get(AUTH_TYPE)
|
|
68
|
+
auth_plugin = try_obtain_cli_auth_plugin(app, federation, auth_type)
|
|
69
|
+
if auth_plugin is None:
|
|
70
|
+
typer.secho(
|
|
71
|
+
f'❌ Authentication type "{auth_type}" not found',
|
|
72
|
+
fg=typer.colors.RED,
|
|
73
|
+
bold=True,
|
|
74
|
+
)
|
|
75
|
+
raise typer.Exit(code=1)
|
|
76
|
+
|
|
77
|
+
# Login
|
|
78
|
+
auth_config = auth_plugin.login(dict(login_response.login_details), stub)
|
|
79
|
+
|
|
80
|
+
# Store the tokens
|
|
81
|
+
auth_plugin.store_tokens(auth_config)
|
flwr/cli/ls.py
CHANGED
|
@@ -18,27 +18,23 @@
|
|
|
18
18
|
import io
|
|
19
19
|
import json
|
|
20
20
|
from datetime import datetime, timedelta
|
|
21
|
-
from logging import DEBUG
|
|
22
21
|
from pathlib import Path
|
|
23
|
-
from typing import Annotated,
|
|
22
|
+
from typing import Annotated, Optional
|
|
24
23
|
|
|
25
|
-
import grpc
|
|
26
24
|
import typer
|
|
27
25
|
from rich.console import Console
|
|
28
26
|
from rich.table import Table
|
|
29
27
|
from rich.text import Text
|
|
30
|
-
from typer import Exit
|
|
31
28
|
|
|
32
29
|
from flwr.cli.config_utils import (
|
|
30
|
+
exit_if_no_address,
|
|
33
31
|
load_and_validate,
|
|
34
|
-
|
|
32
|
+
process_loaded_project_config,
|
|
35
33
|
validate_federation_in_project_config,
|
|
36
|
-
validate_project_config,
|
|
37
34
|
)
|
|
38
35
|
from flwr.common.constant import FAB_CONFIG_FILE, CliOutputFormat, SubStatus
|
|
39
36
|
from flwr.common.date import format_timedelta, isoformat8601_utc
|
|
40
|
-
from flwr.common.
|
|
41
|
-
from flwr.common.logger import log, redirect_output, remove_emojis, restore_output
|
|
37
|
+
from flwr.common.logger import print_json_error, redirect_output, restore_output
|
|
42
38
|
from flwr.common.serde import run_from_proto
|
|
43
39
|
from flwr.common.typing import Run
|
|
44
40
|
from flwr.proto.exec_pb2 import ( # pylint: disable=E0611
|
|
@@ -47,6 +43,8 @@ from flwr.proto.exec_pb2 import ( # pylint: disable=E0611
|
|
|
47
43
|
)
|
|
48
44
|
from flwr.proto.exec_pb2_grpc import ExecStub
|
|
49
45
|
|
|
46
|
+
from .utils import init_channel, try_obtain_cli_auth_plugin
|
|
47
|
+
|
|
50
48
|
_RunListType = tuple[int, str, str, str, str, str, str, str, str]
|
|
51
49
|
|
|
52
50
|
|
|
@@ -82,7 +80,20 @@ def ls( # pylint: disable=too-many-locals, too-many-branches
|
|
|
82
80
|
),
|
|
83
81
|
] = CliOutputFormat.DEFAULT,
|
|
84
82
|
) -> None:
|
|
85
|
-
"""List runs.
|
|
83
|
+
"""List the details of one provided run ID or all runs in a Flower federation.
|
|
84
|
+
|
|
85
|
+
The following details are displayed:
|
|
86
|
+
|
|
87
|
+
- **Run ID:** Unique identifier for the run.
|
|
88
|
+
- **FAB:** Name of the FAB associated with the run (``{FAB_ID} (v{FAB_VERSION})``).
|
|
89
|
+
- **Status:** Current status of the run (pending, starting, running, finished).
|
|
90
|
+
- **Elapsed:** Time elapsed since the run started (``HH:MM:SS``).
|
|
91
|
+
- **Created At:** Timestamp when the run was created.
|
|
92
|
+
- **Running At:** Timestamp when the run started running.
|
|
93
|
+
- **Finished At:** Timestamp when the run finished.
|
|
94
|
+
|
|
95
|
+
All timestamps follow ISO 8601, UTC and are formatted as ``YYYY-MM-DD HH:MM:SSZ``.
|
|
96
|
+
"""
|
|
86
97
|
suppress_output = output_format == CliOutputFormat.JSON
|
|
87
98
|
captured_output = io.StringIO()
|
|
88
99
|
try:
|
|
@@ -94,27 +105,19 @@ def ls( # pylint: disable=too-many-locals, too-many-branches
|
|
|
94
105
|
|
|
95
106
|
pyproject_path = app / FAB_CONFIG_FILE if app else None
|
|
96
107
|
config, errors, warnings = load_and_validate(path=pyproject_path)
|
|
97
|
-
config =
|
|
108
|
+
config = process_loaded_project_config(config, errors, warnings)
|
|
98
109
|
federation, federation_config = validate_federation_in_project_config(
|
|
99
110
|
federation, config
|
|
100
111
|
)
|
|
101
|
-
|
|
102
|
-
if "address" not in federation_config:
|
|
103
|
-
typer.secho(
|
|
104
|
-
"❌ `flwr ls` currently works with Exec API. Ensure that the correct"
|
|
105
|
-
"Exec API address is provided in the `pyproject.toml`.",
|
|
106
|
-
fg=typer.colors.RED,
|
|
107
|
-
bold=True,
|
|
108
|
-
)
|
|
109
|
-
raise typer.Exit(code=1)
|
|
112
|
+
exit_if_no_address(federation_config, "ls")
|
|
110
113
|
|
|
111
114
|
try:
|
|
112
115
|
if runs and run_id is not None:
|
|
113
116
|
raise ValueError(
|
|
114
117
|
"The options '--runs' and '--run-id' are mutually exclusive."
|
|
115
118
|
)
|
|
116
|
-
|
|
117
|
-
channel =
|
|
119
|
+
auth_plugin = try_obtain_cli_auth_plugin(app, federation)
|
|
120
|
+
channel = init_channel(app, federation_config, auth_plugin)
|
|
118
121
|
stub = ExecStub(channel)
|
|
119
122
|
|
|
120
123
|
# Display information about a specific run ID
|
|
@@ -141,7 +144,7 @@ def ls( # pylint: disable=too-many-locals, too-many-branches
|
|
|
141
144
|
if suppress_output:
|
|
142
145
|
restore_output()
|
|
143
146
|
e_message = captured_output.getvalue()
|
|
144
|
-
|
|
147
|
+
print_json_error(e_message, err)
|
|
145
148
|
else:
|
|
146
149
|
typer.secho(
|
|
147
150
|
f"{err}",
|
|
@@ -154,27 +157,6 @@ def ls( # pylint: disable=too-many-locals, too-many-branches
|
|
|
154
157
|
captured_output.close()
|
|
155
158
|
|
|
156
159
|
|
|
157
|
-
def on_channel_state_change(channel_connectivity: str) -> None:
|
|
158
|
-
"""Log channel connectivity."""
|
|
159
|
-
log(DEBUG, channel_connectivity)
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
def _init_channel(app: Path, federation_config: dict[str, Any]) -> grpc.Channel:
|
|
163
|
-
"""Initialize gRPC channel to the Exec API."""
|
|
164
|
-
insecure, root_certificates_bytes = validate_certificate_in_federation_config(
|
|
165
|
-
app, federation_config
|
|
166
|
-
)
|
|
167
|
-
channel = create_channel(
|
|
168
|
-
server_address=federation_config["address"],
|
|
169
|
-
insecure=insecure,
|
|
170
|
-
root_certificates=root_certificates_bytes,
|
|
171
|
-
max_message_length=GRPC_MAX_MESSAGE_LENGTH,
|
|
172
|
-
interceptors=None,
|
|
173
|
-
)
|
|
174
|
-
channel.subscribe(on_channel_state_change)
|
|
175
|
-
return channel
|
|
176
|
-
|
|
177
|
-
|
|
178
160
|
def _format_runs(run_dict: dict[int, Run], now_isoformat: str) -> list[_RunListType]:
|
|
179
161
|
"""Format runs to a list."""
|
|
180
162
|
|
|
@@ -340,15 +322,3 @@ def _display_one_run(
|
|
|
340
322
|
Console().print_json(_to_json(formatted_runs))
|
|
341
323
|
else:
|
|
342
324
|
Console().print(_to_table(formatted_runs))
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
def _print_json_error(msg: str, e: Union[Exit, Exception]) -> None:
|
|
346
|
-
"""Print error message as JSON."""
|
|
347
|
-
Console().print_json(
|
|
348
|
-
json.dumps(
|
|
349
|
-
{
|
|
350
|
-
"success": False,
|
|
351
|
-
"error-message": remove_emojis(str(msg) + "\n" + str(e)),
|
|
352
|
-
}
|
|
353
|
-
)
|
|
354
|
-
)
|
flwr/cli/new/__init__.py
CHANGED
flwr/cli/new/new.py
CHANGED
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
# ==============================================================================
|
|
15
15
|
"""Flower command line interface `new` command."""
|
|
16
16
|
|
|
17
|
+
|
|
17
18
|
import re
|
|
18
19
|
from enum import Enum
|
|
19
20
|
from pathlib import Path
|
|
@@ -81,7 +82,7 @@ def render_template(template: str, data: dict[str, str]) -> str:
|
|
|
81
82
|
def create_file(file_path: Path, content: str) -> None:
|
|
82
83
|
"""Create file including all nessecary directories and write content into file."""
|
|
83
84
|
file_path.parent.mkdir(exist_ok=True)
|
|
84
|
-
file_path.write_text(content)
|
|
85
|
+
file_path.write_text(content, encoding="utf-8")
|
|
85
86
|
|
|
86
87
|
|
|
87
88
|
def render_and_create(file_path: Path, template: str, context: dict[str, str]) -> None:
|
|
@@ -12,10 +12,10 @@ dependencies = [
|
|
|
12
12
|
"flwr-datasets>=0.3.0",
|
|
13
13
|
"torch==2.3.1",
|
|
14
14
|
"trl==0.8.1",
|
|
15
|
-
"bitsandbytes==0.
|
|
15
|
+
"bitsandbytes==0.45.0",
|
|
16
16
|
"scipy==1.13.0",
|
|
17
17
|
"peft==0.6.2",
|
|
18
|
-
"transformers==4.
|
|
18
|
+
"transformers==4.47.0",
|
|
19
19
|
"sentencepiece==0.2.0",
|
|
20
20
|
"omegaconf==2.3.0",
|
|
21
21
|
"hf_transfer==0.1.8",
|