I’m implementing the SCAFFOLD algorithm (https://arxiv.org/abs/1910.06378) in TensorFlow Federated, which needs stateful clients. I based my work on the answer to this Stackoverflow post, but I cannot manage to correctly initialize the ‘client_states’. For initializing them, I created the following function
@tff.federated_computation def intialize_client_state(): return tff.federated_value(server_init(), tff.CLIENTS)
, and call it right after iterative_process.initialize() (which initializes the server’s weights). By doing this, I got the following error in the line where I call “initialize_client_state”:
ValueError: Expected at least one participant for the 'CLIENTS' placement, found none. It is possible that the inferred number of clients is 0, you can explicitly pass `num_clients` when constructing the execution stack
What am I doing wrong ? How should I initialize the clients’ states ?
Thanks in advance.
If you only execute that computation, the executor does not know what number of clients to expect, as the error hints at. You can set the number of clients by invoking
tff.backends.native.set_local_execution_context with the
default_num_clients you expect, somewhere at the start of your Python code.
Alternatively, if the initial client state is the same for all, you can create the state once, and have a list containing one copy of the state per client.