Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(framework) Support Fleet API GetFab in grpc-adapter transport #4067

Merged
merged 4 commits into from
Aug 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/py/flwr/server/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,7 @@ def run_superlink() -> None:
fleet_server = _run_fleet_api_grpc_adapter(
address=fleet_address,
state_factory=state_factory,
ffs_factory=ffs_factory,
certificates=certificates,
)
grpc_servers.append(fleet_server)
Expand Down Expand Up @@ -516,12 +517,14 @@ def _run_fleet_api_grpc_rere(
def _run_fleet_api_grpc_adapter(
address: str,
state_factory: StateFactory,
ffs_factory: FfsFactory,
certificates: Optional[Tuple[bytes, bytes, bytes]],
) -> grpc.Server:
"""Run Fleet API (GrpcAdapter)."""
# Create Fleet API gRPC server
fleet_servicer = GrpcAdapterServicer(
state_factory=state_factory,
ffs_factory=ffs_factory,
)
fleet_add_servicer_to_server_fn = add_GrpcAdapterServicer_to_server
fleet_grpc_server = generic_create_grpc_server(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

from flwr.common.logger import log
from flwr.proto import grpcadapter_pb2_grpc # pylint: disable=E0611
from flwr.proto.fab_pb2 import GetFabRequest, GetFabResponse # pylint: disable=E0611
from flwr.proto.fleet_pb2 import ( # pylint: disable=E0611
CreateNodeRequest,
CreateNodeResponse,
Expand All @@ -37,6 +38,7 @@
)
from flwr.proto.grpcadapter_pb2 import MessageContainer # pylint: disable=E0611
from flwr.proto.run_pb2 import GetRunRequest, GetRunResponse # pylint: disable=E0611
from flwr.server.superlink.ffs.ffs_factory import FfsFactory
from flwr.server.superlink.fleet.message_handler import message_handler
from flwr.server.superlink.state import StateFactory

Expand All @@ -60,10 +62,11 @@ def _handle(
class GrpcAdapterServicer(grpcadapter_pb2_grpc.GrpcAdapterServicer):
"""Fleet API via GrpcAdapter servicer."""

def __init__(self, state_factory: StateFactory) -> None:
def __init__(self, state_factory: StateFactory, ffs_factory: FfsFactory) -> None:
self.state_factory = state_factory
self.ffs_factory = ffs_factory

def SendReceive(
def SendReceive( # pylint: disable=too-many-return-statements
self, request: MessageContainer, context: grpc.ServicerContext
) -> MessageContainer:
"""."""
Expand All @@ -80,6 +83,8 @@ def SendReceive(
return _handle(request, PushTaskResRequest, self._push_task_res)
if request.grpc_message_name == GetRunRequest.__qualname__:
return _handle(request, GetRunRequest, self._get_run)
if request.grpc_message_name == GetFabRequest.__qualname__:
return _handle(request, GetFabRequest, self._get_fab)
raise ValueError(f"Invalid grpc_message_name: {request.grpc_message_name}")

def _create_node(self, request: CreateNodeRequest) -> CreateNodeResponse:
Expand Down Expand Up @@ -129,3 +134,11 @@ def _get_run(self, request: GetRunRequest) -> GetRunResponse:
request=request,
state=self.state_factory.state(),
)

def _get_fab(self, request: GetFabRequest) -> GetFabResponse:
"""Get FAB."""
log(INFO, "GrpcAdapter.GetFab")
return message_handler.get_fab(
request=request,
ffs=self.ffs_factory.ffs(),
)