我有以下问题。我想使用联邦学习来训练机器学习模型。为此,我想使用“flower”包,它用于服务器和客户端之间的通信 gRCP 协议。我无法让这种沟通发挥作用。
我的设置如下。我有一台 Windows10 主机,但我在 Ubuntu 虚拟机中开发所有代码。到目前为止,我对这个设置从来没有遇到过问题。但我没有问题,我用于客户端和服务器的相同代码可以在我的 Windows 主机上运行,但不能在我的 Ubuntu VM 上运行。
对于测试场景,我正在使用名为“helloworld”的 python 的 gRCP 包中的快速入门:https ://grpc.io/docs/languages/python/quickstart/
在客户端,我们有以下代码:
from concurrent import futures
import logging
import grpc
import helloworld_pb2
import helloworld_pb2_grpc
class Greeter(helloworld_pb2_grpc.GreeterServicer):
def SayHello(self, request, context):
return helloworld_pb2.HelloReply(message='Hello, %s!' % request.name)
def serve():
print('Starting server. Listening on port 50051.')
server = grpc.server(futures.ThreadPoolExecutor(max_workers=10))
helloworld_pb2_grpc.add_GreeterServicer_to_server(Greeter(), server)
server.add_insecure_port('[::]:50051')
server.start()
server.wait_for_termination()
if __name__ == '__main__':
logging.basicConfig()
serve()
在服务器端:
def run():
# NOTE(gRPC Python Team): .close() is possible on a channel and should be
# used in circumstances in which the with statement does not fit the needs
# of the code.
with grpc.insecure_channel('localhost:50051') as channel:
stub = helloworld_pb2_grpc.GreeterStub(channel)
response = stub.SayHello(helloworld_pb2.HelloRequest(name='you'))
print("Greeter client received: " + response.message)
if __name__ == '__main__':
logging.basicConfig()
run()
在 Windows 上使用此设置时,连接没有问题,而在 VM 中运行相同的代码时,会出现以下错误:
grpc._channel._InactiveRpcError: <_InactiveRpcError of RPC that terminated with:
status = StatusCode.UNAVAILABLE
details = "failed to connect to all addresses"
debug_error_string = "{"created":"@1644307702.209907738","description":"Failed to pick subchannel","file":"src/core/ext/filters/client_channel/client_channel.cc","file_line":3134,"referenced_errors":[{"created":"@1644307702.209907355","description":"failed to connect to all addresses","file":"src/core/lib/transport/error_utils.cc","file_line":163,"grpc_status":14}]}"
我尝试了不同的端口,将本地主机切换到“[::]”或“0.0.0.0”,但没有任何效果。显然我无法在我的虚拟机中创建本地网络。
有没有人遇到过类似的问题并可以帮助我?谢谢!