Upgrade to Flower 1.0¶
Note
This guide is for users who have already worked with Flower 0.x and want to upgrade to Flower 1.0. Newer versions of Flower (1.13 and later) are based on a new architecture and not covered in this guide. After upgrading Flower 0.x projects to Flower 1.0, please refer to Upgrade to Flower 1.13 to make your project compatible with the lastest version of Flower.
Flower 1.0 is here. Along with new features, Flower 1.0 provides a stable foundation for future growth. Compared to Flower 0.19 (and other 0.x series releases), there are a few breaking changes that make it necessary to change the code of existing 0.x-series projects.
Install update¶
Here’s how to update an existing installation to Flower 1.0 using either pip or Poetry:
pip: add
-Uwhen installing.python -m pip install -U flwr(when usingstart_serverandstart_client)python -m pip install -U 'flwr[simulation]'(when usingstart_simulation)
Poetry: update the
flwrdependency inpyproject.tomland then reinstall (don’t forget to deletepoetry.lockviarm poetry.lockbefore runningpoetry install).flwr = "^1.0.0"(when usingstart_serverandstart_client)flwr = { version = "^1.0.0", extras = ["simulation"] }(when usingstart_simulation)
Required changes¶
The following breaking changes require manual updates.
General¶
Pass all arguments as keyword arguments (not as positional arguments). Here’s an example:
Flower 0.19 (positional arguments):
start_client("127.0.0.1:8080", FlowerClient())Flower 1.0 (keyword arguments):
start_client(server_address="127.0.0.1:8080", client=FlowerClient())
Client¶
Subclasses of
NumPyClient: changedef get_parameters(self):`todef get_parameters(self, config):Subclasses of
Client: changedef get_parameters(self):`todef get_parameters(self, ins: GetParametersIns):
Strategies / start_server / start_simulation¶
Pass
ServerConfig(instead of a dictionary) tostart_serverandstart_simulation. Here’s an example:Flower 0.19:
start_server(..., config={"num_rounds": 3, "round_timeout": 600.0}, ...)Flower 1.0:
start_server(..., config=flwr.server.ServerConfig(num_rounds=3, round_timeout=600.0), ...)
Replace
num_rounds=1instart_simulationwith the newconfig=ServerConfig(...)(see previous item)Remove
force_final_distributed_evalparameter from calls tostart_server. Distributed evaluation on all clients can be enabled by configuring the strategy to sample all clients for evaluation after the last round of training.Rename parameter/ndarray conversion functions:
parameters_to_weights–>parameters_to_ndarraysweights_to_parameters–>ndarrays_to_parameters
Strategy initialization: if the strategy relies on the default values for
fraction_fitandfraction_evaluate, setfraction_fitandfraction_evaluatemanually to0.1. Projects that do not manually create a strategy (by callingstart_serverorstart_simulationwithout passing a strategy instance) should now manually initialize FedAvg withfraction_fitandfraction_evaluateset to0.1.Rename built-in strategy parameters (e.g.,
FedAvg):fraction_eval–>fraction_evaluatemin_eval_clients–>min_evaluate_clientseval_fn–>evaluate_fn
Rename
rndtoserver_round. This impacts multiple methods and functions, for example,configure_fit,aggregate_fit,configure_evaluate,aggregate_evaluate, andevaluate_fn.Add
server_roundandconfigtoevaluate_fn:Flower 0.19:
def evaluate(parameters: NDArrays) -> Optional[Tuple[float, Dict[str, Scalar]]]:Flower 1.0:
def evaluate(server_round: int, parameters: NDArrays, config: Dict[str, Scalar]) -> Optional[Tuple[float, Dict[str, Scalar]]]:
Custom strategies¶
The type of parameter
failureshas changed fromList[BaseException]toList[Union[Tuple[ClientProxy, FitRes], BaseException]](inaggregate_fit) andList[Union[Tuple[ClientProxy, EvaluateRes], BaseException]](inaggregate_evaluate)The
Strategymethodevaluatenow receives the current round of federated learning/evaluation as the first parameter:Flower 0.19:
def evaluate(self, parameters: Parameters) -> Optional[Tuple[float, Dict[str, Scalar]]]:Flower 1.0:
def evaluate(self, server_round: int, parameters: Parameters) -> Optional[Tuple[float, Dict[str, Scalar]]]:
Optional improvements¶
Along with the necessary changes above, there are a number of potential improvements that just became possible:
Remove “placeholder” methods from subclasses of
ClientorNumPyClient. If you, for example, use server-side evaluation, then empty placeholder implementations ofevaluateare no longer necessary.Configure the round timeout via
start_simulation:start_simulation(..., config=flwr.server.ServerConfig(num_rounds=3, round_timeout=600.0), ...)
Further help¶
Most official Flower code examples are already updated to Flower 1.0,
they can serve as a reference for using the Flower 1.0 API. If there are further
questions, join the Flower Slack and use the channel
#questions.