flwr-nightly 1.14.0.dev20241204__py3-none-any.whl → 1.14.0.dev20241214__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.

Files changed (100) hide show
  1. flwr/cli/app.py +5 -0
  2. flwr/cli/build.py +1 -0
  3. flwr/cli/cli_user_auth_interceptor.py +86 -0
  4. flwr/cli/config_utils.py +19 -2
  5. flwr/cli/example.py +1 -0
  6. flwr/cli/install.py +1 -0
  7. flwr/cli/log.py +11 -31
  8. flwr/cli/login/__init__.py +22 -0
  9. flwr/cli/login/login.py +83 -0
  10. flwr/cli/ls.py +10 -40
  11. flwr/cli/new/__init__.py +1 -0
  12. flwr/cli/new/new.py +2 -1
  13. flwr/cli/new/templates/app/pyproject.flowertune.toml.tpl +2 -2
  14. flwr/cli/new/templates/app/pyproject.mlx.toml.tpl +1 -2
  15. flwr/cli/run/__init__.py +1 -0
  16. flwr/cli/run/run.py +15 -25
  17. flwr/cli/stop.py +91 -0
  18. flwr/cli/utils.py +109 -1
  19. flwr/client/app.py +3 -2
  20. flwr/client/client.py +1 -0
  21. flwr/client/clientapp/app.py +1 -0
  22. flwr/client/clientapp/utils.py +1 -0
  23. flwr/client/grpc_adapter_client/connection.py +1 -1
  24. flwr/client/grpc_client/connection.py +1 -1
  25. flwr/client/grpc_rere_client/connection.py +3 -3
  26. flwr/client/message_handler/message_handler.py +1 -0
  27. flwr/client/mod/comms_mods.py +1 -0
  28. flwr/client/mod/localdp_mod.py +1 -1
  29. flwr/client/nodestate/__init__.py +1 -0
  30. flwr/client/nodestate/nodestate.py +1 -0
  31. flwr/client/nodestate/nodestate_factory.py +1 -0
  32. flwr/client/rest_client/connection.py +3 -3
  33. flwr/client/supernode/app.py +1 -0
  34. flwr/common/address.py +1 -0
  35. flwr/common/args.py +1 -0
  36. flwr/common/auth_plugin/__init__.py +24 -0
  37. flwr/common/auth_plugin/auth_plugin.py +111 -0
  38. flwr/common/config.py +3 -1
  39. flwr/common/constant.py +6 -1
  40. flwr/common/logger.py +1 -0
  41. flwr/common/message.py +1 -0
  42. flwr/common/object_ref.py +57 -54
  43. flwr/common/pyproject.py +1 -0
  44. flwr/common/record/__init__.py +1 -0
  45. flwr/common/record/parametersrecord.py +1 -0
  46. flwr/common/retry_invoker.py +75 -0
  47. flwr/common/secure_aggregation/secaggplus_utils.py +2 -2
  48. flwr/common/telemetry.py +2 -1
  49. flwr/common/typing.py +12 -0
  50. flwr/common/version.py +1 -0
  51. flwr/proto/exec_pb2.py +27 -3
  52. flwr/proto/exec_pb2.pyi +103 -0
  53. flwr/proto/exec_pb2_grpc.py +102 -0
  54. flwr/proto/exec_pb2_grpc.pyi +39 -0
  55. flwr/proto/fab_pb2.py +4 -4
  56. flwr/proto/fab_pb2.pyi +4 -1
  57. flwr/proto/serverappio_pb2.py +18 -18
  58. flwr/proto/serverappio_pb2.pyi +8 -2
  59. flwr/proto/serverappio_pb2_grpc.py +34 -0
  60. flwr/proto/serverappio_pb2_grpc.pyi +13 -0
  61. flwr/proto/simulationio_pb2.py +2 -2
  62. flwr/proto/simulationio_pb2_grpc.py +34 -0
  63. flwr/proto/simulationio_pb2_grpc.pyi +13 -0
  64. flwr/server/app.py +53 -1
  65. flwr/server/compat/app_utils.py +7 -1
  66. flwr/server/driver/grpc_driver.py +11 -63
  67. flwr/server/driver/inmemory_driver.py +5 -1
  68. flwr/server/serverapp/app.py +9 -2
  69. flwr/server/strategy/dpfedavg_fixed.py +1 -0
  70. flwr/server/superlink/driver/serverappio_grpc.py +1 -0
  71. flwr/server/superlink/driver/serverappio_servicer.py +72 -22
  72. flwr/server/superlink/ffs/disk_ffs.py +1 -0
  73. flwr/server/superlink/fleet/grpc_adapter/grpc_adapter_servicer.py +1 -0
  74. flwr/server/superlink/fleet/grpc_bidi/flower_service_servicer.py +1 -0
  75. flwr/server/superlink/fleet/grpc_rere/fleet_servicer.py +32 -12
  76. flwr/server/superlink/fleet/message_handler/message_handler.py +31 -2
  77. flwr/server/superlink/fleet/rest_rere/rest_api.py +4 -1
  78. flwr/server/superlink/fleet/vce/__init__.py +1 -0
  79. flwr/server/superlink/fleet/vce/backend/__init__.py +1 -0
  80. flwr/server/superlink/fleet/vce/backend/raybackend.py +1 -0
  81. flwr/server/superlink/linkstate/in_memory_linkstate.py +14 -30
  82. flwr/server/superlink/linkstate/linkstate.py +13 -2
  83. flwr/server/superlink/linkstate/sqlite_linkstate.py +24 -44
  84. flwr/server/superlink/simulation/simulationio_servicer.py +20 -0
  85. flwr/server/superlink/utils.py +65 -0
  86. flwr/simulation/app.py +1 -0
  87. flwr/simulation/ray_transport/ray_actor.py +1 -0
  88. flwr/simulation/ray_transport/utils.py +1 -0
  89. flwr/simulation/run_simulation.py +1 -0
  90. flwr/superexec/app.py +1 -0
  91. flwr/superexec/deployment.py +1 -0
  92. flwr/superexec/exec_grpc.py +19 -1
  93. flwr/superexec/exec_servicer.py +76 -2
  94. flwr/superexec/exec_user_auth_interceptor.py +101 -0
  95. flwr/superexec/executor.py +1 -0
  96. {flwr_nightly-1.14.0.dev20241204.dist-info → flwr_nightly-1.14.0.dev20241214.dist-info}/METADATA +8 -7
  97. {flwr_nightly-1.14.0.dev20241204.dist-info → flwr_nightly-1.14.0.dev20241214.dist-info}/RECORD +100 -92
  98. {flwr_nightly-1.14.0.dev20241204.dist-info → flwr_nightly-1.14.0.dev20241214.dist-info}/LICENSE +0 -0
  99. {flwr_nightly-1.14.0.dev20241204.dist-info → flwr_nightly-1.14.0.dev20241214.dist-info}/WHEEL +0 -0
  100. {flwr_nightly-1.14.0.dev20241204.dist-info → flwr_nightly-1.14.0.dev20241214.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
@@ -14,6 +14,7 @@
14
14
  # ==============================================================================
15
15
  """Flower command line interface `build` command."""
16
16
 
17
+
17
18
  import hashlib
18
19
  import os
19
20
  import shutil
@@ -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 validate_project_config(
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
- """Validate and return the Flower project configuration."""
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
@@ -14,6 +14,7 @@
14
14
  # ==============================================================================
15
15
  """Flower command line interface `example` command."""
16
16
 
17
+
17
18
  import json
18
19
  import os
19
20
  import subprocess
flwr/cli/install.py CHANGED
@@ -14,6 +14,7 @@
14
14
  # ==============================================================================
15
15
  """Flower command line interface `install` command."""
16
16
 
17
+
17
18
  import hashlib
18
19
  import shutil
19
20
  import tempfile
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
- validate_certificate_in_federation_config,
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 = validate_project_config(config, errors, warnings)
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
- if "address" not in federation_config:
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
- insecure, root_certificates_bytes = validate_certificate_in_federation_config(
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, federation_config)
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
+ ]
@@ -0,0 +1,83 @@
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(
69
+ app, federation, federation_config, auth_type
70
+ )
71
+ if auth_plugin is None:
72
+ typer.secho(
73
+ f'❌ Authentication type "{auth_type}" not found',
74
+ fg=typer.colors.RED,
75
+ bold=True,
76
+ )
77
+ raise typer.Exit(code=1)
78
+
79
+ # Login
80
+ auth_config = auth_plugin.login(dict(login_response.login_details), stub)
81
+
82
+ # Store the tokens
83
+ auth_plugin.store_tokens(auth_config)
flwr/cli/ls.py CHANGED
@@ -18,11 +18,9 @@
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, Any, Optional, Union
22
+ from typing import Annotated, Optional, Union
24
23
 
25
- import grpc
26
24
  import typer
27
25
  from rich.console import Console
28
26
  from rich.table import Table
@@ -30,15 +28,14 @@ from rich.text import Text
30
28
  from typer import Exit
31
29
 
32
30
  from flwr.cli.config_utils import (
31
+ exit_if_no_address,
33
32
  load_and_validate,
34
- validate_certificate_in_federation_config,
33
+ process_loaded_project_config,
35
34
  validate_federation_in_project_config,
36
- validate_project_config,
37
35
  )
38
36
  from flwr.common.constant import FAB_CONFIG_FILE, CliOutputFormat, SubStatus
39
37
  from flwr.common.date import format_timedelta, isoformat8601_utc
40
- from flwr.common.grpc import GRPC_MAX_MESSAGE_LENGTH, create_channel
41
- from flwr.common.logger import log, redirect_output, remove_emojis, restore_output
38
+ from flwr.common.logger import redirect_output, remove_emojis, restore_output
42
39
  from flwr.common.serde import run_from_proto
43
40
  from flwr.common.typing import Run
44
41
  from flwr.proto.exec_pb2 import ( # pylint: disable=E0611
@@ -47,6 +44,8 @@ from flwr.proto.exec_pb2 import ( # pylint: disable=E0611
47
44
  )
48
45
  from flwr.proto.exec_pb2_grpc import ExecStub
49
46
 
47
+ from .utils import init_channel, try_obtain_cli_auth_plugin
48
+
50
49
  _RunListType = tuple[int, str, str, str, str, str, str, str, str]
51
50
 
52
51
 
@@ -94,27 +93,19 @@ def ls( # pylint: disable=too-many-locals, too-many-branches
94
93
 
95
94
  pyproject_path = app / FAB_CONFIG_FILE if app else None
96
95
  config, errors, warnings = load_and_validate(path=pyproject_path)
97
- config = validate_project_config(config, errors, warnings)
96
+ config = process_loaded_project_config(config, errors, warnings)
98
97
  federation, federation_config = validate_federation_in_project_config(
99
98
  federation, config
100
99
  )
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)
100
+ exit_if_no_address(federation_config, "ls")
110
101
 
111
102
  try:
112
103
  if runs and run_id is not None:
113
104
  raise ValueError(
114
105
  "The options '--runs' and '--run-id' are mutually exclusive."
115
106
  )
116
-
117
- channel = _init_channel(app, federation_config)
107
+ auth_plugin = try_obtain_cli_auth_plugin(app, federation, federation_config)
108
+ channel = init_channel(app, federation_config, auth_plugin)
118
109
  stub = ExecStub(channel)
119
110
 
120
111
  # Display information about a specific run ID
@@ -154,27 +145,6 @@ def ls( # pylint: disable=too-many-locals, too-many-branches
154
145
  captured_output.close()
155
146
 
156
147
 
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
148
  def _format_runs(run_dict: dict[int, Run], now_isoformat: str) -> list[_RunListType]:
179
149
  """Format runs to a list."""
180
150
 
flwr/cli/new/__init__.py CHANGED
@@ -14,6 +14,7 @@
14
14
  # ==============================================================================
15
15
  """Flower command line interface `new` command."""
16
16
 
17
+
17
18
  from .new import new as new
18
19
 
19
20
  __all__ = [
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.43.0",
15
+ "bitsandbytes==0.45.0",
16
16
  "scipy==1.13.0",
17
17
  "peft==0.6.2",
18
- "transformers==4.43.1",
18
+ "transformers==4.47.0",
19
19
  "sentencepiece==0.2.0",
20
20
  "omegaconf==2.3.0",
21
21
  "hf_transfer==0.1.8",
@@ -10,8 +10,7 @@ license = "Apache-2.0"
10
10
  dependencies = [
11
11
  "flwr[simulation]>=1.13.1",
12
12
  "flwr-datasets[vision]>=0.3.0",
13
- "mlx==0.16.1",
14
- "numpy==1.24.4",
13
+ "mlx==0.21.1",
15
14
  ]
16
15
 
17
16
  [tool.hatch.build.targets.wheel]
flwr/cli/run/__init__.py CHANGED
@@ -14,6 +14,7 @@
14
14
  # ==============================================================================
15
15
  """Flower command line interface `run` command."""
16
16
 
17
+
17
18
  from .run import run as run
18
19
 
19
20
  __all__ = [
flwr/cli/run/run.py CHANGED
@@ -14,10 +14,10 @@
14
14
  # ==============================================================================
15
15
  """Flower command line interface `run` command."""
16
16
 
17
+
17
18
  import io
18
19
  import json
19
20
  import subprocess
20
- from logging import DEBUG
21
21
  from pathlib import Path
22
22
  from typing import Annotated, Any, Optional, Union
23
23
 
@@ -28,9 +28,8 @@ from flwr.cli.build import build
28
28
  from flwr.cli.config_utils import (
29
29
  get_fab_metadata,
30
30
  load_and_validate,
31
- validate_certificate_in_federation_config,
31
+ process_loaded_project_config,
32
32
  validate_federation_in_project_config,
33
- validate_project_config,
34
33
  )
35
34
  from flwr.common.config import (
36
35
  flatten_dict,
@@ -38,8 +37,7 @@ from flwr.common.config import (
38
37
  user_config_to_configsrecord,
39
38
  )
40
39
  from flwr.common.constant import CliOutputFormat
41
- from flwr.common.grpc import GRPC_MAX_MESSAGE_LENGTH, create_channel
42
- from flwr.common.logger import log, redirect_output, remove_emojis, restore_output
40
+ from flwr.common.logger import redirect_output, remove_emojis, restore_output
43
41
  from flwr.common.serde import (
44
42
  configs_record_to_proto,
45
43
  fab_to_proto,
@@ -50,15 +48,11 @@ from flwr.proto.exec_pb2 import StartRunRequest # pylint: disable=E0611
50
48
  from flwr.proto.exec_pb2_grpc import ExecStub
51
49
 
52
50
  from ..log import start_stream
51
+ from ..utils import init_channel, try_obtain_cli_auth_plugin
53
52
 
54
53
  CONN_REFRESH_PERIOD = 60 # Connection refresh period for log streaming (seconds)
55
54
 
56
55
 
57
- def on_channel_state_change(channel_connectivity: str) -> None:
58
- """Log channel connectivity."""
59
- log(DEBUG, channel_connectivity)
60
-
61
-
62
56
  # pylint: disable-next=too-many-locals
63
57
  def run(
64
58
  app: Annotated[
@@ -108,14 +102,19 @@ def run(
108
102
 
109
103
  pyproject_path = app / "pyproject.toml" if app else None
110
104
  config, errors, warnings = load_and_validate(path=pyproject_path)
111
- config = validate_project_config(config, errors, warnings)
105
+ config = process_loaded_project_config(config, errors, warnings)
112
106
  federation, federation_config = validate_federation_in_project_config(
113
107
  federation, config
114
108
  )
115
109
 
116
110
  if "address" in federation_config:
117
111
  _run_with_exec_api(
118
- app, federation_config, config_overrides, stream, output_format
112
+ app,
113
+ federation,
114
+ federation_config,
115
+ config_overrides,
116
+ stream,
117
+ output_format,
119
118
  )
120
119
  else:
121
120
  _run_without_exec_api(app, federation_config, config_overrides, federation)
@@ -136,26 +135,17 @@ def run(
136
135
  captured_output.close()
137
136
 
138
137
 
139
- # pylint: disable-next=too-many-locals
138
+ # pylint: disable-next=R0913, R0914, R0917
140
139
  def _run_with_exec_api(
141
140
  app: Path,
141
+ federation: str,
142
142
  federation_config: dict[str, Any],
143
143
  config_overrides: Optional[list[str]],
144
144
  stream: bool,
145
145
  output_format: str,
146
146
  ) -> None:
147
-
148
- insecure, root_certificates_bytes = validate_certificate_in_federation_config(
149
- app, federation_config
150
- )
151
- channel = create_channel(
152
- server_address=federation_config["address"],
153
- insecure=insecure,
154
- root_certificates=root_certificates_bytes,
155
- max_message_length=GRPC_MAX_MESSAGE_LENGTH,
156
- interceptors=None,
157
- )
158
- channel.subscribe(on_channel_state_change)
147
+ auth_plugin = try_obtain_cli_auth_plugin(app, federation, federation_config)
148
+ channel = init_channel(app, federation_config, auth_plugin)
159
149
  stub = ExecStub(channel)
160
150
 
161
151
  fab_path, fab_hash = build(app)