I want to implement an FL algorithm and run it like flower-simulation-step-by-step-pytorch. Therefore, I have to change the strategy from the line 55 to 78 in the main.py file. Suppose my strategy name is FedNew. What steps should I follow to do this type of strategy implementation? If there is any example code available please share.
Thank you
Hi @ruhul5347, you could customise a new strategy (e.g., inherited from FedAvg) as below:
class FedNew(flwr.server.strategy.FedAvg):
def __init__(**kwargs: Any,)
# define any new arguments
super().__init__(**kwargs)
def aggregate_fit(
self,
server_round: int,
results: List[Tuple[ClientProxy, FitRes]],
failures: List[Union[Tuple[ClientProxy, FitRes], BaseException]],
) -> Tuple[Optional[Parameters], Dict[str, Scalar]]:
# define new aggregation methods here
def configure_fit(
self, rnd: int, parameters: Parameters, client_manager: ClientManager
) -> List[Tuple[ClientProxy, FitIns]]:
# override client sampling method if needed
Note that aggregate_fit()
and configure_fit()
are for training. If doing changes for evaluation, then override aggregate_evaluate()
and configure_evaluate()
.
Then, call this new FedNew
strategy similar to line 68 in main.py.
strategy = FedNew(...)
4 Likes