Skip to content

Crash trying to construct module_arguments when module is created in a method #1976

@maximsch2

Description

@maximsch2

Last line here crashes:

import pytorch_lightning as pl
class Module(pl.LightningModule):
    def forward(self):
        return 0

def test_outside():
    a = Module()
    print(a.module_arguments)

class A:
    def test(self):
        a = Module()
        print(a.module_arguments)

    def test2(self):
        test_outside()
        
        
test_outside() # prints {}
A().test2() # prints {}
A().test() # crashes

For context, this happens when we want to instantiate LightningModules as part of a unit testing functions.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions