Skip to content
This repository has been archived by the owner on Aug 30, 2022. It is now read-only.

Commit

Permalink
PB-402 Add more logs (#281)
Browse files Browse the repository at this point in the history
* PB-402 Add more logs

* PB-402 Rename message_size_in_bytes to message_byte_size

* PB-402 Add helper func

* PB-402 Fix pylint issue
  • Loading branch information
Robert-Steiner authored Feb 12, 2020
1 parent 0dbd211 commit fa14462
Showing 1 changed file with 28 additions and 2 deletions.
30 changes: 28 additions & 2 deletions xain_fl/coordinator/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
from numpy import ndarray
from structlog import get_logger
from xain_proto.fl.coordinator_pb2 import (
_RENDEZVOUSREPLY,
_STATE,
EndTrainingRoundRequest,
EndTrainingRoundResponse,
HeartbeatRequest,
Expand Down Expand Up @@ -178,7 +180,8 @@ def on_message(

logger.debug(
"Received message from participant",
message_type=type(message),
message_type=message.DESCRIPTOR.name,
message_byte_size=message.ByteSize(),
participant_id=participant_id,
)

Expand Down Expand Up @@ -273,6 +276,9 @@ def _handle_rendezvous(
current_participants_count=self.participants.len(),
)

logger.debug(
"Send RendezvousResponse", reply=pb_enum_to_str(_RENDEZVOUSREPLY, reply)
)
return RendezvousResponse(reply=reply)

def _handle_heartbeat(
Expand Down Expand Up @@ -304,8 +310,9 @@ def _handle_heartbeat(
logger.debug(
"Heartbeat response",
participant_id=participant_id,
message=state,
state=pb_enum_to_str(_STATE, state),
round=self.current_round,
current_participants_count=self.participants.len(),
)
return HeartbeatResponse(state=state, round=self.current_round)

Expand All @@ -332,6 +339,11 @@ def _handle_start_training_round(
"StartTrainingRoundRequest outside of a round"
)

logger.debug(
"Send StartTrainingRoundResponse",
epochs=self.epochs,
epoch_base=self.epoch_base,
)
return StartTrainingRoundResponse(
weights=ndarray_to_proto(self.weights),
epochs=self.epochs,
Expand Down Expand Up @@ -402,4 +414,18 @@ def _handle_end_training_round(
# reinitialize the round
self.select_participant_ids_and_init_round()

logger.debug("Send EndTrainingRoundResponse", participant_id=participant_id)
return EndTrainingRoundResponse()


def pb_enum_to_str(pb_enum, member_value: int) -> str:
"""Return the human readable string of a enum member value.
Args:
pb_enum: The proto enum definition.
member_value: The enum member value.
Returns:
The human readable string of a enum member value.
"""
return pb_enum.values_by_number[member_value].name

0 comments on commit fa14462

Please sign in to comment.