share custom data between the server and one client

Hi everyone,

I need to pass some initialization parameters to the client class and use them within its init method. Is there an easy way to send custom information from the server to the client at this point? I mean I know about callbacks which fit_config and evaluate_config but I need to have my information available within the init.

PS likely these information come from command line params passed when the main is run, then the main passes them to the server but I cannot send them to all clients

Thanks a lot for the usual great support.

1 Like

Hey @gm000 ,

Great question! One of the best ways to pass configs to initialize your Clients is via either the run config or the node config.

I’m assuming you are familiar with the quickstart-pytorch example in the Flower repo. The client_fn function instantiates your Client. Note that this function receives as input argument an object of type Context. You can read the run config as shown below.

def client_fn(context: Context):
    """Construct a Client that will be run in a ClientApp."""

    ...

    # Read the "batch-size" config from the Run config
    batch_size = context.run_config["batch-size"]
    learning_rate = context.run_config["learning-rate"]

    # Instantiate your client
    return FlowerClient(...)

The above batch_size and learning_rate that are in the run config are defined in the pyproject.toml of your Flower App. If you inspect such file from the example you’ll see:


[tool.flwr.app.config]
num-server-rounds = 3
fraction-evaluate = 0.5
local-epochs = 1
learning-rate = 0.1
batch-size = 32

You can ofcourse change those values. Note none of these values are compulsory in Flower. So may add more (e.g. L2 regularization) if you want your ClientApp to make use of it during training – but for that you also need to implement the code.

I hope this helps!!

PS: the other way of passing configs is via the node config. Note that this is only possible when using Flower’ deployment engine (i.e. it’s not possible during simulation). With the deployment engine you’ll set a node config like this:

flower-supernode <args> --node-config="path-to-data='....' another-arg=123"

and your ClientApp will be able to read that info at run time via context.node_config

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.