From 95c179505f97496c921123414d06afe96c4d8559 Mon Sep 17 00:00:00 2001 From: ThibaultFy Date: Wed, 19 Jun 2024 15:46:06 +0200 Subject: [PATCH 1/4] chore: add cancel cp option for camelyon benchmark Signed-off-by: ThibaultFy --- benchmark/camelyon/benchmarks.py | 1 + benchmark/camelyon/common/utils.py | 2 ++ benchmark/camelyon/workflows.py | 5 +++++ 3 files changed, 8 insertions(+) diff --git a/benchmark/camelyon/benchmarks.py b/benchmark/camelyon/benchmarks.py index 888419f0..f6b6aa61 100644 --- a/benchmark/camelyon/benchmarks.py +++ b/benchmark/camelyon/benchmarks.py @@ -63,6 +63,7 @@ def fed_avg(params: dict, train_folder: Path, test_folder: Path): model=model, mode=exp_params["mode"], cp_name=exp_params["cp_name"], + cancel_cp=exp_params["cancel_cp"], torch_gpu=exp_params["torch_gpu"], ) diff --git a/benchmark/camelyon/common/utils.py b/benchmark/camelyon/common/utils.py index 5e0a6607..19b40ecb 100644 --- a/benchmark/camelyon/common/utils.py +++ b/benchmark/camelyon/common/utils.py @@ -75,6 +75,7 @@ def parse_params() -> dict: default=Path(__file__).resolve().parents[1] / "data", help="Path to the data", ) + parser.add_argument("--cancel-cp", action="store_false", help="Cancel the CP after registration for remote mode") parser.add_argument("--torch-gpu", action="store_true", help="Use PyTorch with GPU/CUDA support") parser.add_argument( "--cp-name", @@ -95,6 +96,7 @@ def parse_params() -> dict: params["nb_train_data_samples"] = args.nb_train_data_samples params["nb_test_data_samples"] = args.nb_test_data_samples params["data_path"] = args.data_path + params["cancel_cp"] = args.cancel_cp params["torch_gpu"] = args.torch_gpu params["cp_name"] = args.cp_name diff --git a/benchmark/camelyon/workflows.py b/benchmark/camelyon/workflows.py index 6dd5630b..db01d0f2 100644 --- a/benchmark/camelyon/workflows.py +++ b/benchmark/camelyon/workflows.py @@ -42,6 +42,7 @@ def substrafl_fed_avg( credentials_path: Path, asset_keys_path: Path, cp_name: Optional[str], + cancel_cp: bool = False, torch_gpu: bool = False, ) -> benchmark_metrics.BenchmarkResults: """Execute Weldon algorithm for a fed avg strategy with substrafl API. @@ -65,6 +66,7 @@ def substrafl_fed_avg( asset_keys_path (Path): Remote only: path to asset key file. If un existent, it will be created. Otherwise, all present keys in this fill will be reused per Substra in remote mode. cp_name ben): (Optional[str]): Compute Plan name to display + cancel_cp (bool): if set to True, the CP will be canceled as soon as it's registered. Only work for remote mode. torch_gpu (bool): Use GPU default index for pytorch Returns: dict: Results of the experiment. @@ -140,6 +142,9 @@ def accuracy(data_from_opener, predictions): name=cp_name, ) + if cancel_cp: + clients[0].cancel_compute_plan(key=compute_plan.key) + clients[0].wait_compute_plan(key=compute_plan.key, raise_on_failure=True) performances = clients[1].get_performances(key=compute_plan.key) From 50405436b4a945369cd9b39eccb7ef5c9f1a94fb Mon Sep 17 00:00:00 2001 From: ThibaultFy Date: Wed, 19 Jun 2024 15:46:44 +0200 Subject: [PATCH 2/4] chore: add cancel cp option for camelyon benchmark Signed-off-by: ThibaultFy --- benchmark/camelyon/common/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/benchmark/camelyon/common/utils.py b/benchmark/camelyon/common/utils.py index 19b40ecb..85bd88a5 100644 --- a/benchmark/camelyon/common/utils.py +++ b/benchmark/camelyon/common/utils.py @@ -75,7 +75,7 @@ def parse_params() -> dict: default=Path(__file__).resolve().parents[1] / "data", help="Path to the data", ) - parser.add_argument("--cancel-cp", action="store_false", help="Cancel the CP after registration for remote mode") + parser.add_argument("--cancel-cp", action="store_false", help="Remote only: cancel the CP after registration") parser.add_argument("--torch-gpu", action="store_true", help="Use PyTorch with GPU/CUDA support") parser.add_argument( "--cp-name", From a3f4e111283f042c3e3afe96ae4d84aae250a1de Mon Sep 17 00:00:00 2001 From: ThibaultFy Date: Wed, 19 Jun 2024 16:23:23 +0200 Subject: [PATCH 3/4] chore: add cancel cp option for camelyon benchmark Signed-off-by: ThibaultFy --- benchmark/camelyon/common/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/benchmark/camelyon/common/utils.py b/benchmark/camelyon/common/utils.py index 85bd88a5..fd836994 100644 --- a/benchmark/camelyon/common/utils.py +++ b/benchmark/camelyon/common/utils.py @@ -75,7 +75,7 @@ def parse_params() -> dict: default=Path(__file__).resolve().parents[1] / "data", help="Path to the data", ) - parser.add_argument("--cancel-cp", action="store_false", help="Remote only: cancel the CP after registration") + parser.add_argument("--cancel-cp", type=bool, default=False, help="Remote only: cancel the CP after registration") parser.add_argument("--torch-gpu", action="store_true", help="Use PyTorch with GPU/CUDA support") parser.add_argument( "--cp-name", From 3ffaa79e77d41b0bae560e70a66e10b905c49833 Mon Sep 17 00:00:00 2001 From: ThibaultFy Date: Wed, 19 Jun 2024 17:03:46 +0200 Subject: [PATCH 4/4] chore: add cancel cp option for camelyon benchmark extreme Signed-off-by: ThibaultFy --- benchmark/camelyon/workflows.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/benchmark/camelyon/workflows.py b/benchmark/camelyon/workflows.py index db01d0f2..329e3d33 100644 --- a/benchmark/camelyon/workflows.py +++ b/benchmark/camelyon/workflows.py @@ -4,6 +4,7 @@ from typing import Optional import numpy as np +import substra import torch import weldon_fedavg from common import benchmark_metrics @@ -142,7 +143,7 @@ def accuracy(data_from_opener, predictions): name=cp_name, ) - if cancel_cp: + if cancel_cp and clients[0].backend_mode == substra.BackendType.REMOTE: clients[0].cancel_compute_plan(key=compute_plan.key) clients[0].wait_compute_plan(key=compute_plan.key, raise_on_failure=True)