Does pytorch register modules that are assigned to object properties?

Viewed 39

Say I have a module like:

class MyModule(nn.Module):
    def __init__(self):
        super().__init__()
        self.cnn = CNN(params)

And then I do:

module = MyModule()
module.cnn = CNN(some_other_params)

Is the replacement registered? Will there be any nasty side effects down the line?

1 Answers

Yes. This is the standard way to reassign attributes. Whether there are nasty side effects depends on whether your replacement is specified compatibly.

Related