flwr-nightly 1.12.0.dev20240907__py3-none-any.whl → 1.12.0.dev20240913__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 (118) hide show
  1. flwr/cli/build.py +1 -2
  2. flwr/cli/config_utils.py +10 -10
  3. flwr/cli/install.py +1 -2
  4. flwr/cli/new/new.py +26 -40
  5. flwr/cli/new/templates/app/code/client.huggingface.py.tpl +19 -29
  6. flwr/cli/new/templates/app/code/client.tensorflow.py.tpl +0 -3
  7. flwr/cli/new/templates/app/code/server.huggingface.py.tpl +18 -3
  8. flwr/cli/new/templates/app/code/task.huggingface.py.tpl +16 -13
  9. flwr/cli/new/templates/app/pyproject.huggingface.toml.tpl +9 -1
  10. flwr/cli/run/run.py +6 -7
  11. flwr/cli/utils.py +2 -2
  12. flwr/client/app.py +14 -14
  13. flwr/client/client_app.py +5 -5
  14. flwr/client/clientapp/app.py +2 -2
  15. flwr/client/dpfedavg_numpy_client.py +6 -7
  16. flwr/client/grpc_adapter_client/connection.py +4 -3
  17. flwr/client/grpc_client/connection.py +4 -3
  18. flwr/client/grpc_rere_client/client_interceptor.py +5 -5
  19. flwr/client/grpc_rere_client/connection.py +5 -4
  20. flwr/client/grpc_rere_client/grpc_adapter.py +2 -2
  21. flwr/client/message_handler/message_handler.py +3 -3
  22. flwr/client/mod/secure_aggregation/secaggplus_mod.py +25 -25
  23. flwr/client/mod/utils.py +1 -3
  24. flwr/client/node_state.py +2 -2
  25. flwr/client/numpy_client.py +8 -8
  26. flwr/client/rest_client/connection.py +5 -4
  27. flwr/client/supernode/app.py +7 -8
  28. flwr/common/address.py +2 -2
  29. flwr/common/config.py +8 -8
  30. flwr/common/constant.py +12 -1
  31. flwr/common/differential_privacy.py +2 -2
  32. flwr/common/dp.py +1 -3
  33. flwr/common/exit_handlers.py +3 -3
  34. flwr/common/grpc.py +2 -1
  35. flwr/common/logger.py +3 -3
  36. flwr/common/object_ref.py +3 -3
  37. flwr/common/record/configsrecord.py +3 -3
  38. flwr/common/record/metricsrecord.py +3 -3
  39. flwr/common/record/parametersrecord.py +3 -2
  40. flwr/common/record/recordset.py +1 -1
  41. flwr/common/record/typeddict.py +23 -10
  42. flwr/common/recordset_compat.py +7 -5
  43. flwr/common/retry_invoker.py +6 -17
  44. flwr/common/secure_aggregation/crypto/shamir.py +10 -10
  45. flwr/common/secure_aggregation/crypto/symmetric_encryption.py +2 -2
  46. flwr/common/secure_aggregation/ndarrays_arithmetic.py +16 -16
  47. flwr/common/secure_aggregation/quantization.py +7 -7
  48. flwr/common/secure_aggregation/secaggplus_utils.py +3 -5
  49. flwr/common/serde.py +11 -9
  50. flwr/common/telemetry.py +5 -5
  51. flwr/common/typing.py +19 -19
  52. flwr/common/version.py +2 -3
  53. flwr/server/app.py +18 -18
  54. flwr/server/client_manager.py +6 -6
  55. flwr/server/compat/app_utils.py +2 -3
  56. flwr/server/driver/driver.py +3 -2
  57. flwr/server/driver/grpc_driver.py +7 -7
  58. flwr/server/driver/inmemory_driver.py +5 -4
  59. flwr/server/history.py +8 -9
  60. flwr/server/run_serverapp.py +5 -6
  61. flwr/server/server.py +36 -36
  62. flwr/server/strategy/aggregate.py +13 -13
  63. flwr/server/strategy/bulyan.py +8 -8
  64. flwr/server/strategy/dp_adaptive_clipping.py +20 -20
  65. flwr/server/strategy/dp_fixed_clipping.py +19 -19
  66. flwr/server/strategy/dpfedavg_adaptive.py +6 -6
  67. flwr/server/strategy/dpfedavg_fixed.py +10 -10
  68. flwr/server/strategy/fault_tolerant_fedavg.py +11 -11
  69. flwr/server/strategy/fedadagrad.py +8 -8
  70. flwr/server/strategy/fedadam.py +8 -8
  71. flwr/server/strategy/fedavg.py +16 -16
  72. flwr/server/strategy/fedavg_android.py +16 -16
  73. flwr/server/strategy/fedavgm.py +8 -8
  74. flwr/server/strategy/fedmedian.py +4 -4
  75. flwr/server/strategy/fedopt.py +5 -5
  76. flwr/server/strategy/fedprox.py +6 -6
  77. flwr/server/strategy/fedtrimmedavg.py +8 -8
  78. flwr/server/strategy/fedxgb_bagging.py +11 -11
  79. flwr/server/strategy/fedxgb_cyclic.py +9 -9
  80. flwr/server/strategy/fedxgb_nn_avg.py +5 -5
  81. flwr/server/strategy/fedyogi.py +8 -8
  82. flwr/server/strategy/krum.py +8 -8
  83. flwr/server/strategy/qfedavg.py +15 -15
  84. flwr/server/strategy/strategy.py +10 -10
  85. flwr/server/superlink/driver/driver_grpc.py +2 -2
  86. flwr/server/superlink/driver/driver_servicer.py +6 -6
  87. flwr/server/superlink/ffs/disk_ffs.py +4 -4
  88. flwr/server/superlink/ffs/ffs.py +4 -4
  89. flwr/server/superlink/fleet/grpc_adapter/grpc_adapter_servicer.py +2 -2
  90. flwr/server/superlink/fleet/grpc_bidi/flower_service_servicer.py +2 -1
  91. flwr/server/superlink/fleet/grpc_bidi/grpc_bridge.py +2 -1
  92. flwr/server/superlink/fleet/grpc_bidi/grpc_server.py +9 -8
  93. flwr/server/superlink/fleet/grpc_rere/server_interceptor.py +5 -3
  94. flwr/server/superlink/fleet/message_handler/message_handler.py +2 -2
  95. flwr/server/superlink/fleet/rest_rere/rest_api.py +2 -1
  96. flwr/server/superlink/fleet/vce/backend/__init__.py +2 -3
  97. flwr/server/superlink/fleet/vce/backend/backend.py +3 -3
  98. flwr/server/superlink/fleet/vce/backend/raybackend.py +26 -17
  99. flwr/server/superlink/fleet/vce/vce_api.py +6 -6
  100. flwr/server/superlink/state/in_memory_state.py +18 -18
  101. flwr/server/superlink/state/sqlite_state.py +22 -21
  102. flwr/server/superlink/state/state.py +7 -7
  103. flwr/server/utils/tensorboard.py +4 -4
  104. flwr/server/utils/validator.py +2 -2
  105. flwr/server/workflow/default_workflows.py +5 -5
  106. flwr/server/workflow/secure_aggregation/secaggplus_workflow.py +22 -22
  107. flwr/simulation/app.py +8 -8
  108. flwr/simulation/ray_transport/ray_actor.py +23 -23
  109. flwr/simulation/run_simulation.py +16 -4
  110. flwr/superexec/app.py +4 -4
  111. flwr/superexec/deployment.py +2 -2
  112. flwr/superexec/exec_grpc.py +2 -2
  113. flwr/superexec/exec_servicer.py +3 -2
  114. {flwr_nightly-1.12.0.dev20240907.dist-info → flwr_nightly-1.12.0.dev20240913.dist-info}/METADATA +4 -6
  115. {flwr_nightly-1.12.0.dev20240907.dist-info → flwr_nightly-1.12.0.dev20240913.dist-info}/RECORD +118 -118
  116. {flwr_nightly-1.12.0.dev20240907.dist-info → flwr_nightly-1.12.0.dev20240913.dist-info}/LICENSE +0 -0
  117. {flwr_nightly-1.12.0.dev20240907.dist-info → flwr_nightly-1.12.0.dev20240913.dist-info}/WHEEL +0 -0
  118. {flwr_nightly-1.12.0.dev20240907.dist-info → flwr_nightly-1.12.0.dev20240913.dist-info}/entry_points.txt +0 -0
@@ -17,7 +17,7 @@
17
17
  Paper: arxiv.org/pdf/1710.06963.pdf
18
18
  """
19
19
 
20
- from typing import Dict, List, Optional, Tuple, Union
20
+ from typing import Optional, Union
21
21
 
22
22
  from flwr.common import EvaluateIns, EvaluateRes, FitIns, FitRes, Parameters, Scalar
23
23
  from flwr.common.dp import add_gaussian_noise
@@ -79,7 +79,7 @@ class DPFedAvgFixed(Strategy):
79
79
 
80
80
  def configure_fit(
81
81
  self, server_round: int, parameters: Parameters, client_manager: ClientManager
82
- ) -> List[Tuple[ClientProxy, FitIns]]:
82
+ ) -> list[tuple[ClientProxy, FitIns]]:
83
83
  """Configure the next round of training incorporating Differential Privacy (DP).
84
84
 
85
85
  Configuration of the next training round includes information related to DP,
@@ -119,7 +119,7 @@ class DPFedAvgFixed(Strategy):
119
119
 
120
120
  def configure_evaluate(
121
121
  self, server_round: int, parameters: Parameters, client_manager: ClientManager
122
- ) -> List[Tuple[ClientProxy, EvaluateIns]]:
122
+ ) -> list[tuple[ClientProxy, EvaluateIns]]:
123
123
  """Configure the next round of evaluation using the specified strategy.
124
124
 
125
125
  Parameters
@@ -147,9 +147,9 @@ class DPFedAvgFixed(Strategy):
147
147
  def aggregate_fit(
148
148
  self,
149
149
  server_round: int,
150
- results: List[Tuple[ClientProxy, FitRes]],
151
- failures: List[Union[Tuple[ClientProxy, FitRes], BaseException]],
152
- ) -> Tuple[Optional[Parameters], Dict[str, Scalar]]:
150
+ results: list[tuple[ClientProxy, FitRes]],
151
+ failures: list[Union[tuple[ClientProxy, FitRes], BaseException]],
152
+ ) -> tuple[Optional[Parameters], dict[str, Scalar]]:
153
153
  """Aggregate training results using unweighted aggregation."""
154
154
  if failures:
155
155
  return None, {}
@@ -168,14 +168,14 @@ class DPFedAvgFixed(Strategy):
168
168
  def aggregate_evaluate(
169
169
  self,
170
170
  server_round: int,
171
- results: List[Tuple[ClientProxy, EvaluateRes]],
172
- failures: List[Union[Tuple[ClientProxy, EvaluateRes], BaseException]],
173
- ) -> Tuple[Optional[float], Dict[str, Scalar]]:
171
+ results: list[tuple[ClientProxy, EvaluateRes]],
172
+ failures: list[Union[tuple[ClientProxy, EvaluateRes], BaseException]],
173
+ ) -> tuple[Optional[float], dict[str, Scalar]]:
174
174
  """Aggregate evaluation losses using the given strategy."""
175
175
  return self.strategy.aggregate_evaluate(server_round, results, failures)
176
176
 
177
177
  def evaluate(
178
178
  self, server_round: int, parameters: Parameters
179
- ) -> Optional[Tuple[float, Dict[str, Scalar]]]:
179
+ ) -> Optional[tuple[float, dict[str, Scalar]]]:
180
180
  """Evaluate model parameters using an evaluation function from the strategy."""
181
181
  return self.strategy.evaluate(server_round, parameters)
@@ -16,7 +16,7 @@
16
16
 
17
17
 
18
18
  from logging import WARNING
19
- from typing import Callable, Dict, List, Optional, Tuple, Union
19
+ from typing import Callable, Optional, Union
20
20
 
21
21
  from flwr.common import (
22
22
  EvaluateRes,
@@ -49,12 +49,12 @@ class FaultTolerantFedAvg(FedAvg):
49
49
  min_available_clients: int = 1,
50
50
  evaluate_fn: Optional[
51
51
  Callable[
52
- [int, NDArrays, Dict[str, Scalar]],
53
- Optional[Tuple[float, Dict[str, Scalar]]],
52
+ [int, NDArrays, dict[str, Scalar]],
53
+ Optional[tuple[float, dict[str, Scalar]]],
54
54
  ]
55
55
  ] = None,
56
- on_fit_config_fn: Optional[Callable[[int], Dict[str, Scalar]]] = None,
57
- on_evaluate_config_fn: Optional[Callable[[int], Dict[str, Scalar]]] = None,
56
+ on_fit_config_fn: Optional[Callable[[int], dict[str, Scalar]]] = None,
57
+ on_evaluate_config_fn: Optional[Callable[[int], dict[str, Scalar]]] = None,
58
58
  min_completion_rate_fit: float = 0.5,
59
59
  min_completion_rate_evaluate: float = 0.5,
60
60
  initial_parameters: Optional[Parameters] = None,
@@ -85,9 +85,9 @@ class FaultTolerantFedAvg(FedAvg):
85
85
  def aggregate_fit(
86
86
  self,
87
87
  server_round: int,
88
- results: List[Tuple[ClientProxy, FitRes]],
89
- failures: List[Union[Tuple[ClientProxy, FitRes], BaseException]],
90
- ) -> Tuple[Optional[Parameters], Dict[str, Scalar]]:
88
+ results: list[tuple[ClientProxy, FitRes]],
89
+ failures: list[Union[tuple[ClientProxy, FitRes], BaseException]],
90
+ ) -> tuple[Optional[Parameters], dict[str, Scalar]]:
91
91
  """Aggregate fit results using weighted average."""
92
92
  if not results:
93
93
  return None, {}
@@ -117,9 +117,9 @@ class FaultTolerantFedAvg(FedAvg):
117
117
  def aggregate_evaluate(
118
118
  self,
119
119
  server_round: int,
120
- results: List[Tuple[ClientProxy, EvaluateRes]],
121
- failures: List[Union[Tuple[ClientProxy, EvaluateRes], BaseException]],
122
- ) -> Tuple[Optional[float], Dict[str, Scalar]]:
120
+ results: list[tuple[ClientProxy, EvaluateRes]],
121
+ failures: list[Union[tuple[ClientProxy, EvaluateRes], BaseException]],
122
+ ) -> tuple[Optional[float], dict[str, Scalar]]:
123
123
  """Aggregate evaluation losses using weighted average."""
124
124
  if not results:
125
125
  return None, {}
@@ -20,7 +20,7 @@ Paper: arxiv.org/abs/2003.00295
20
20
  """
21
21
 
22
22
 
23
- from typing import Callable, Dict, List, Optional, Tuple, Union
23
+ from typing import Callable, Optional, Union
24
24
 
25
25
  import numpy as np
26
26
 
@@ -89,12 +89,12 @@ class FedAdagrad(FedOpt):
89
89
  min_available_clients: int = 2,
90
90
  evaluate_fn: Optional[
91
91
  Callable[
92
- [int, NDArrays, Dict[str, Scalar]],
93
- Optional[Tuple[float, Dict[str, Scalar]]],
92
+ [int, NDArrays, dict[str, Scalar]],
93
+ Optional[tuple[float, dict[str, Scalar]]],
94
94
  ]
95
95
  ] = None,
96
- on_fit_config_fn: Optional[Callable[[int], Dict[str, Scalar]]] = None,
97
- on_evaluate_config_fn: Optional[Callable[[int], Dict[str, Scalar]]] = None,
96
+ on_fit_config_fn: Optional[Callable[[int], dict[str, Scalar]]] = None,
97
+ on_evaluate_config_fn: Optional[Callable[[int], dict[str, Scalar]]] = None,
98
98
  fit_metrics_aggregation_fn: Optional[MetricsAggregationFn] = None,
99
99
  evaluate_metrics_aggregation_fn: Optional[MetricsAggregationFn] = None,
100
100
  accept_failures: bool = True,
@@ -131,9 +131,9 @@ class FedAdagrad(FedOpt):
131
131
  def aggregate_fit(
132
132
  self,
133
133
  server_round: int,
134
- results: List[Tuple[ClientProxy, FitRes]],
135
- failures: List[Union[Tuple[ClientProxy, FitRes], BaseException]],
136
- ) -> Tuple[Optional[Parameters], Dict[str, Scalar]]:
134
+ results: list[tuple[ClientProxy, FitRes]],
135
+ failures: list[Union[tuple[ClientProxy, FitRes], BaseException]],
136
+ ) -> tuple[Optional[Parameters], dict[str, Scalar]]:
137
137
  """Aggregate fit results using weighted average."""
138
138
  fedavg_parameters_aggregated, metrics_aggregated = super().aggregate_fit(
139
139
  server_round=server_round, results=results, failures=failures
@@ -20,7 +20,7 @@ Paper: arxiv.org/abs/2003.00295
20
20
  """
21
21
 
22
22
 
23
- from typing import Callable, Dict, List, Optional, Tuple, Union
23
+ from typing import Callable, Optional, Union
24
24
 
25
25
  import numpy as np
26
26
 
@@ -93,12 +93,12 @@ class FedAdam(FedOpt):
93
93
  min_available_clients: int = 2,
94
94
  evaluate_fn: Optional[
95
95
  Callable[
96
- [int, NDArrays, Dict[str, Scalar]],
97
- Optional[Tuple[float, Dict[str, Scalar]]],
96
+ [int, NDArrays, dict[str, Scalar]],
97
+ Optional[tuple[float, dict[str, Scalar]]],
98
98
  ]
99
99
  ] = None,
100
- on_fit_config_fn: Optional[Callable[[int], Dict[str, Scalar]]] = None,
101
- on_evaluate_config_fn: Optional[Callable[[int], Dict[str, Scalar]]] = None,
100
+ on_fit_config_fn: Optional[Callable[[int], dict[str, Scalar]]] = None,
101
+ on_evaluate_config_fn: Optional[Callable[[int], dict[str, Scalar]]] = None,
102
102
  accept_failures: bool = True,
103
103
  initial_parameters: Parameters,
104
104
  fit_metrics_aggregation_fn: Optional[MetricsAggregationFn] = None,
@@ -137,9 +137,9 @@ class FedAdam(FedOpt):
137
137
  def aggregate_fit(
138
138
  self,
139
139
  server_round: int,
140
- results: List[Tuple[ClientProxy, FitRes]],
141
- failures: List[Union[Tuple[ClientProxy, FitRes], BaseException]],
142
- ) -> Tuple[Optional[Parameters], Dict[str, Scalar]]:
140
+ results: list[tuple[ClientProxy, FitRes]],
141
+ failures: list[Union[tuple[ClientProxy, FitRes], BaseException]],
142
+ ) -> tuple[Optional[Parameters], dict[str, Scalar]]:
143
143
  """Aggregate fit results using weighted average."""
144
144
  fedavg_parameters_aggregated, metrics_aggregated = super().aggregate_fit(
145
145
  server_round=server_round, results=results, failures=failures
@@ -19,7 +19,7 @@ Paper: arxiv.org/abs/1602.05629
19
19
 
20
20
 
21
21
  from logging import WARNING
22
- from typing import Callable, Dict, List, Optional, Tuple, Union
22
+ from typing import Callable, Optional, Union
23
23
 
24
24
  from flwr.common import (
25
25
  EvaluateIns,
@@ -99,12 +99,12 @@ class FedAvg(Strategy):
99
99
  min_available_clients: int = 2,
100
100
  evaluate_fn: Optional[
101
101
  Callable[
102
- [int, NDArrays, Dict[str, Scalar]],
103
- Optional[Tuple[float, Dict[str, Scalar]]],
102
+ [int, NDArrays, dict[str, Scalar]],
103
+ Optional[tuple[float, dict[str, Scalar]]],
104
104
  ]
105
105
  ] = None,
106
- on_fit_config_fn: Optional[Callable[[int], Dict[str, Scalar]]] = None,
107
- on_evaluate_config_fn: Optional[Callable[[int], Dict[str, Scalar]]] = None,
106
+ on_fit_config_fn: Optional[Callable[[int], dict[str, Scalar]]] = None,
107
+ on_evaluate_config_fn: Optional[Callable[[int], dict[str, Scalar]]] = None,
108
108
  accept_failures: bool = True,
109
109
  initial_parameters: Optional[Parameters] = None,
110
110
  fit_metrics_aggregation_fn: Optional[MetricsAggregationFn] = None,
@@ -138,12 +138,12 @@ class FedAvg(Strategy):
138
138
  rep = f"FedAvg(accept_failures={self.accept_failures})"
139
139
  return rep
140
140
 
141
- def num_fit_clients(self, num_available_clients: int) -> Tuple[int, int]:
141
+ def num_fit_clients(self, num_available_clients: int) -> tuple[int, int]:
142
142
  """Return the sample size and the required number of available clients."""
143
143
  num_clients = int(num_available_clients * self.fraction_fit)
144
144
  return max(num_clients, self.min_fit_clients), self.min_available_clients
145
145
 
146
- def num_evaluation_clients(self, num_available_clients: int) -> Tuple[int, int]:
146
+ def num_evaluation_clients(self, num_available_clients: int) -> tuple[int, int]:
147
147
  """Use a fraction of available clients for evaluation."""
148
148
  num_clients = int(num_available_clients * self.fraction_evaluate)
149
149
  return max(num_clients, self.min_evaluate_clients), self.min_available_clients
@@ -158,7 +158,7 @@ class FedAvg(Strategy):
158
158
 
159
159
  def evaluate(
160
160
  self, server_round: int, parameters: Parameters
161
- ) -> Optional[Tuple[float, Dict[str, Scalar]]]:
161
+ ) -> Optional[tuple[float, dict[str, Scalar]]]:
162
162
  """Evaluate model parameters using an evaluation function."""
163
163
  if self.evaluate_fn is None:
164
164
  # No evaluation function provided
@@ -172,7 +172,7 @@ class FedAvg(Strategy):
172
172
 
173
173
  def configure_fit(
174
174
  self, server_round: int, parameters: Parameters, client_manager: ClientManager
175
- ) -> List[Tuple[ClientProxy, FitIns]]:
175
+ ) -> list[tuple[ClientProxy, FitIns]]:
176
176
  """Configure the next round of training."""
177
177
  config = {}
178
178
  if self.on_fit_config_fn is not None:
@@ -193,7 +193,7 @@ class FedAvg(Strategy):
193
193
 
194
194
  def configure_evaluate(
195
195
  self, server_round: int, parameters: Parameters, client_manager: ClientManager
196
- ) -> List[Tuple[ClientProxy, EvaluateIns]]:
196
+ ) -> list[tuple[ClientProxy, EvaluateIns]]:
197
197
  """Configure the next round of evaluation."""
198
198
  # Do not configure federated evaluation if fraction eval is 0.
199
199
  if self.fraction_evaluate == 0.0:
@@ -220,9 +220,9 @@ class FedAvg(Strategy):
220
220
  def aggregate_fit(
221
221
  self,
222
222
  server_round: int,
223
- results: List[Tuple[ClientProxy, FitRes]],
224
- failures: List[Union[Tuple[ClientProxy, FitRes], BaseException]],
225
- ) -> Tuple[Optional[Parameters], Dict[str, Scalar]]:
223
+ results: list[tuple[ClientProxy, FitRes]],
224
+ failures: list[Union[tuple[ClientProxy, FitRes], BaseException]],
225
+ ) -> tuple[Optional[Parameters], dict[str, Scalar]]:
226
226
  """Aggregate fit results using weighted average."""
227
227
  if not results:
228
228
  return None, {}
@@ -256,9 +256,9 @@ class FedAvg(Strategy):
256
256
  def aggregate_evaluate(
257
257
  self,
258
258
  server_round: int,
259
- results: List[Tuple[ClientProxy, EvaluateRes]],
260
- failures: List[Union[Tuple[ClientProxy, EvaluateRes], BaseException]],
261
- ) -> Tuple[Optional[float], Dict[str, Scalar]]:
259
+ results: list[tuple[ClientProxy, EvaluateRes]],
260
+ failures: list[Union[tuple[ClientProxy, EvaluateRes], BaseException]],
261
+ ) -> tuple[Optional[float], dict[str, Scalar]]:
262
262
  """Aggregate evaluation losses using weighted average."""
263
263
  if not results:
264
264
  return None, {}
@@ -18,7 +18,7 @@ Paper: arxiv.org/abs/1602.05629
18
18
  """
19
19
 
20
20
 
21
- from typing import Callable, Dict, List, Optional, Tuple, Union, cast
21
+ from typing import Callable, Optional, Union, cast
22
22
 
23
23
  import numpy as np
24
24
 
@@ -81,12 +81,12 @@ class FedAvgAndroid(Strategy):
81
81
  min_available_clients: int = 2,
82
82
  evaluate_fn: Optional[
83
83
  Callable[
84
- [int, NDArrays, Dict[str, Scalar]],
85
- Optional[Tuple[float, Dict[str, Scalar]]],
84
+ [int, NDArrays, dict[str, Scalar]],
85
+ Optional[tuple[float, dict[str, Scalar]]],
86
86
  ]
87
87
  ] = None,
88
- on_fit_config_fn: Optional[Callable[[int], Dict[str, Scalar]]] = None,
89
- on_evaluate_config_fn: Optional[Callable[[int], Dict[str, Scalar]]] = None,
88
+ on_fit_config_fn: Optional[Callable[[int], dict[str, Scalar]]] = None,
89
+ on_evaluate_config_fn: Optional[Callable[[int], dict[str, Scalar]]] = None,
90
90
  accept_failures: bool = True,
91
91
  initial_parameters: Optional[Parameters] = None,
92
92
  ) -> None:
@@ -107,12 +107,12 @@ class FedAvgAndroid(Strategy):
107
107
  rep = f"FedAvg(accept_failures={self.accept_failures})"
108
108
  return rep
109
109
 
110
- def num_fit_clients(self, num_available_clients: int) -> Tuple[int, int]:
110
+ def num_fit_clients(self, num_available_clients: int) -> tuple[int, int]:
111
111
  """Return the sample size and the required number of available clients."""
112
112
  num_clients = int(num_available_clients * self.fraction_fit)
113
113
  return max(num_clients, self.min_fit_clients), self.min_available_clients
114
114
 
115
- def num_evaluation_clients(self, num_available_clients: int) -> Tuple[int, int]:
115
+ def num_evaluation_clients(self, num_available_clients: int) -> tuple[int, int]:
116
116
  """Use a fraction of available clients for evaluation."""
117
117
  num_clients = int(num_available_clients * self.fraction_evaluate)
118
118
  return max(num_clients, self.min_evaluate_clients), self.min_available_clients
@@ -127,7 +127,7 @@ class FedAvgAndroid(Strategy):
127
127
 
128
128
  def evaluate(
129
129
  self, server_round: int, parameters: Parameters
130
- ) -> Optional[Tuple[float, Dict[str, Scalar]]]:
130
+ ) -> Optional[tuple[float, dict[str, Scalar]]]:
131
131
  """Evaluate model parameters using an evaluation function."""
132
132
  if self.evaluate_fn is None:
133
133
  # No evaluation function provided
@@ -141,7 +141,7 @@ class FedAvgAndroid(Strategy):
141
141
 
142
142
  def configure_fit(
143
143
  self, server_round: int, parameters: Parameters, client_manager: ClientManager
144
- ) -> List[Tuple[ClientProxy, FitIns]]:
144
+ ) -> list[tuple[ClientProxy, FitIns]]:
145
145
  """Configure the next round of training."""
146
146
  config = {}
147
147
  if self.on_fit_config_fn is not None:
@@ -162,7 +162,7 @@ class FedAvgAndroid(Strategy):
162
162
 
163
163
  def configure_evaluate(
164
164
  self, server_round: int, parameters: Parameters, client_manager: ClientManager
165
- ) -> List[Tuple[ClientProxy, EvaluateIns]]:
165
+ ) -> list[tuple[ClientProxy, EvaluateIns]]:
166
166
  """Configure the next round of evaluation."""
167
167
  # Do not configure federated evaluation if fraction_evaluate is 0
168
168
  if self.fraction_evaluate == 0.0:
@@ -189,9 +189,9 @@ class FedAvgAndroid(Strategy):
189
189
  def aggregate_fit(
190
190
  self,
191
191
  server_round: int,
192
- results: List[Tuple[ClientProxy, FitRes]],
193
- failures: List[Union[Tuple[ClientProxy, FitRes], BaseException]],
194
- ) -> Tuple[Optional[Parameters], Dict[str, Scalar]]:
192
+ results: list[tuple[ClientProxy, FitRes]],
193
+ failures: list[Union[tuple[ClientProxy, FitRes], BaseException]],
194
+ ) -> tuple[Optional[Parameters], dict[str, Scalar]]:
195
195
  """Aggregate fit results using weighted average."""
196
196
  if not results:
197
197
  return None, {}
@@ -208,9 +208,9 @@ class FedAvgAndroid(Strategy):
208
208
  def aggregate_evaluate(
209
209
  self,
210
210
  server_round: int,
211
- results: List[Tuple[ClientProxy, EvaluateRes]],
212
- failures: List[Union[Tuple[ClientProxy, EvaluateRes], BaseException]],
213
- ) -> Tuple[Optional[float], Dict[str, Scalar]]:
211
+ results: list[tuple[ClientProxy, EvaluateRes]],
212
+ failures: list[Union[tuple[ClientProxy, EvaluateRes], BaseException]],
213
+ ) -> tuple[Optional[float], dict[str, Scalar]]:
214
214
  """Aggregate evaluation losses using weighted average."""
215
215
  if not results:
216
216
  return None, {}
@@ -19,7 +19,7 @@ Paper: arxiv.org/pdf/1909.06335.pdf
19
19
 
20
20
 
21
21
  from logging import WARNING
22
- from typing import Callable, Dict, List, Optional, Tuple, Union
22
+ from typing import Callable, Optional, Union
23
23
 
24
24
  from flwr.common import (
25
25
  FitRes,
@@ -84,12 +84,12 @@ class FedAvgM(FedAvg):
84
84
  min_available_clients: int = 2,
85
85
  evaluate_fn: Optional[
86
86
  Callable[
87
- [int, NDArrays, Dict[str, Scalar]],
88
- Optional[Tuple[float, Dict[str, Scalar]]],
87
+ [int, NDArrays, dict[str, Scalar]],
88
+ Optional[tuple[float, dict[str, Scalar]]],
89
89
  ]
90
90
  ] = None,
91
- on_fit_config_fn: Optional[Callable[[int], Dict[str, Scalar]]] = None,
92
- on_evaluate_config_fn: Optional[Callable[[int], Dict[str, Scalar]]] = None,
91
+ on_fit_config_fn: Optional[Callable[[int], dict[str, Scalar]]] = None,
92
+ on_evaluate_config_fn: Optional[Callable[[int], dict[str, Scalar]]] = None,
93
93
  accept_failures: bool = True,
94
94
  initial_parameters: Optional[Parameters] = None,
95
95
  fit_metrics_aggregation_fn: Optional[MetricsAggregationFn] = None,
@@ -132,9 +132,9 @@ class FedAvgM(FedAvg):
132
132
  def aggregate_fit(
133
133
  self,
134
134
  server_round: int,
135
- results: List[Tuple[ClientProxy, FitRes]],
136
- failures: List[Union[Tuple[ClientProxy, FitRes], BaseException]],
137
- ) -> Tuple[Optional[Parameters], Dict[str, Scalar]]:
135
+ results: list[tuple[ClientProxy, FitRes]],
136
+ failures: list[Union[tuple[ClientProxy, FitRes], BaseException]],
137
+ ) -> tuple[Optional[Parameters], dict[str, Scalar]]:
138
138
  """Aggregate fit results using weighted average."""
139
139
  if not results:
140
140
  return None, {}
@@ -19,7 +19,7 @@ Paper: arxiv.org/pdf/1803.01498v1.pdf
19
19
 
20
20
 
21
21
  from logging import WARNING
22
- from typing import Dict, List, Optional, Tuple, Union
22
+ from typing import Optional, Union
23
23
 
24
24
  from flwr.common import (
25
25
  FitRes,
@@ -46,9 +46,9 @@ class FedMedian(FedAvg):
46
46
  def aggregate_fit(
47
47
  self,
48
48
  server_round: int,
49
- results: List[Tuple[ClientProxy, FitRes]],
50
- failures: List[Union[Tuple[ClientProxy, FitRes], BaseException]],
51
- ) -> Tuple[Optional[Parameters], Dict[str, Scalar]]:
49
+ results: list[tuple[ClientProxy, FitRes]],
50
+ failures: list[Union[tuple[ClientProxy, FitRes], BaseException]],
51
+ ) -> tuple[Optional[Parameters], dict[str, Scalar]]:
52
52
  """Aggregate fit results using median."""
53
53
  if not results:
54
54
  return None, {}
@@ -18,7 +18,7 @@ Paper: arxiv.org/abs/2003.00295
18
18
  """
19
19
 
20
20
 
21
- from typing import Callable, Dict, Optional, Tuple
21
+ from typing import Callable, Optional
22
22
 
23
23
  from flwr.common import (
24
24
  MetricsAggregationFn,
@@ -86,12 +86,12 @@ class FedOpt(FedAvg):
86
86
  min_available_clients: int = 2,
87
87
  evaluate_fn: Optional[
88
88
  Callable[
89
- [int, NDArrays, Dict[str, Scalar]],
90
- Optional[Tuple[float, Dict[str, Scalar]]],
89
+ [int, NDArrays, dict[str, Scalar]],
90
+ Optional[tuple[float, dict[str, Scalar]]],
91
91
  ]
92
92
  ] = None,
93
- on_fit_config_fn: Optional[Callable[[int], Dict[str, Scalar]]] = None,
94
- on_evaluate_config_fn: Optional[Callable[[int], Dict[str, Scalar]]] = None,
93
+ on_fit_config_fn: Optional[Callable[[int], dict[str, Scalar]]] = None,
94
+ on_evaluate_config_fn: Optional[Callable[[int], dict[str, Scalar]]] = None,
95
95
  accept_failures: bool = True,
96
96
  initial_parameters: Parameters,
97
97
  fit_metrics_aggregation_fn: Optional[MetricsAggregationFn] = None,
@@ -18,7 +18,7 @@ Paper: arxiv.org/abs/1812.06127
18
18
  """
19
19
 
20
20
 
21
- from typing import Callable, Dict, List, Optional, Tuple
21
+ from typing import Callable, Optional
22
22
 
23
23
  from flwr.common import FitIns, MetricsAggregationFn, NDArrays, Parameters, Scalar
24
24
  from flwr.server.client_manager import ClientManager
@@ -113,12 +113,12 @@ class FedProx(FedAvg):
113
113
  min_available_clients: int = 2,
114
114
  evaluate_fn: Optional[
115
115
  Callable[
116
- [int, NDArrays, Dict[str, Scalar]],
117
- Optional[Tuple[float, Dict[str, Scalar]]],
116
+ [int, NDArrays, dict[str, Scalar]],
117
+ Optional[tuple[float, dict[str, Scalar]]],
118
118
  ]
119
119
  ] = None,
120
- on_fit_config_fn: Optional[Callable[[int], Dict[str, Scalar]]] = None,
121
- on_evaluate_config_fn: Optional[Callable[[int], Dict[str, Scalar]]] = None,
120
+ on_fit_config_fn: Optional[Callable[[int], dict[str, Scalar]]] = None,
121
+ on_evaluate_config_fn: Optional[Callable[[int], dict[str, Scalar]]] = None,
122
122
  accept_failures: bool = True,
123
123
  initial_parameters: Optional[Parameters] = None,
124
124
  fit_metrics_aggregation_fn: Optional[MetricsAggregationFn] = None,
@@ -148,7 +148,7 @@ class FedProx(FedAvg):
148
148
 
149
149
  def configure_fit(
150
150
  self, server_round: int, parameters: Parameters, client_manager: ClientManager
151
- ) -> List[Tuple[ClientProxy, FitIns]]:
151
+ ) -> list[tuple[ClientProxy, FitIns]]:
152
152
  """Configure the next round of training.
153
153
 
154
154
  Sends the proximal factor mu to the clients
@@ -17,7 +17,7 @@
17
17
  Paper: arxiv.org/abs/1803.01498
18
18
  """
19
19
  from logging import WARNING
20
- from typing import Callable, Dict, List, Optional, Tuple, Union
20
+ from typing import Callable, Optional, Union
21
21
 
22
22
  from flwr.common import (
23
23
  FitRes,
@@ -78,12 +78,12 @@ class FedTrimmedAvg(FedAvg):
78
78
  min_available_clients: int = 2,
79
79
  evaluate_fn: Optional[
80
80
  Callable[
81
- [int, NDArrays, Dict[str, Scalar]],
82
- Optional[Tuple[float, Dict[str, Scalar]]],
81
+ [int, NDArrays, dict[str, Scalar]],
82
+ Optional[tuple[float, dict[str, Scalar]]],
83
83
  ]
84
84
  ] = None,
85
- on_fit_config_fn: Optional[Callable[[int], Dict[str, Scalar]]] = None,
86
- on_evaluate_config_fn: Optional[Callable[[int], Dict[str, Scalar]]] = None,
85
+ on_fit_config_fn: Optional[Callable[[int], dict[str, Scalar]]] = None,
86
+ on_evaluate_config_fn: Optional[Callable[[int], dict[str, Scalar]]] = None,
87
87
  accept_failures: bool = True,
88
88
  initial_parameters: Optional[Parameters] = None,
89
89
  fit_metrics_aggregation_fn: Optional[MetricsAggregationFn] = None,
@@ -114,9 +114,9 @@ class FedTrimmedAvg(FedAvg):
114
114
  def aggregate_fit(
115
115
  self,
116
116
  server_round: int,
117
- results: List[Tuple[ClientProxy, FitRes]],
118
- failures: List[Union[Tuple[ClientProxy, FitRes], BaseException]],
119
- ) -> Tuple[Optional[Parameters], Dict[str, Scalar]]:
117
+ results: list[tuple[ClientProxy, FitRes]],
118
+ failures: list[Union[tuple[ClientProxy, FitRes], BaseException]],
119
+ ) -> tuple[Optional[Parameters], dict[str, Scalar]]:
120
120
  """Aggregate fit results using trimmed average."""
121
121
  if not results:
122
122
  return None, {}
@@ -17,7 +17,7 @@
17
17
 
18
18
  import json
19
19
  from logging import WARNING
20
- from typing import Any, Callable, Dict, List, Optional, Tuple, Union, cast
20
+ from typing import Any, Callable, Optional, Union, cast
21
21
 
22
22
  from flwr.common import EvaluateRes, FitRes, Parameters, Scalar
23
23
  from flwr.common.logger import log
@@ -34,8 +34,8 @@ class FedXgbBagging(FedAvg):
34
34
  self,
35
35
  evaluate_function: Optional[
36
36
  Callable[
37
- [int, Parameters, Dict[str, Scalar]],
38
- Optional[Tuple[float, Dict[str, Scalar]]],
37
+ [int, Parameters, dict[str, Scalar]],
38
+ Optional[tuple[float, dict[str, Scalar]]],
39
39
  ]
40
40
  ] = None,
41
41
  **kwargs: Any,
@@ -52,9 +52,9 @@ class FedXgbBagging(FedAvg):
52
52
  def aggregate_fit(
53
53
  self,
54
54
  server_round: int,
55
- results: List[Tuple[ClientProxy, FitRes]],
56
- failures: List[Union[Tuple[ClientProxy, FitRes], BaseException]],
57
- ) -> Tuple[Optional[Parameters], Dict[str, Scalar]]:
55
+ results: list[tuple[ClientProxy, FitRes]],
56
+ failures: list[Union[tuple[ClientProxy, FitRes], BaseException]],
57
+ ) -> tuple[Optional[Parameters], dict[str, Scalar]]:
58
58
  """Aggregate fit results using bagging."""
59
59
  if not results:
60
60
  return None, {}
@@ -79,9 +79,9 @@ class FedXgbBagging(FedAvg):
79
79
  def aggregate_evaluate(
80
80
  self,
81
81
  server_round: int,
82
- results: List[Tuple[ClientProxy, EvaluateRes]],
83
- failures: List[Union[Tuple[ClientProxy, EvaluateRes], BaseException]],
84
- ) -> Tuple[Optional[float], Dict[str, Scalar]]:
82
+ results: list[tuple[ClientProxy, EvaluateRes]],
83
+ failures: list[Union[tuple[ClientProxy, EvaluateRes], BaseException]],
84
+ ) -> tuple[Optional[float], dict[str, Scalar]]:
85
85
  """Aggregate evaluation metrics using average."""
86
86
  if not results:
87
87
  return None, {}
@@ -101,7 +101,7 @@ class FedXgbBagging(FedAvg):
101
101
 
102
102
  def evaluate(
103
103
  self, server_round: int, parameters: Parameters
104
- ) -> Optional[Tuple[float, Dict[str, Scalar]]]:
104
+ ) -> Optional[tuple[float, dict[str, Scalar]]]:
105
105
  """Evaluate model parameters using an evaluation function."""
106
106
  if self.evaluate_function is None:
107
107
  # No evaluation function provided
@@ -152,7 +152,7 @@ def aggregate(
152
152
  return bst_prev_bytes
153
153
 
154
154
 
155
- def _get_tree_nums(xgb_model_org: bytes) -> Tuple[int, int]:
155
+ def _get_tree_nums(xgb_model_org: bytes) -> tuple[int, int]:
156
156
  xgb_model = json.loads(bytearray(xgb_model_org))
157
157
  # Get the number of trees
158
158
  tree_num = int(
@@ -16,7 +16,7 @@
16
16
 
17
17
 
18
18
  from logging import WARNING
19
- from typing import Any, Dict, List, Optional, Tuple, Union, cast
19
+ from typing import Any, Optional, Union, cast
20
20
 
21
21
  from flwr.common import EvaluateIns, EvaluateRes, FitIns, FitRes, Parameters, Scalar
22
22
  from flwr.common.logger import log
@@ -45,9 +45,9 @@ class FedXgbCyclic(FedAvg):
45
45
  def aggregate_fit(
46
46
  self,
47
47
  server_round: int,
48
- results: List[Tuple[ClientProxy, FitRes]],
49
- failures: List[Union[Tuple[ClientProxy, FitRes], BaseException]],
50
- ) -> Tuple[Optional[Parameters], Dict[str, Scalar]]:
48
+ results: list[tuple[ClientProxy, FitRes]],
49
+ failures: list[Union[tuple[ClientProxy, FitRes], BaseException]],
50
+ ) -> tuple[Optional[Parameters], dict[str, Scalar]]:
51
51
  """Aggregate fit results using bagging."""
52
52
  if not results:
53
53
  return None, {}
@@ -69,9 +69,9 @@ class FedXgbCyclic(FedAvg):
69
69
  def aggregate_evaluate(
70
70
  self,
71
71
  server_round: int,
72
- results: List[Tuple[ClientProxy, EvaluateRes]],
73
- failures: List[Union[Tuple[ClientProxy, EvaluateRes], BaseException]],
74
- ) -> Tuple[Optional[float], Dict[str, Scalar]]:
72
+ results: list[tuple[ClientProxy, EvaluateRes]],
73
+ failures: list[Union[tuple[ClientProxy, EvaluateRes], BaseException]],
74
+ ) -> tuple[Optional[float], dict[str, Scalar]]:
75
75
  """Aggregate evaluation metrics using average."""
76
76
  if not results:
77
77
  return None, {}
@@ -91,7 +91,7 @@ class FedXgbCyclic(FedAvg):
91
91
 
92
92
  def configure_fit(
93
93
  self, server_round: int, parameters: Parameters, client_manager: ClientManager
94
- ) -> List[Tuple[ClientProxy, FitIns]]:
94
+ ) -> list[tuple[ClientProxy, FitIns]]:
95
95
  """Configure the next round of training."""
96
96
  config = {}
97
97
  if self.on_fit_config_fn is not None:
@@ -117,7 +117,7 @@ class FedXgbCyclic(FedAvg):
117
117
 
118
118
  def configure_evaluate(
119
119
  self, server_round: int, parameters: Parameters, client_manager: ClientManager
120
- ) -> List[Tuple[ClientProxy, EvaluateIns]]:
120
+ ) -> list[tuple[ClientProxy, EvaluateIns]]:
121
121
  """Configure the next round of evaluation."""
122
122
  # Do not configure federated evaluation if fraction eval is 0.
123
123
  if self.fraction_evaluate == 0.0: