gpt4 book ai didi

tensorflow-federated - Tensorflow 联合 : How to map the remote-worker with remote datasets in iterative_process. 下一个?

转载 作者:行者123 更新时间:2023-12-04 08:53:44 24 4
gpt4 key购买 nike

我想将 federated_train_data 指向远程客户端数据,如下面的代码所示。这可能吗?如何 ?
如果不是,我需要什么进一步的实现来尝试这个。请指点我相关的代码。

factory = tff.framework.create_executor_factory(make_remote_executor)
context = tff.framework.ExecutionContext(factory)
tff.framework.set_default_context(context)

state = iterative_process.initialize()

state, metrics = iterative_process.next(state, federated_train_data)
def make_remote_executor(inferred_cardinalities):
"""Make remote executor."""

def create_worker_stack(ex):
ex = tff.framework.ThreadDelegatingExecutor(ex)
return tff.framework.ReferenceResolvingExecutor(ex)

client_ex = []
num_clients = inferred_cardinalities.get(tff.CLIENTS, None)
if num_clients:
print('Inferred that there are {} clients'.format(num_clients))
else:
print('No CLIENTS placement provided')

for _ in range(num_clients or 0):
channel = grpc.insecure_channel('{}:{}'.format(FLAGS.host, FLAGS.port))
remote_ex = tff.framework.RemoteExecutor(channel, rpc_mode='STREAMING')
worker_stack = create_worker_stack(remote_ex)
client_ex.append(worker_stack)

federating_strategy_factory = tff.framework.FederatedResolvingStrategy.factory(
{
tff.SERVER: create_worker_stack(tff.framework.EagerTFExecutor()),
tff.CLIENTS: client_ex,
})
unplaced_ex = create_worker_stack(tff.framework.EagerTFExecutor())
federating_ex = tff.framework.FederatingExecutor(federating_strategy_factory,
unplaced_ex)
return tff.framework.ReferenceResolvingExecutor(federating_ex)
这是来自 https://github.com/tensorflow/federated/blob/master/tensorflow_federated/python/examples/remote_execution/remote_executor_example.py

最佳答案

在链接的示例中,您可以看到客户端数据来自 tf.data.Dataset每个客户端由 make_federated data function 生成.
客户端数据可以以可序列化的形式提供 tf.data.Dataset或者,根据您定义迭代过程的方式,您可以 tff.federated_map使用 TensorFlow 将一些输入数据(例如客户端 ID)添加到数据集。
请注意,RemoteExecutors 并非旨在针对“客户端”上的数据运行,即在远程执行器本身上运行。它们或许可以通过 TensorFlow 代码以这种方式使用,以将数据从远程执行器的文件系统读取到数据集中,但通常这不是受支持的用例。处理客户端数据的推荐方法是使用可以生成 tf.data.Dataset 的 TensorFlow 计算。基于客户端 ID 或客户端 TensorFlow 计算的其他输入来表示客户端数据。

关于tensorflow-federated - Tensorflow 联合 : How to map the remote-worker with remote datasets in iterative_process. 下一个?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63955527/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com