From f1e1292907fa535314291438b68500630f34b83d Mon Sep 17 00:00:00 2001 From: David Emerson <43939939+emersodb@users.noreply.github.com> Date: Mon, 18 Nov 2024 10:58:57 -0500 Subject: [PATCH 1/2] Fixing infinite test issue --- fl4health/server/base_server.py | 4 +++- tests/server/test_base_server.py | 11 +++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/fl4health/server/base_server.py b/fl4health/server/base_server.py index 2773e55eb..56f9c7472 100644 --- a/fl4health/server/base_server.py +++ b/fl4health/server/base_server.py @@ -349,7 +349,9 @@ def evaluate_round( "eval_round_end": str(end_time), } dummy_params = Parameters([], "None") - config = self.strategy.configure_fit(server_round, dummy_params, self._client_manager)[0][1].config + config = self.strategy.configure_evaluate(server_round, dummy_params, self._client_manager)[0][ + 1 + ].config if config.get("local_epochs", None) is not None: report_data["fit_epoch"] = server_round * config["local_epochs"] elif config.get("local_steps", None) is not None: diff --git a/tests/server/test_base_server.py b/tests/server/test_base_server.py index 4ca55722b..902cf8c6e 100644 --- a/tests/server/test_base_server.py +++ b/tests/server/test_base_server.py @@ -3,6 +3,7 @@ from typing import List, Tuple, Union from unittest.mock import Mock, patch +import freezegun import pytest import torch import torch.nn as nn @@ -10,6 +11,7 @@ from flwr.common.parameter import ndarrays_to_parameters from flwr.server.client_proxy import ClientProxy from flwr.server.history import History +from flwr.server.strategy import FedAvg from freezegun import freeze_time from fl4health.checkpointing.checkpointer import BestLossTorchCheckpointer @@ -25,6 +27,8 @@ from tests.test_utils.custom_client_proxy import CustomClientProxy from tests.test_utils.models_for_test import LinearTransform +freezegun.config.configure(extend_ignore_list=["transformers"]) + model = LinearTransform() @@ -247,9 +251,12 @@ def test_metrics_reporter_evaluate_round(mock_evaluate_round: Mock) -> None: test_metrics_aggregated, (None, None), ) - + client_manager = SimpleClientManager() + client_manager.register(CustomClientProxy("test_id", 1)) reporter = JsonReporter() - fl_server = FlServer(SimpleClientManager(), reporters=[reporter]) + fl_server = FlServer( + client_manager, reporters=[reporter], strategy=FedAvg(min_evaluate_clients=1, min_available_clients=1) + ) fl_server.evaluate_round(test_round, None) metrics_to_assert = { From dfc9a6a8a5f2658be265f9efe7a9080c82d43c35 Mon Sep 17 00:00:00 2001 From: David Emerson <43939939+emersodb@users.noreply.github.com> Date: Mon, 18 Nov 2024 11:04:41 -0500 Subject: [PATCH 2/2] Dropping the freezegun hack fix as its no longer necessary --- tests/server/test_base_server.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/tests/server/test_base_server.py b/tests/server/test_base_server.py index 902cf8c6e..c2c8c5894 100644 --- a/tests/server/test_base_server.py +++ b/tests/server/test_base_server.py @@ -3,7 +3,6 @@ from typing import List, Tuple, Union from unittest.mock import Mock, patch -import freezegun import pytest import torch import torch.nn as nn @@ -27,8 +26,6 @@ from tests.test_utils.custom_client_proxy import CustomClientProxy from tests.test_utils.models_for_test import LinearTransform -freezegun.config.configure(extend_ignore_list=["transformers"]) - model = LinearTransform()