From 9824b1705699c2e5d1c36f1bc0fcb51e686e5802 Mon Sep 17 00:00:00 2001 From: awaelchli Date: Thu, 4 Aug 2022 14:07:07 +0200 Subject: [PATCH 1/2] Remove unused auto_collect_arguments class method --- src/pytorch_lightning/core/module.py | 28 ---------------------- tests/tests_pytorch/models/test_hparams.py | 2 +- 2 files changed, 1 insertion(+), 29 deletions(-) diff --git a/src/pytorch_lightning/core/module.py b/src/pytorch_lightning/core/module.py index b8cc1d91cde18..d10c7ff273b81 100644 --- a/src/pytorch_lightning/core/module.py +++ b/src/pytorch_lightning/core/module.py @@ -1782,34 +1782,6 @@ def _verify_is_manual_optimization(self, fn_name): " set model property `automatic_optimization` as False" ) - @classmethod - def _auto_collect_arguments(cls, frame=None) -> Tuple[Dict, Dict]: - """Collect all module arguments in the current constructor and all child constructors. The child - constructors are all the ``__init__`` methods that reach the current class through (chained) - ``super().__init__()`` calls. - - Args: - frame: instance frame - - Returns: - self_arguments: arguments dictionary of the first instance - parents_arguments: arguments dictionary of the parent's instances - """ - if not frame: - frame = inspect.currentframe() - - frame_args = collect_init_args(frame.f_back, []) - self_arguments = frame_args[-1] - - # set hyper_parameters in child - self_arguments = self_arguments - parents_arguments = {} - - # add all arguments from parents - for args in frame_args[:-1]: - parents_arguments.update(args) - return self_arguments, parents_arguments - @torch.no_grad() def to_onnx(self, file_path: Union[str, Path], input_sample: Optional[Any] = None, **kwargs): """Saves the model in ONNX format. diff --git a/tests/tests_pytorch/models/test_hparams.py b/tests/tests_pytorch/models/test_hparams.py index 20bdfda5dc224..c130381c7832d 100644 --- a/tests/tests_pytorch/models/test_hparams.py +++ b/tests/tests_pytorch/models/test_hparams.py @@ -410,7 +410,7 @@ def __init__(self, arg1, arg2, *args, **kwargs): class LocalVariableModelSuperFirst(BoringModel): - """This model has the _auto_collect_arguments() call at the end.""" + """This model has the save_hyperparameters() call at the end.""" def __init__(self, arg1, arg2, *args, **kwargs): super().__init__(*args, **kwargs) From 6d018fa5321ac9b2e067e554258aa0aceadf7277 Mon Sep 17 00:00:00 2001 From: awaelchli Date: Thu, 4 Aug 2022 14:11:10 +0200 Subject: [PATCH 2/2] remove unused imports --- src/pytorch_lightning/core/module.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/pytorch_lightning/core/module.py b/src/pytorch_lightning/core/module.py index d10c7ff273b81..f58503edd88cb 100644 --- a/src/pytorch_lightning/core/module.py +++ b/src/pytorch_lightning/core/module.py @@ -14,7 +14,6 @@ """The LightningModule - an nn.Module with many additional features.""" import collections.abc -import inspect import logging import numbers import os @@ -46,7 +45,6 @@ from pytorch_lightning.utilities.distributed import distributed_available, sync_ddp from pytorch_lightning.utilities.exceptions import MisconfigurationException from pytorch_lightning.utilities.imports import _TORCH_GREATER_EQUAL_1_11, _TORCH_GREATER_EQUAL_1_13 -from pytorch_lightning.utilities.parsing import collect_init_args from pytorch_lightning.utilities.rank_zero import rank_zero_debug, rank_zero_deprecation, rank_zero_warn from pytorch_lightning.utilities.signature_utils import is_param_in_hook_signature from pytorch_lightning.utilities.types import _METRIC_COLLECTION, EPOCH_OUTPUT, LRSchedulerTypeUnion, STEP_OUTPUT