|
37 | 37 | from fl4health.utils.typing import LogLevel, TorchFeatureType, TorchInputType, TorchPredType, TorchTargetType |
38 | 38 |
|
39 | 39 |
|
| 40 | +EXPECTED_OUTPUT_TUPLE_SIZE = 2 |
| 41 | + |
| 42 | + |
40 | 43 | class BasicClient(NumPyClient): |
41 | 44 | def __init__( |
42 | 45 | self, |
@@ -140,8 +143,10 @@ def _maybe_checkpoint(self, loss: float, metrics: dict[str, Scalar], checkpoint_ |
140 | 143 | If checkpointer exists, maybe checkpoint model based on the provided metric values. |
141 | 144 |
|
142 | 145 | Args: |
143 | | - loss (float): validation loss to potentially be used for checkpointing |
144 | | - metrics (dict[str, float]): validation metrics to potentially be used for checkpointing |
| 146 | + loss (float): Validation loss to potentially be used for checkpointing. |
| 147 | + metrics (dict[str, Scalar]): Validation metrics to potentially be used for checkpointing |
| 148 | + checkpoint_mode (CheckpointMode): Whether we're doing checkpointing pre- or post-aggregation on the server |
| 149 | + side. |
145 | 150 | """ |
146 | 151 | self.checkpoint_and_state_module.maybe_checkpoint(self.model, loss, metrics, checkpoint_mode) |
147 | 152 |
|
@@ -439,10 +444,10 @@ def _log_header_str( |
439 | 444 | the round if training by steps. |
440 | 445 |
|
441 | 446 | Args: |
442 | | - current_round (int | None, optional): The current FL round. (Ie current |
443 | | - server round). Defaults to None. |
444 | | - current_epoch (int | None, optional): The current epoch of local |
445 | | - training. Defaults to None. |
| 447 | + current_round (int | None, optional): The current FL round. (Ie current server round). Defaults to None. |
| 448 | + current_epoch (int | None, optional): The current epoch of local training. Defaults to None. |
| 449 | + logging_mode (LoggingMode, optional): The logging mode to be used in logging. This mainly changes the |
| 450 | + way in which logging is decorated. Defaults to LoggingMode.TRAIN. |
446 | 451 | """ |
447 | 452 | log_str = f"Current FL Round: {int(current_round)} " if current_round is not None else "" |
448 | 453 | log_str += f"Current Epoch: {int(current_epoch)} " if current_epoch is not None else "" |
@@ -1002,7 +1007,7 @@ def predict(self, input: TorchInputType) -> tuple[TorchPredType, TorchFeatureTyp |
1002 | 1007 | if isinstance(output, torch.Tensor): |
1003 | 1008 | return {"prediction": output}, {} |
1004 | 1009 | if isinstance(output, tuple): |
1005 | | - if len(output) != 2: |
| 1010 | + if len(output) != EXPECTED_OUTPUT_TUPLE_SIZE: |
1006 | 1011 | raise ValueError(f"Output tuple should have length 2 but has length {len(output)}") |
1007 | 1012 | preds, features = output |
1008 | 1013 | return preds, features |
|
0 commit comments