adap / flower

Flower: A Friendly Federated AI Framework
https://flower.ai
Apache License 2.0
5.09k stars 875 forks source link

Sever config should be passed to the client when retrieving the initial parameters #3770

Open scarere opened 4 months ago

scarere commented 4 months ago

Describe the type of feature and its functionality.

Currently, when the Server class initialises the global model parameters by randomly sampling a client, it provides an empty config. In my particular case, the client requires information from the server in order to initialise the model and hence the model parameters.

The proposed feature is to allow information to be passed from the server to the client during initialisation of global model parameters

Describe step by step what files and adjustments are you planning to include.

I see two ways of implementing this.

1. Create an optional argument to the Server class in server.py.

Either a dictionary (eg. init_params_config) or a function similar to on_fit_config_fn (eg. on_init_config_fn). Although a function might be overkill if we don't have any variables to pass to it. Use this argument to get a config for parameter initialization and on line 281 of server.py change ins = GetParametersIns(config={}) to ins = GetParametersIns(config=self.init_params_config)

2. Use the config from on_fit_config_fn

Replace line 281 of server.py with:

config = self.strategy.on_fit_config_fn(-1) # server round is -1
ins = GetParametersIns(config=config)

Is there something else you want to add?

This seems like a really easy feature to implement that provides a lot of immediate value. It also just seems natural. Whats the point of GetParameterIns if it is only used in Server._get_initial_parameters() where an empty dict is passed to it?

scarere commented 3 months ago

Probably would be good to add the 'good first issue' label as this is a simple change