如何使用 TensorFlow Federated 框架在有状态联邦学习中初始化客户端状态?
How to initialize clients' states in stateful Federated Learning, using the TensorFlow Federated framework?
我正在实现 SCAFFOLD 算法(https://arxiv.org/abs/1910.06378) in TensorFlow Federated, which needs stateful clients. I based my work on the answer to this ,但我无法正确初始化 'client_states'。为了初始化它们,我创建了以下函数
@tff.federated_computation
def intialize_client_state():
return tff.federated_value(server_init(), tff.CLIENTS)
,并在 iterative_process.initialize()(初始化服务器的权重)之后立即调用它。通过这样做,我在调用“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
我做错了什么?我应该如何初始化客户端的状态?
提前致谢。
如果你只执行那个计算,执行者不知道预期的客户端数量,正如错误提示的那样。您可以通过在 Python 代码开头的某处使用您期望的 default_num_clients
调用 tff.backends.native.set_local_execution_context
来设置客户端数量。
或者,如果所有客户端的初始状态都相同,您可以创建状态一次,并为每个客户端创建一个包含状态副本的列表。
我正在实现 SCAFFOLD 算法(https://arxiv.org/abs/1910.06378) in TensorFlow Federated, which needs stateful clients. I based my work on the answer to this
@tff.federated_computation
def intialize_client_state():
return tff.federated_value(server_init(), tff.CLIENTS)
,并在 iterative_process.initialize()(初始化服务器的权重)之后立即调用它。通过这样做,我在调用“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
我做错了什么?我应该如何初始化客户端的状态?
提前致谢。
如果你只执行那个计算,执行者不知道预期的客户端数量,正如错误提示的那样。您可以通过在 Python 代码开头的某处使用您期望的 default_num_clients
调用 tff.backends.native.set_local_execution_context
来设置客户端数量。
或者,如果所有客户端的初始状态都相同,您可以创建状态一次,并为每个客户端创建一个包含状态副本的列表。