diff --git a/src/pytorch_lightning/utilities/parsing.py b/src/pytorch_lightning/utilities/parsing.py index 92675bc9919d0..a63c56bb74725 100644 --- a/src/pytorch_lightning/utilities/parsing.py +++ b/src/pytorch_lightning/utilities/parsing.py @@ -182,7 +182,7 @@ def collect_init_args( if "__class__" in local_vars: local_args = get_init_args(frame) # recursive update - path_args.append(local_args) + path_args.insert(0, local_args) return collect_init_args(frame.f_back, path_args, inside=True) if not inside: return collect_init_args(frame.f_back, path_args, inside) diff --git a/tests/tests_pytorch/utilities/test_parsing.py b/tests/tests_pytorch/utilities/test_parsing.py index 2fbed03de84c2..13c98ade6f31b 100644 --- a/tests/tests_pytorch/utilities/test_parsing.py +++ b/tests/tests_pytorch/utilities/test_parsing.py @@ -265,8 +265,8 @@ def __init__(self, anyarg, childarg, anykw=42, childkw=42, **kwargs): super().__init__(anyarg, anykw=anykw, **kwargs) my_class = AutomaticArgsChild("test1", "test2", anykw=32, childkw=22, otherkw=123) - assert my_class.result[0] == {"anyarg": "test1", "anykw": 32, "otherkw": 123} - assert my_class.result[1] == {"anyarg": "test1", "childarg": "test2", "anykw": 32, "childkw": 22, "otherkw": 123} + assert my_class.result[0] == {"anyarg": "test1", "childarg": "test2", "anykw": 32, "childkw": 22, "otherkw": 123} + assert my_class.result[1] == {"anyarg": "test1", "anykw": 32, "otherkw": 123} def test_attribute_dict(tmpdir):