flwr-nightly 1.21.0.dev20250902__py3-none-any.whl → 1.21.0.dev20250903__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.
- flwr/cli/constant.py +25 -8
- flwr/cli/new/templates/app/code/server.pytorch_msg_api.py.tpl +0 -8
- flwr/cli/run/run.py +2 -6
- flwr/clientapp/__init__.py +4 -0
- flwr/clientapp/centraldp_mods.py +132 -0
- flwr/common/exception.py +31 -0
- flwr/common/exit/exit_code.py +2 -0
- flwr/server/serverapp/app.py +41 -28
- flwr/serverapp/dp_fixed_clipping.py +352 -0
- flwr/serverapp/strategy/__init__.py +6 -0
- flwr/serverapp/strategy/dp_fixed_clipping.py +352 -0
- flwr/serverapp/strategy/result.py +76 -2
- flwr/serverapp/strategy/strategy.py +15 -20
- flwr/serverapp/strategy/strategy_utils.py +5 -1
- {flwr_nightly-1.21.0.dev20250902.dist-info → flwr_nightly-1.21.0.dev20250903.dist-info}/METADATA +1 -1
- {flwr_nightly-1.21.0.dev20250902.dist-info → flwr_nightly-1.21.0.dev20250903.dist-info}/RECORD +18 -14
- {flwr_nightly-1.21.0.dev20250902.dist-info → flwr_nightly-1.21.0.dev20250903.dist-info}/WHEEL +0 -0
- {flwr_nightly-1.21.0.dev20250902.dist-info → flwr_nightly-1.21.0.dev20250903.dist-info}/entry_points.txt +0 -0
@@ -0,0 +1,352 @@
|
|
1
|
+
# Copyright 2025 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
|
+
"""Message-based Central differential privacy with fixed clipping.
|
16
|
+
|
17
|
+
Papers: https://arxiv.org/abs/1712.07557, https://arxiv.org/abs/1710.06963
|
18
|
+
"""
|
19
|
+
|
20
|
+
from abc import ABC
|
21
|
+
from collections import OrderedDict
|
22
|
+
from collections.abc import Iterable
|
23
|
+
from logging import INFO, WARNING
|
24
|
+
from typing import Optional
|
25
|
+
|
26
|
+
from flwr.common import Array, ArrayRecord, ConfigRecord, Message, MetricRecord, log
|
27
|
+
from flwr.common.differential_privacy import (
|
28
|
+
add_gaussian_noise_inplace,
|
29
|
+
compute_clip_model_update,
|
30
|
+
compute_stdv,
|
31
|
+
)
|
32
|
+
from flwr.common.differential_privacy_constants import (
|
33
|
+
CLIENTS_DISCREPANCY_WARNING,
|
34
|
+
KEY_CLIPPING_NORM,
|
35
|
+
)
|
36
|
+
from flwr.server import Grid
|
37
|
+
|
38
|
+
from .strategy import Strategy
|
39
|
+
|
40
|
+
|
41
|
+
class DifferentialPrivacyFixedClippingBase(Strategy, ABC):
|
42
|
+
"""Base class for DP strategies with fixed clipping.
|
43
|
+
|
44
|
+
This class contains common functionality shared between server-side and
|
45
|
+
client-side fixed clipping implementations.
|
46
|
+
|
47
|
+
Parameters
|
48
|
+
----------
|
49
|
+
strategy : Strategy
|
50
|
+
The strategy to which DP functionalities will be added by this wrapper.
|
51
|
+
noise_multiplier : float
|
52
|
+
The noise multiplier for the Gaussian mechanism for model updates.
|
53
|
+
A value of 1.0 or higher is recommended for strong privacy.
|
54
|
+
clipping_norm : float
|
55
|
+
The value of the clipping norm.
|
56
|
+
num_sampled_clients : int
|
57
|
+
The number of clients that are sampled on each round.
|
58
|
+
"""
|
59
|
+
|
60
|
+
# pylint: disable=too-many-arguments,too-many-instance-attributes
|
61
|
+
def __init__(
|
62
|
+
self,
|
63
|
+
strategy: Strategy,
|
64
|
+
noise_multiplier: float,
|
65
|
+
clipping_norm: float,
|
66
|
+
num_sampled_clients: int,
|
67
|
+
) -> None:
|
68
|
+
super().__init__()
|
69
|
+
|
70
|
+
self.strategy = strategy
|
71
|
+
|
72
|
+
if noise_multiplier < 0:
|
73
|
+
raise ValueError("The noise multiplier should be a non-negative value.")
|
74
|
+
|
75
|
+
if clipping_norm <= 0:
|
76
|
+
raise ValueError("The clipping norm should be a positive value.")
|
77
|
+
|
78
|
+
if num_sampled_clients <= 0:
|
79
|
+
raise ValueError(
|
80
|
+
"The number of sampled clients should be a positive value."
|
81
|
+
)
|
82
|
+
|
83
|
+
self.noise_multiplier = noise_multiplier
|
84
|
+
self.clipping_norm = clipping_norm
|
85
|
+
self.num_sampled_clients = num_sampled_clients
|
86
|
+
|
87
|
+
def _validate_replies(self, replies: Iterable[Message]) -> bool:
|
88
|
+
"""Validate replies and log errors/warnings.
|
89
|
+
|
90
|
+
Returns
|
91
|
+
-------
|
92
|
+
bool
|
93
|
+
True if replies are valid for aggregation, False otherwise.
|
94
|
+
"""
|
95
|
+
num_errors = 0
|
96
|
+
num_replies_with_content = 0
|
97
|
+
for msg in replies:
|
98
|
+
if msg.has_error():
|
99
|
+
log(
|
100
|
+
INFO,
|
101
|
+
"Received error in reply from node %d: %s",
|
102
|
+
msg.metadata.src_node_id,
|
103
|
+
msg.error,
|
104
|
+
)
|
105
|
+
num_errors += 1
|
106
|
+
else:
|
107
|
+
num_replies_with_content += 1
|
108
|
+
|
109
|
+
# Errors are not allowed
|
110
|
+
if num_errors:
|
111
|
+
log(
|
112
|
+
INFO,
|
113
|
+
"aggregate_train: Some clients reported errors. Skipping aggregation.",
|
114
|
+
)
|
115
|
+
return False
|
116
|
+
|
117
|
+
log(
|
118
|
+
INFO,
|
119
|
+
"aggregate_train: Received %s results and %s failures",
|
120
|
+
num_replies_with_content,
|
121
|
+
num_errors,
|
122
|
+
)
|
123
|
+
|
124
|
+
if num_replies_with_content != self.num_sampled_clients:
|
125
|
+
log(
|
126
|
+
WARNING,
|
127
|
+
CLIENTS_DISCREPANCY_WARNING,
|
128
|
+
num_replies_with_content,
|
129
|
+
self.num_sampled_clients,
|
130
|
+
)
|
131
|
+
|
132
|
+
return True
|
133
|
+
|
134
|
+
def _add_noise_to_aggregated_arrays(
|
135
|
+
self, aggregated_arrays: ArrayRecord
|
136
|
+
) -> ArrayRecord:
|
137
|
+
"""Add Gaussian noise to aggregated arrays.
|
138
|
+
|
139
|
+
Parameters
|
140
|
+
----------
|
141
|
+
aggregated_arrays : ArrayRecord
|
142
|
+
The aggregated arrays to add noise to.
|
143
|
+
|
144
|
+
Returns
|
145
|
+
-------
|
146
|
+
ArrayRecord
|
147
|
+
The aggregated arrays with noise added.
|
148
|
+
"""
|
149
|
+
aggregated_ndarrays = aggregated_arrays.to_numpy_ndarrays()
|
150
|
+
stdv = compute_stdv(
|
151
|
+
self.noise_multiplier, self.clipping_norm, self.num_sampled_clients
|
152
|
+
)
|
153
|
+
add_gaussian_noise_inplace(aggregated_ndarrays, stdv)
|
154
|
+
|
155
|
+
log(
|
156
|
+
INFO,
|
157
|
+
"aggregate_fit: central DP noise with %.4f stdev added",
|
158
|
+
stdv,
|
159
|
+
)
|
160
|
+
|
161
|
+
return ArrayRecord(
|
162
|
+
OrderedDict(
|
163
|
+
{
|
164
|
+
k: Array(v)
|
165
|
+
for k, v in zip(aggregated_arrays.keys(), aggregated_ndarrays)
|
166
|
+
}
|
167
|
+
)
|
168
|
+
)
|
169
|
+
|
170
|
+
def configure_evaluate(
|
171
|
+
self, server_round: int, arrays: ArrayRecord, config: ConfigRecord, grid: Grid
|
172
|
+
) -> Iterable[Message]:
|
173
|
+
"""Configure the next round of federated evaluation."""
|
174
|
+
return self.strategy.configure_evaluate(server_round, arrays, config, grid)
|
175
|
+
|
176
|
+
def aggregate_evaluate(
|
177
|
+
self,
|
178
|
+
server_round: int,
|
179
|
+
replies: Iterable[Message],
|
180
|
+
) -> Optional[MetricRecord]:
|
181
|
+
"""Aggregate MetricRecords in the received Messages."""
|
182
|
+
return self.strategy.aggregate_evaluate(server_round, replies)
|
183
|
+
|
184
|
+
def summary(self) -> None:
|
185
|
+
"""Log summary configuration of the strategy."""
|
186
|
+
self.strategy.summary()
|
187
|
+
|
188
|
+
|
189
|
+
class DifferentialPrivacyServerSideFixedClipping(DifferentialPrivacyFixedClippingBase):
|
190
|
+
"""Strategy wrapper for central DP with server-side fixed clipping.
|
191
|
+
|
192
|
+
Parameters
|
193
|
+
----------
|
194
|
+
strategy : Strategy
|
195
|
+
The strategy to which DP functionalities will be added by this wrapper.
|
196
|
+
noise_multiplier : float
|
197
|
+
The noise multiplier for the Gaussian mechanism for model updates.
|
198
|
+
A value of 1.0 or higher is recommended for strong privacy.
|
199
|
+
clipping_norm : float
|
200
|
+
The value of the clipping norm.
|
201
|
+
num_sampled_clients : int
|
202
|
+
The number of clients that are sampled on each round.
|
203
|
+
|
204
|
+
Examples
|
205
|
+
--------
|
206
|
+
Create a strategy::
|
207
|
+
|
208
|
+
strategy = fl.serverapp.FedAvg( ... )
|
209
|
+
|
210
|
+
Wrap the strategy with the `DifferentialPrivacyServerSideFixedClipping` wrapper::
|
211
|
+
|
212
|
+
dp_strategy = DifferentialPrivacyServerSideFixedClipping(
|
213
|
+
strategy, cfg.noise_multiplier, cfg.clipping_norm, cfg.num_sampled_clients
|
214
|
+
)
|
215
|
+
"""
|
216
|
+
|
217
|
+
def __init__(
|
218
|
+
self,
|
219
|
+
strategy: Strategy,
|
220
|
+
noise_multiplier: float,
|
221
|
+
clipping_norm: float,
|
222
|
+
num_sampled_clients: int,
|
223
|
+
) -> None:
|
224
|
+
super().__init__(strategy, noise_multiplier, clipping_norm, num_sampled_clients)
|
225
|
+
self.current_arrays: ArrayRecord = ArrayRecord()
|
226
|
+
|
227
|
+
def __repr__(self) -> str:
|
228
|
+
"""Compute a string representation of the strategy."""
|
229
|
+
return "Differential Privacy Strategy Wrapper (Server-Side Fixed Clipping)"
|
230
|
+
|
231
|
+
def configure_train(
|
232
|
+
self, server_round: int, arrays: ArrayRecord, config: ConfigRecord, grid: Grid
|
233
|
+
) -> Iterable[Message]:
|
234
|
+
"""Configure the next round of training."""
|
235
|
+
self.current_arrays = arrays
|
236
|
+
return self.strategy.configure_train(server_round, arrays, config, grid)
|
237
|
+
|
238
|
+
def aggregate_train(
|
239
|
+
self,
|
240
|
+
server_round: int,
|
241
|
+
replies: Iterable[Message],
|
242
|
+
) -> tuple[Optional[ArrayRecord], Optional[MetricRecord]]:
|
243
|
+
"""Aggregate ArrayRecords and MetricRecords in the received Messages."""
|
244
|
+
if not self._validate_replies(replies):
|
245
|
+
return None, None
|
246
|
+
|
247
|
+
# Clip arrays in replies
|
248
|
+
current_ndarrays = self.current_arrays.to_numpy_ndarrays()
|
249
|
+
for reply in replies:
|
250
|
+
for arr_name, record in reply.content.array_records.items():
|
251
|
+
# Clip
|
252
|
+
reply_ndarrays = record.to_numpy_ndarrays()
|
253
|
+
compute_clip_model_update(
|
254
|
+
param1=reply_ndarrays,
|
255
|
+
param2=current_ndarrays,
|
256
|
+
clipping_norm=self.clipping_norm,
|
257
|
+
)
|
258
|
+
# Replace content while preserving keys
|
259
|
+
reply.content[arr_name] = ArrayRecord(
|
260
|
+
OrderedDict(
|
261
|
+
{k: Array(v) for k, v in zip(record.keys(), reply_ndarrays)}
|
262
|
+
)
|
263
|
+
)
|
264
|
+
log(
|
265
|
+
INFO,
|
266
|
+
"aggregate_fit: parameters are clipped by value: %.4f.",
|
267
|
+
self.clipping_norm,
|
268
|
+
)
|
269
|
+
|
270
|
+
# Pass the new parameters for aggregation
|
271
|
+
aggregated_arrays, aggregated_metrics = self.strategy.aggregate_train(
|
272
|
+
server_round, replies
|
273
|
+
)
|
274
|
+
|
275
|
+
# Add Gaussian noise to the aggregated arrays
|
276
|
+
if aggregated_arrays:
|
277
|
+
aggregated_arrays = self._add_noise_to_aggregated_arrays(aggregated_arrays)
|
278
|
+
|
279
|
+
return aggregated_arrays, aggregated_metrics
|
280
|
+
|
281
|
+
|
282
|
+
class DifferentialPrivacyClientSideFixedClipping(DifferentialPrivacyFixedClippingBase):
|
283
|
+
"""Strategy wrapper for central DP with client-side fixed clipping.
|
284
|
+
|
285
|
+
Use `fixedclipping_mod` modifier at the client side.
|
286
|
+
|
287
|
+
In comparison to `DifferentialPrivacyServerSideFixedClipping`,
|
288
|
+
which performs clipping on the server-side,
|
289
|
+
`DifferentialPrivacyClientSideFixedClipping` expects clipping to happen
|
290
|
+
on the client-side, usually by using the built-in `fixedclipping_mod`.
|
291
|
+
|
292
|
+
Parameters
|
293
|
+
----------
|
294
|
+
strategy : Strategy
|
295
|
+
The strategy to which DP functionalities will be added by this wrapper.
|
296
|
+
noise_multiplier : float
|
297
|
+
The noise multiplier for the Gaussian mechanism for model updates.
|
298
|
+
A value of 1.0 or higher is recommended for strong privacy.
|
299
|
+
clipping_norm : float
|
300
|
+
The value of the clipping norm.
|
301
|
+
num_sampled_clients : int
|
302
|
+
The number of clients that are sampled on each round.
|
303
|
+
|
304
|
+
Examples
|
305
|
+
--------
|
306
|
+
Create a strategy::
|
307
|
+
|
308
|
+
strategy = fl.serverapp.FedAvg(...)
|
309
|
+
|
310
|
+
Wrap the strategy with the `DifferentialPrivacyClientSideFixedClipping` wrapper::
|
311
|
+
|
312
|
+
dp_strategy = DifferentialPrivacyClientSideFixedClipping(
|
313
|
+
strategy, cfg.noise_multiplier, cfg.clipping_norm, cfg.num_sampled_clients
|
314
|
+
)
|
315
|
+
|
316
|
+
On the client, add the `fixedclipping_mod` to the client-side mods::
|
317
|
+
|
318
|
+
app = fl.client.ClientApp(mods=[fixedclipping_mod])
|
319
|
+
"""
|
320
|
+
|
321
|
+
def __repr__(self) -> str:
|
322
|
+
"""Compute a string representation of the strategy."""
|
323
|
+
return "Differential Privacy Strategy Wrapper (Client-Side Fixed Clipping)"
|
324
|
+
|
325
|
+
def configure_train(
|
326
|
+
self, server_round: int, arrays: ArrayRecord, config: ConfigRecord, grid: Grid
|
327
|
+
) -> Iterable[Message]:
|
328
|
+
"""Configure the next round of training."""
|
329
|
+
# Inject clipping norm in config
|
330
|
+
config[KEY_CLIPPING_NORM] = self.clipping_norm
|
331
|
+
# Call parent method
|
332
|
+
return self.strategy.configure_train(server_round, arrays, config, grid)
|
333
|
+
|
334
|
+
def aggregate_train(
|
335
|
+
self,
|
336
|
+
server_round: int,
|
337
|
+
replies: Iterable[Message],
|
338
|
+
) -> tuple[Optional[ArrayRecord], Optional[MetricRecord]]:
|
339
|
+
"""Aggregate ArrayRecords and MetricRecords in the received Messages."""
|
340
|
+
if not self._validate_replies(replies):
|
341
|
+
return None, None
|
342
|
+
|
343
|
+
# Aggregate
|
344
|
+
aggregated_arrays, aggregated_metrics = self.strategy.aggregate_train(
|
345
|
+
server_round, replies
|
346
|
+
)
|
347
|
+
|
348
|
+
# Add Gaussian noise to the aggregated arrays
|
349
|
+
if aggregated_arrays:
|
350
|
+
aggregated_arrays = self._add_noise_to_aggregated_arrays(aggregated_arrays)
|
351
|
+
|
352
|
+
return aggregated_arrays, aggregated_metrics
|
@@ -14,17 +14,91 @@
|
|
14
14
|
# ==============================================================================
|
15
15
|
"""Strategy results."""
|
16
16
|
|
17
|
-
|
17
|
+
import pprint
|
18
18
|
from dataclasses import dataclass, field
|
19
19
|
|
20
20
|
from flwr.common import ArrayRecord, MetricRecord
|
21
|
+
from flwr.common.typing import MetricRecordValues
|
21
22
|
|
22
23
|
|
23
24
|
@dataclass
|
24
25
|
class Result:
|
25
|
-
"""Data class carrying records generated during the execution of a strategy.
|
26
|
+
"""Data class carrying records generated during the execution of a strategy.
|
27
|
+
|
28
|
+
This class encapsulates the results of a federated learning strategy execution,
|
29
|
+
including the final global model parameters and metrics collected throughout
|
30
|
+
the federated training and evaluation (both federated and centralized) stages.
|
31
|
+
|
32
|
+
Attributes
|
33
|
+
----------
|
34
|
+
arrays : ArrayRecord
|
35
|
+
The final global model parameters. Contains the
|
36
|
+
aggregated model weights/parameters that resulted from the federated
|
37
|
+
learning process.
|
38
|
+
train_metrics_clientapp : dict[int, MetricRecord]
|
39
|
+
Training metrics collected from ClientApps, indexed by round number.
|
40
|
+
Contains aggregated metrics (e.g., loss, accuracy) from the training
|
41
|
+
phase of each federated learning round.
|
42
|
+
evaluate_metrics_clientapp : dict[int, MetricRecord]
|
43
|
+
Evaluation metrics collected from ClientApps, indexed by round number.
|
44
|
+
Contains aggregated metrics (e.g. validation loss) from the evaluation
|
45
|
+
phase where ClientApps evaluate the global model on their local
|
46
|
+
validation/test data.
|
47
|
+
evaluate_metrics_serverapp : dict[int, MetricRecord]
|
48
|
+
Evaluation metrics generated at the ServerApp, indexed by round number.
|
49
|
+
Contains metrics from centralized evaluation performed by the ServerApp
|
50
|
+
(e.g., when the server evaluates the global model on a held-out dataset).
|
51
|
+
"""
|
26
52
|
|
27
53
|
arrays: ArrayRecord = field(default_factory=ArrayRecord)
|
28
54
|
train_metrics_clientapp: dict[int, MetricRecord] = field(default_factory=dict)
|
29
55
|
evaluate_metrics_clientapp: dict[int, MetricRecord] = field(default_factory=dict)
|
30
56
|
evaluate_metrics_serverapp: dict[int, MetricRecord] = field(default_factory=dict)
|
57
|
+
|
58
|
+
def __repr__(self) -> str:
|
59
|
+
"""Create a representation of the Result instance."""
|
60
|
+
rep = ""
|
61
|
+
arr_size = sum(len(array.data) for array in self.arrays.values()) / (1024**2)
|
62
|
+
rep += "Global Arrays:\n" + f"\tArrayRecord ({arr_size:.3f} MB)\n" + "\n"
|
63
|
+
rep += (
|
64
|
+
"Aggregated Client-side Train Metrics:\n"
|
65
|
+
+ pprint.pformat(stringify_dict(self.train_metrics_clientapp), indent=2)
|
66
|
+
+ "\n\n"
|
67
|
+
)
|
68
|
+
|
69
|
+
rep += (
|
70
|
+
"Aggregated Client-side Evaluate Metrics:\n"
|
71
|
+
+ pprint.pformat(stringify_dict(self.evaluate_metrics_clientapp), indent=2)
|
72
|
+
+ "\n\n"
|
73
|
+
)
|
74
|
+
|
75
|
+
rep += (
|
76
|
+
"Server-side Evaluate Metrics:\n"
|
77
|
+
+ pprint.pformat(stringify_dict(self.evaluate_metrics_serverapp), indent=2)
|
78
|
+
+ "\n"
|
79
|
+
)
|
80
|
+
|
81
|
+
return rep
|
82
|
+
|
83
|
+
|
84
|
+
def format_value(val: MetricRecordValues) -> str:
|
85
|
+
"""Format a value as string, applying scientific notation for floats."""
|
86
|
+
if isinstance(val, float):
|
87
|
+
return f"{val:.4e}"
|
88
|
+
if isinstance(val, int):
|
89
|
+
return str(val)
|
90
|
+
if isinstance(val, list):
|
91
|
+
return str([f"{x:.4e}" if isinstance(x, float) else str(x) for x in val])
|
92
|
+
return str(val)
|
93
|
+
|
94
|
+
|
95
|
+
def stringify_dict(d: dict[int, MetricRecord]) -> dict[int, dict[str, str]]:
|
96
|
+
"""Return a copy results metrics but with values converted to string and formatted
|
97
|
+
accordingtly."""
|
98
|
+
new_metrics_dict = {}
|
99
|
+
for k, inner in d.items():
|
100
|
+
new_inner = {}
|
101
|
+
for ik, iv in inner.items():
|
102
|
+
new_inner[ik] = format_value(iv)
|
103
|
+
new_metrics_dict[k] = new_inner
|
104
|
+
return new_metrics_dict
|
@@ -15,6 +15,7 @@
|
|
15
15
|
"""Flower message-based strategy."""
|
16
16
|
|
17
17
|
|
18
|
+
import io
|
18
19
|
import time
|
19
20
|
from abc import ABC, abstractmethod
|
20
21
|
from collections.abc import Iterable
|
@@ -22,11 +23,10 @@ from logging import INFO
|
|
22
23
|
from typing import Callable, Optional
|
23
24
|
|
24
25
|
from flwr.common import ArrayRecord, ConfigRecord, Message, MetricRecord, log
|
25
|
-
from flwr.common.exit import ExitCode, flwr_exit
|
26
26
|
from flwr.server import Grid
|
27
27
|
|
28
28
|
from .result import Result
|
29
|
-
from .strategy_utils import
|
29
|
+
from .strategy_utils import log_strategy_start_info
|
30
30
|
|
31
31
|
|
32
32
|
class Strategy(ABC):
|
@@ -218,15 +218,10 @@ class Strategy(ABC):
|
|
218
218
|
)
|
219
219
|
|
220
220
|
# Aggregate train
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
)
|
226
|
-
except InconsistentMessageReplies as e:
|
227
|
-
flwr_exit(
|
228
|
-
ExitCode.SERVERAPP_STRATEGY_PRECONDITION_UNMET, message=str(e)
|
229
|
-
)
|
221
|
+
agg_arrays, agg_train_metrics = self.aggregate_train(
|
222
|
+
current_round,
|
223
|
+
train_replies,
|
224
|
+
)
|
230
225
|
|
231
226
|
# Log training metrics and append to history
|
232
227
|
if agg_arrays is not None:
|
@@ -253,15 +248,10 @@ class Strategy(ABC):
|
|
253
248
|
)
|
254
249
|
|
255
250
|
# Aggregate evaluate
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
)
|
261
|
-
except InconsistentMessageReplies as e:
|
262
|
-
flwr_exit(
|
263
|
-
ExitCode.SERVERAPP_STRATEGY_PRECONDITION_UNMET, message=str(e)
|
264
|
-
)
|
251
|
+
agg_evaluate_metrics = self.aggregate_evaluate(
|
252
|
+
current_round,
|
253
|
+
evaluate_replies,
|
254
|
+
)
|
265
255
|
|
266
256
|
# Log training metrics and append to history
|
267
257
|
if agg_evaluate_metrics is not None:
|
@@ -282,5 +272,10 @@ class Strategy(ABC):
|
|
282
272
|
log(INFO, "")
|
283
273
|
log(INFO, "Strategy execution finished in %.2fs", time.time() - t_start)
|
284
274
|
log(INFO, "")
|
275
|
+
log(INFO, "Final results:")
|
276
|
+
log(INFO, "")
|
277
|
+
for line in io.StringIO(str(result)):
|
278
|
+
log(INFO, "\t%s", line.strip("\n"))
|
279
|
+
log(INFO, "")
|
285
280
|
|
286
281
|
return result
|
@@ -30,13 +30,17 @@ from flwr.common import (
|
|
30
30
|
RecordDict,
|
31
31
|
log,
|
32
32
|
)
|
33
|
+
from flwr.common.exception import AppExitException
|
34
|
+
from flwr.common.exit import ExitCode
|
33
35
|
from flwr.server import Grid
|
34
36
|
|
35
37
|
|
36
|
-
class InconsistentMessageReplies(
|
38
|
+
class InconsistentMessageReplies(AppExitException):
|
37
39
|
"""Exception triggered when replies are inconsistent and therefore aggregation must
|
38
40
|
be skipped."""
|
39
41
|
|
42
|
+
exit_code = ExitCode.SERVERAPP_STRATEGY_PRECONDITION_UNMET
|
43
|
+
|
40
44
|
def __init__(self, reason: str):
|
41
45
|
super().__init__(reason)
|
42
46
|
|
{flwr_nightly-1.21.0.dev20250902.dist-info → flwr_nightly-1.21.0.dev20250903.dist-info}/METADATA
RENAMED
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.3
|
2
2
|
Name: flwr-nightly
|
3
|
-
Version: 1.21.0.
|
3
|
+
Version: 1.21.0.dev20250903
|
4
4
|
Summary: Flower: A Friendly Federated AI Framework
|
5
5
|
License: Apache-2.0
|
6
6
|
Keywords: Artificial Intelligence,Federated AI,Federated Analytics,Federated Evaluation,Federated Learning,Flower,Machine Learning
|
{flwr_nightly-1.21.0.dev20250902.dist-info → flwr_nightly-1.21.0.dev20250903.dist-info}/RECORD
RENAMED
@@ -9,7 +9,7 @@ flwr/cli/auth_plugin/oidc_cli_plugin.py,sha256=kQteGRB9-DmC7K5F9TBmUc8ndSBR7WyT2
|
|
9
9
|
flwr/cli/build.py,sha256=hE54Q_eMdWLpVKSVC2aQaUxVaiUlWnAosGNvIPSEg6Y,7284
|
10
10
|
flwr/cli/cli_user_auth_interceptor.py,sha256=O4S8tbA1-rgBNe5YMGACDqmY7v2SJoxyibRhshrzXu4,3129
|
11
11
|
flwr/cli/config_utils.py,sha256=o75PJzgCTl9FdFo_I9OjCB02-ykK0VWZdhIAeR0A8QA,9130
|
12
|
-
flwr/cli/constant.py,sha256=
|
12
|
+
flwr/cli/constant.py,sha256=LtxufmhkEqNWQ9doWbbbkUKa12vN_RK_Of5u0So-GHA,1729
|
13
13
|
flwr/cli/example.py,sha256=SNTorkKPrx1rOryGREUyZu8TcOc1-vFv1zEddaysdY0,2216
|
14
14
|
flwr/cli/install.py,sha256=Jr883qR7qssVpUr3hEOEcLK-dfW67Rsve3lZchjA9RU,8180
|
15
15
|
flwr/cli/log.py,sha256=n_fcoECKIkY3MTOfXhB8AjOG1LSQW_GSPY-2qc7rW9Q,6553
|
@@ -52,7 +52,7 @@ flwr/cli/new/templates/app/code/server.jax.py.tpl,sha256=IHk57syZhvO4nWVHGxE9S8f
|
|
52
52
|
flwr/cli/new/templates/app/code/server.mlx.py.tpl,sha256=GAqalaI-U2uRdttNeRn75k1FzdEW3rmgT-ywuKkFdK4,988
|
53
53
|
flwr/cli/new/templates/app/code/server.numpy.py.tpl,sha256=xbQlLCKutnOqlbLQPZsaL9WM7vnebTceiU8a0HaUcZk,740
|
54
54
|
flwr/cli/new/templates/app/code/server.pytorch.py.tpl,sha256=gvBsGA_Jg9kAH8xTxjzTjMcvBtciuccOwQFbO7ey8tU,916
|
55
|
-
flwr/cli/new/templates/app/code/server.pytorch_msg_api.py.tpl,sha256=
|
55
|
+
flwr/cli/new/templates/app/code/server.pytorch_msg_api.py.tpl,sha256=268EzqUOM0mdiXsf0WWniNu7DiDHh_JGHLe9o-t6ru4,1158
|
56
56
|
flwr/cli/new/templates/app/code/server.sklearn.py.tpl,sha256=JoDYjPU99aKTTfjKsCtKHzMICiOR9pi8JGVBsxFpWO4,1133
|
57
57
|
flwr/cli/new/templates/app/code/server.tensorflow.py.tpl,sha256=xMhQ7AumowgLkgUilgjVK7IbpRhPjslhVJU-vID6NY8,856
|
58
58
|
flwr/cli/new/templates/app/code/strategy.baseline.py.tpl,sha256=YkHAgppUeD2BnBoGfVB6dEvBfjuIPGsU1gw4CiUi3qA,40
|
@@ -76,7 +76,7 @@ flwr/cli/new/templates/app/pyproject.pytorch_msg_api.toml.tpl,sha256=fS9Brr-dXYE
|
|
76
76
|
flwr/cli/new/templates/app/pyproject.sklearn.toml.tpl,sha256=mAEPeBfGyrINgRuP6-nX_KJNTQjC4E5N1Nrcddxiffs,1484
|
77
77
|
flwr/cli/new/templates/app/pyproject.tensorflow.toml.tpl,sha256=mK8wOWqoQOVxZG6-OVwA2ChmKxexC7TfQV0ztPE4BWY,1508
|
78
78
|
flwr/cli/run/__init__.py,sha256=RPyB7KbYTFl6YRiilCch6oezxrLQrl1kijV7BMGkLbA,790
|
79
|
-
flwr/cli/run/run.py,sha256=
|
79
|
+
flwr/cli/run/run.py,sha256=ECa0kup9dn15O70H74QdgUsEaeErbzDqVX_U0zZO5IM,8173
|
80
80
|
flwr/cli/stop.py,sha256=TR9F61suTxNUzGIktUdoBhXwdRtCdvzGhy3qCuvcfBg,5000
|
81
81
|
flwr/cli/utils.py,sha256=fkyiWXWfXo5fS_sACw8Rg9wweq3RQ7XvEUEAa_caqkE,12349
|
82
82
|
flwr/client/__init__.py,sha256=boIhKaK6I977zrILmoTutNx94x5jB0e6F1gnAjaRJnI,1250
|
@@ -106,7 +106,8 @@ flwr/client/rest_client/__init__.py,sha256=MBiuK62hj439m9rtwSwI184Hth6Tt5GbmpNMy
|
|
106
106
|
flwr/client/rest_client/connection.py,sha256=fyiS1aXTv71jWczx7mSco94LYJTBXgTF-p2PnAk3CL8,15784
|
107
107
|
flwr/client/run_info_store.py,sha256=MaJ3UQ-07hWtK67wnWu0zR29jrk0fsfgJX506dvEOfE,4042
|
108
108
|
flwr/client/typing.py,sha256=Jw3rawDzI_-ZDcRmEQcs5gZModY7oeQlEeltYsdOhlU,1048
|
109
|
-
flwr/clientapp/__init__.py,sha256=
|
109
|
+
flwr/clientapp/__init__.py,sha256=h8RNxAbCbdaLf_htSx-e5UCb2A0mLA-mpEX_6giZuU0,799
|
110
|
+
flwr/clientapp/centraldp_mods.py,sha256=M8vvdrjfLVsFLMd9JXqD_-P08q9jsNOgu_4AAs-X9Zk,4626
|
110
111
|
flwr/common/__init__.py,sha256=5GCLVk399Az_rTJHNticRlL0Sl_oPw_j5_LuFKfX7-M,4171
|
111
112
|
flwr/common/address.py,sha256=9JucdTwlc-jpeJkRKeUboZoacUtErwSVtnDR9kAtLqE,4119
|
112
113
|
flwr/common/args.py,sha256=Nq2u4yePbkSY0CWFamn0hZY6Rms8G1xYDeDGIcLIITE,5849
|
@@ -121,9 +122,10 @@ flwr/common/differential_privacy_constants.py,sha256=ruEjH4qF_S2bgxRI6brWCGWQPxF
|
|
121
122
|
flwr/common/dp.py,sha256=ftqWheOICK5N_zPaofnbFb474lMb5w9lclwxf5DKY0w,1978
|
122
123
|
flwr/common/event_log_plugin/__init__.py,sha256=ts3VAL3Fk6Grp1EK_1Qg_V-BfOof9F86iBx4rbrEkyo,838
|
123
124
|
flwr/common/event_log_plugin/event_log_plugin.py,sha256=4SkVa1Ic-sPlICJShBuggXmXDcQtWQ1KDby4kthFNF0,2064
|
125
|
+
flwr/common/exception.py,sha256=dAKSNrdh9YqKZTdYaN8hts4dAMVZHfNDV-ytzYby0LQ,1246
|
124
126
|
flwr/common/exit/__init__.py,sha256=8W7xaO1iw0vacgmQW7FTFbSh7csNv6XfsgIlnIbNF6U,978
|
125
127
|
flwr/common/exit/exit.py,sha256=DcXJfbpW1g-pQJqSZmps-1MZydd7T7RaarghIf2e4tU,3636
|
126
|
-
flwr/common/exit/exit_code.py,sha256=
|
128
|
+
flwr/common/exit/exit_code.py,sha256=e8O71zIqVT1H84mNBeenTz7S39yPZSpZQm-xUenpzN4,5249
|
127
129
|
flwr/common/exit/exit_handler.py,sha256=uzDdWwhKgc1w5csZS52b86kjmEApmDZKwMn_X0zDZZo,2126
|
128
130
|
flwr/common/exit/signal_handler.py,sha256=wqxykrwgmpFzmEMhpnlM7RtO0PnqIvYiSB1qYahZ5Sk,3710
|
129
131
|
flwr/common/grpc.py,sha256=nHnFC7E84pZVTvd6BhcSYWnGd0jf8t5UmGea04qvilM,9806
|
@@ -256,7 +258,7 @@ flwr/server/server.py,sha256=39m4FSN2T-uVA-no9nstN0eWW0co-IUUAIMmpd3V7Jc,17893
|
|
256
258
|
flwr/server/server_app.py,sha256=8uagoZX-3CY3tazPqkIV9jY-cN0YrRRrDmVe23o0AV0,9515
|
257
259
|
flwr/server/server_config.py,sha256=e_6ddh0riwOJsdNn2BFev344uMWfDk9n7dyjNpPgm1w,1349
|
258
260
|
flwr/server/serverapp/__init__.py,sha256=xcC0T_MQSMS9cicUzUUpMNCOsF2d8Oh_8jvnoBLuZvo,800
|
259
|
-
flwr/server/serverapp/app.py,sha256=
|
261
|
+
flwr/server/serverapp/app.py,sha256=d42XiEwEhee_LttXEMOa9GFP81zvaufzGyt64VlCEo0,9841
|
260
262
|
flwr/server/serverapp_components.py,sha256=dfSqmrsVy3arKXpl3ZIBQWdV8rehfIms8aJooyzdmEM,2118
|
261
263
|
flwr/server/strategy/__init__.py,sha256=HhsSWMWaC7oCb2g7Kqn1MBKdrfvgi8VxACy9ZL706Q0,2836
|
262
264
|
flwr/server/strategy/aggregate.py,sha256=smlKKy-uFUuuFR12vlclucnwSQWRz78R79-Km4RWqbw,13978
|
@@ -327,11 +329,13 @@ flwr/server/workflow/secure_aggregation/__init__.py,sha256=vGkycLb65CxdaMkKsANxQ
|
|
327
329
|
flwr/server/workflow/secure_aggregation/secagg_workflow.py,sha256=b_pKk7gmbahwyj0ftOOLXvu-AMtRHEc82N9PJTEO8dc,5839
|
328
330
|
flwr/server/workflow/secure_aggregation/secaggplus_workflow.py,sha256=DkayCsnlAya6Y2PZsueLgoUCMRtV-GbnW08RfWx_SXM,29460
|
329
331
|
flwr/serverapp/__init__.py,sha256=dUGPpyO0YEJRIjwNw2YrUWXgsEj9JOUrP5OGm8bPX9k,774
|
330
|
-
flwr/serverapp/
|
332
|
+
flwr/serverapp/dp_fixed_clipping.py,sha256=wbP4W7CaUHXdll8ZSVUnTBSEWrnWM00CGk63rOR-Q2s,12133
|
333
|
+
flwr/serverapp/strategy/__init__.py,sha256=FpZN4AafpTSxW65dAPJ0zekHo9bU84tV4uhO4XVHJTc,1088
|
334
|
+
flwr/serverapp/strategy/dp_fixed_clipping.py,sha256=wbP4W7CaUHXdll8ZSVUnTBSEWrnWM00CGk63rOR-Q2s,12133
|
331
335
|
flwr/serverapp/strategy/fedavg.py,sha256=C8UUvLTjodMpGRb4PNej5gW2cPbXsPKebGX1zPfAMUo,11020
|
332
|
-
flwr/serverapp/strategy/result.py,sha256=
|
333
|
-
flwr/serverapp/strategy/strategy.py,sha256=
|
334
|
-
flwr/serverapp/strategy/strategy_utils.py,sha256=
|
336
|
+
flwr/serverapp/strategy/result.py,sha256=rcg3NqZyC-A_x-f40fq8fk9ovL1zcSz9Jxpr32MRRIc,4285
|
337
|
+
flwr/serverapp/strategy/strategy.py,sha256=9udL2q1zEpVw-rKDMoZG_fwoklF4t1HC9hrnPaYiEhA,10663
|
338
|
+
flwr/serverapp/strategy/strategy_utils.py,sha256=rtcBQwFtWAihNdcWEAHdAqScPlRZSwqbkGjGxaWkmLE,9547
|
335
339
|
flwr/serverapp/strategy/strategy_utils_tests.py,sha256=taG6HwApwutkjUuMY3R8Ib48Xepw6g5xl9HEB_-leoY,9232
|
336
340
|
flwr/simulation/__init__.py,sha256=Gg6OsP1Z-ixc3-xxzvl7j7rz2Fijy9rzyEPpxgAQCeM,1556
|
337
341
|
flwr/simulation/app.py,sha256=LbGLMvN9Ap119yBqsUcNNmVLRnCySnr4VechqcQ1hpA,10401
|
@@ -393,7 +397,7 @@ flwr/supernode/servicer/__init__.py,sha256=lucTzre5WPK7G1YLCfaqg3rbFWdNSb7ZTt-ca
|
|
393
397
|
flwr/supernode/servicer/clientappio/__init__.py,sha256=7Oy62Y_oijqF7Dxi6tpcUQyOpLc_QpIRZ83NvwmB0Yg,813
|
394
398
|
flwr/supernode/servicer/clientappio/clientappio_servicer.py,sha256=nIHRu38EWK-rpNOkcgBRAAKwYQQWFeCwu0lkO7OPZGQ,10239
|
395
399
|
flwr/supernode/start_client_internal.py,sha256=Y9S1-QlO2WP6eo4JvWzIpfaCoh2aoE7bjEYyxNNnlyg,20777
|
396
|
-
flwr_nightly-1.21.0.
|
397
|
-
flwr_nightly-1.21.0.
|
398
|
-
flwr_nightly-1.21.0.
|
399
|
-
flwr_nightly-1.21.0.
|
400
|
+
flwr_nightly-1.21.0.dev20250903.dist-info/METADATA,sha256=x-9LvDwIejGasw9rlnPTi3qrHp3Z2hgABMTMj-_iU3k,15967
|
401
|
+
flwr_nightly-1.21.0.dev20250903.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
|
402
|
+
flwr_nightly-1.21.0.dev20250903.dist-info/entry_points.txt,sha256=hxHD2ixb_vJFDOlZV-zB4Ao32_BQlL34ftsDh1GXv14,420
|
403
|
+
flwr_nightly-1.21.0.dev20250903.dist-info/RECORD,,
|
{flwr_nightly-1.21.0.dev20250902.dist-info → flwr_nightly-1.21.0.dev20250903.dist-info}/WHEEL
RENAMED
File without changes
|
File without changes
|