Server-Edges-Clients Settings

Hello Everyone,
I’ve made progress and answered my questions here. When I finish it, I am planning to make the code public. However, I find myself having some additional questions.

The setup involving a main server, 2 edges, and 10 clients. Initially, both edges serve as servers for their clients, conducting federated learning and saving their final edge models as Edge1_checkpoints and Edge2_checkpoints following thr step in How do I save the global model after training?


#Server.py:

ROUNDS=1

def run_main_server() -> None:

strategy = fl.server.strategy.FedAvg( )

fl.server.start_server(
server_address="0.0.0.0:8888",
config=fl.server.ServerConfig(num_rounds=ROUNDS),
strategy=strategy,
)


if __name__ == "__main__":
run_main_server()

#Edge.py:
def run_client()-> None:

class FlowerClient(fl.client.NumPyClient):
      def get_parameters(self, config): 
            # "parameters_round_2.pkl" is the file with weights in the last round on the Edge1_checkpoints
            with open(os.path.join('HFL/Edge1_checkpoints', "parameters_round_2.pkl"), 'rb') as f:
                model_dict = pickle.load(f)
                weights = model_dict['globa_parameters']
                return weights


fl.client.start_numpy_client(server_address="127.0.0.0:8088", client=FlowerClient())


if __name__ == "__main__":
run_client()

My questions are:

  1. As described here: https://flower.ai/docs/framework/tutorial-series-use-a-federated-learning-strategy-pytorch.html Flower, by default, initializes the global model by asking one random client for the initial parameter through def get_parameters(self, config), How can I ensure that both models are sent to the server for aggregation?

  2. In global federated Averaging, after summing all edge parameters, do we divide it by the number of edges(2) or the number of training data under each edge?

  3. Is it possible for the client to have only the get_parameters(self, config) function if the intention is solely to send the edge model to the server for aggregation? In such a scenario, would including functions like evaluate() and fit() be meaningless, considering there is no training conducted on the edge and no evaluation required?

Thank you in Advance.

3 Likes