From 256626e2394c06cca610c3d31990fd8e1996a337 Mon Sep 17 00:00:00 2001 From: ThibaultFy Date: Mon, 12 Aug 2024 16:38:49 +0200 Subject: [PATCH] chore: rename use_gpu to disable_gpu in TorchAlgo Signed-off-by: ThibaultFy --- substrafl/algorithms/pytorch/torch_base_algo.py | 2 +- substrafl/algorithms/pytorch/torch_fed_avg_algo.py | 4 ++-- substrafl/algorithms/pytorch/torch_fed_pca_algo.py | 4 ++-- substrafl/algorithms/pytorch/torch_newton_raphson_algo.py | 4 ++-- substrafl/algorithms/pytorch/torch_scaffold_algo.py | 4 ++-- .../algorithms/pytorch/torch_single_organization_algo.py | 4 ++-- tests/algorithms/pytorch/test_base_algo.py | 4 ++-- 7 files changed, 13 insertions(+), 13 deletions(-) diff --git a/substrafl/algorithms/pytorch/torch_base_algo.py b/substrafl/algorithms/pytorch/torch_base_algo.py index 55e57053..5752e1c7 100644 --- a/substrafl/algorithms/pytorch/torch_base_algo.py +++ b/substrafl/algorithms/pytorch/torch_base_algo.py @@ -46,7 +46,7 @@ def __init__( optimizer: Optional[torch.optim.Optimizer] = None, scheduler: Optional[torch.optim.lr_scheduler._LRScheduler] = None, seed: Optional[int] = None, - disable_gpu: bool = True, + disable_gpu: bool = False, *args, **kwargs, ): diff --git a/substrafl/algorithms/pytorch/torch_fed_avg_algo.py b/substrafl/algorithms/pytorch/torch_fed_avg_algo.py index 2ecbc751..bb73a92b 100644 --- a/substrafl/algorithms/pytorch/torch_fed_avg_algo.py +++ b/substrafl/algorithms/pytorch/torch_fed_avg_algo.py @@ -92,7 +92,7 @@ def __init__( scheduler: Optional[torch.optim.lr_scheduler._LRScheduler] = None, with_batch_norm_parameters: bool = False, seed: Optional[int] = None, - disable_gpu: bool = True, + disable_gpu: bool = False, *args, **kwargs, ): @@ -125,7 +125,7 @@ def __init__( with_batch_norm_parameters (bool): Whether to include the batch norm layer parameters in the fed avg strategy. Defaults to False. seed (typing.Optional[int]): Seed set at the algo initialization on each organization. Defaults to None. - disable_gpu (bool): Whether to use the GPUs if they are available. Defaults to True. + disable_gpu (bool): Force to disable GPUs usage. Defaults to False. """ super().__init__( *args, diff --git a/substrafl/algorithms/pytorch/torch_fed_pca_algo.py b/substrafl/algorithms/pytorch/torch_fed_pca_algo.py index 8e261ce0..34ad1001 100644 --- a/substrafl/algorithms/pytorch/torch_fed_pca_algo.py +++ b/substrafl/algorithms/pytorch/torch_fed_pca_algo.py @@ -87,7 +87,7 @@ def __init__( out_features: int, batch_size: Optional[int] = None, seed: int = 1, - disable_gpu: bool = True, + disable_gpu: bool = False, *args, **kwargs, ): @@ -101,7 +101,7 @@ def __init__( out_features (int): dimension to keep after PCA batch_size (Optional[int]): mini-batch size seed (int): random generator seed. The seed is mandatory. Default to 1. - disable_gpu (bool): whether to use GPU or not. Default to True. + disable_gpu (bool): force to disable GPUs usage. Defaults to False. """ self.in_features = in_features self.out_features = out_features diff --git a/substrafl/algorithms/pytorch/torch_newton_raphson_algo.py b/substrafl/algorithms/pytorch/torch_newton_raphson_algo.py index 852beba1..07e537f9 100644 --- a/substrafl/algorithms/pytorch/torch_newton_raphson_algo.py +++ b/substrafl/algorithms/pytorch/torch_newton_raphson_algo.py @@ -48,7 +48,7 @@ def __init__( l2_coeff: float = 0, with_batch_norm_parameters: bool = False, seed: Optional[int] = None, - disable_gpu: bool = True, + disable_gpu: bool = False, *args, **kwargs, ): @@ -80,7 +80,7 @@ def __init__( with_batch_norm_parameters (bool): Whether to include the batch norm layer parameters in the Newton-Raphson strategy. Defaults to False. seed (typing.Optional[int]): Seed set at the algo initialization on each organization. Defaults to None. - disable_gpu (bool): Whether to use the GPUs if they are available. Defaults to True. + disable_gpu (bool): Force to disable GPUs usage. Defaults to False. """ assert "optimizer" not in kwargs, "Newton Raphson strategy does not uses optimizers" diff --git a/substrafl/algorithms/pytorch/torch_scaffold_algo.py b/substrafl/algorithms/pytorch/torch_scaffold_algo.py index 8ce14608..f2787f23 100644 --- a/substrafl/algorithms/pytorch/torch_scaffold_algo.py +++ b/substrafl/algorithms/pytorch/torch_scaffold_algo.py @@ -118,7 +118,7 @@ def __init__( with_batch_norm_parameters: bool = False, c_update_rule: CUpdateRule = CUpdateRule.FAST, seed: Optional[int] = None, - disable_gpu: bool = True, + disable_gpu: bool = False, *args, **kwargs, ): @@ -153,7 +153,7 @@ def __init__( client control variate. Defaults to CUpdateRule.FAST. seed (typing.Optional[int]): Seed set at the algo initialization on each organization. Defaults to None. - disable_gpu (bool): Whether to use the GPUs if they are available. Defaults to True. + disable_gpu (bool): Force to disable GPUs usage. Defaults to False. Raises: :ref:`~substrafl.exceptions.NumUpdatesValueError`: If `num_updates` is inferior or equal to zero. """ diff --git a/substrafl/algorithms/pytorch/torch_single_organization_algo.py b/substrafl/algorithms/pytorch/torch_single_organization_algo.py index f0e459ad..00eddadc 100644 --- a/substrafl/algorithms/pytorch/torch_single_organization_algo.py +++ b/substrafl/algorithms/pytorch/torch_single_organization_algo.py @@ -90,7 +90,7 @@ def __init__( dataset: torch.utils.data.Dataset, scheduler: Optional[torch.optim.lr_scheduler._LRScheduler] = None, seed: Optional[int] = None, - disable_gpu: bool = True, + disable_gpu: bool = False, *args, **kwargs, ): @@ -121,7 +121,7 @@ def __init__( scheduler (torch.optim.lr_scheduler._LRScheduler, Optional): A torch scheduler that will be called at every batch. If None, no scheduler will be used. Defaults to None. seed (typing.Optional[int]): Seed set at the algo initialization on each organization. Defaults to None. - disable_gpu (bool): Whether to use the GPUs if they are available. Defaults to True. + disable_gpu (bool): Force to disable GPUs usage. Defaults to False. """ super().__init__( *args, diff --git a/tests/algorithms/pytorch/test_base_algo.py b/tests/algorithms/pytorch/test_base_algo.py index 39c4813b..dd858288 100644 --- a/tests/algorithms/pytorch/test_base_algo.py +++ b/tests/algorithms/pytorch/test_base_algo.py @@ -201,9 +201,9 @@ def __init__(self): disable_gpu=disable_gpu, ) if disable_gpu: - assert self._device == torch.device("cuda") - else: assert self._device == torch.device("cpu") + else: + assert self._device == torch.device("cuda") @property def strategies(self):