I am doing a custom strategy with FedAVG as base strategy.
I was wondering, if there is any way to implement an Early stopping for the strategy, making use of the Flower framework methods, I haven’t seen in the documentation anything related to this, neither how to stop the federated training process manually.
Exactly! I was trying to do something like this, a FedAvg strategy but with early stopping (with patience, best_metric, counter, min_delta…), but then I couldn’t find any way to stop the federated training!
Let’s see if a Flower developer sees this, and recommends us a way to stop the process even if it is in a rudimentary way (closing gRPC communications e.g.) in the meanwhile.
Hi,
Unfortunately, I don’t think it’s currently possible to terminate the simulation earlier based on some external condition like early stopping (the server is started as a separate thread, and I don’t see a way to influence its behavior from the strategy level), but note that I haven’t been involved in the development. Maybe we’ll get a different response from @javier but we’ll have to wait a bit for his response (he’s currently not available).
What some people have done in the past is to modify slightly how the base Server works. Of particular interset is the fit for loop, which runs for the specified number of rounds. What you could do is to add a couple of lines that, given some logic in a custom strategy that you implement, it does the break from the for loop. Does it make sense?
Note you can pass a custom Server object when you write your server_fn that returns an instance of ServerAppComponents.
This is currently the best way to achieve early stopping. It will be easier with upcoming versions of flower.
There is another way: implement a custom strategy and, once your early stopping condition is reached, effectively disable the sampling on clients In this way the remaining rounds will go through but will do no work (which will make your experiment finish very fast).