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) Add Flower package version/name and gRPC message/module to GrpcAdapter metadata #4275

Merged
merged 6 commits into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
17 changes: 13 additions & 4 deletions src/py/flwr/client/grpc_rere_client/grpc_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,13 @@

from flwr.common import log
from flwr.common.constant import (
GRPC_ADAPTER_METADATA_FLOWER_VERSION_KEY,
GRPC_ADAPTER_METADATA_MESSAGE_MODULE_KEY,
GRPC_ADAPTER_METADATA_MESSAGE_QUALNAME_KEY,
GRPC_ADAPTER_METADATA_PACKAGE_NAME_KEY,
GRPC_ADAPTER_METADATA_PACKAGE_VERSION_KEY,
GRPC_ADAPTER_METADATA_SHOULD_EXIT_KEY,
)
from flwr.common.version import package_version
from flwr.common.version import package_name, package_version
from flwr.proto.fab_pb2 import GetFabRequest, GetFabResponse # pylint: disable=E0611
from flwr.proto.fleet_pb2 import ( # pylint: disable=E0611
CreateNodeRequest,
Expand Down Expand Up @@ -62,9 +65,15 @@ def _send_and_receive(
self, request: GrpcMessage, response_type: type[T], **kwargs: Any
) -> T:
# Serialize request
req_cls = request.__class__
container_req = MessageContainer(
metadata={GRPC_ADAPTER_METADATA_FLOWER_VERSION_KEY: package_version},
grpc_message_name=request.__class__.__qualname__,
metadata={
GRPC_ADAPTER_METADATA_PACKAGE_NAME_KEY: package_name,
GRPC_ADAPTER_METADATA_PACKAGE_VERSION_KEY: package_version,
GRPC_ADAPTER_METADATA_MESSAGE_MODULE_KEY: req_cls.__module__,
GRPC_ADAPTER_METADATA_MESSAGE_QUALNAME_KEY: req_cls.__qualname__,
},
grpc_message_name=req_cls.__qualname__,
grpc_message_content=request.SerializeToString(),
)

Expand Down
8 changes: 5 additions & 3 deletions src/py/flwr/common/constant.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@
# IDs
RUN_ID_NUM_BYTES = 8
NODE_ID_NUM_BYTES = 8
GRPC_ADAPTER_METADATA_FLOWER_VERSION_KEY = "flower-version"
GRPC_ADAPTER_METADATA_SHOULD_EXIT_KEY = "should-exit"

# Constants for FAB
APP_DIR = "apps"
Expand All @@ -72,8 +70,12 @@
PARTITION_ID_KEY = "partition-id"
NUM_PARTITIONS_KEY = "num-partitions"

GRPC_ADAPTER_METADATA_FLOWER_VERSION_KEY = "flower-version"
# Constants for keys in `metadata` of `MessageContainer` in `grpc-adapter`
GRPC_ADAPTER_METADATA_PACKAGE_NAME_KEY = "flower-package-name"
GRPC_ADAPTER_METADATA_PACKAGE_VERSION_KEY = "flower-package-version"
GRPC_ADAPTER_METADATA_SHOULD_EXIT_KEY = "should-exit"
GRPC_ADAPTER_METADATA_MESSAGE_MODULE_KEY = "grpc-message-module"
GRPC_ADAPTER_METADATA_MESSAGE_QUALNAME_KEY = "grpc-message-qualname"


class MessageType:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,14 @@
import grpc
from google.protobuf.message import Message as GrpcMessage

from flwr.common.constant import (
GRPC_ADAPTER_METADATA_MESSAGE_MODULE_KEY,
GRPC_ADAPTER_METADATA_MESSAGE_QUALNAME_KEY,
GRPC_ADAPTER_METADATA_PACKAGE_NAME_KEY,
GRPC_ADAPTER_METADATA_PACKAGE_VERSION_KEY,
)
from flwr.common.logger import log
from flwr.common.version import package_name, package_version
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
Expand Down Expand Up @@ -52,9 +59,15 @@ def _handle(
) -> MessageContainer:
req = request_type.FromString(msg_container.grpc_message_content)
res = handler(req)
res_cls = res.__class__
return MessageContainer(
metadata={},
grpc_message_name=res.__class__.__qualname__,
metadata={
GRPC_ADAPTER_METADATA_PACKAGE_NAME_KEY: package_name,
GRPC_ADAPTER_METADATA_PACKAGE_VERSION_KEY: package_version,
GRPC_ADAPTER_METADATA_MESSAGE_MODULE_KEY: res_cls.__module__,
GRPC_ADAPTER_METADATA_MESSAGE_QUALNAME_KEY: res_cls.__qualname__,
},
grpc_message_name=res_cls.__qualname__,
grpc_message_content=res.SerializeToString(),
)

Expand Down
Loading