Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 0 additions & 30 deletions src/pytorch_lightning/core/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
"""The LightningModule - an nn.Module with many additional features."""

import collections.abc
import inspect
import logging
import numbers
import os
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -1782,34 +1780,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.
Expand Down
2 changes: 1 addition & 1 deletion tests/tests_pytorch/models/test_hparams.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down