Pytorch-lightning: LightningModule does not subclass from torch.nn.Module which breaks depedency injection of models

Created on 5 May 2020  路  4Comments  路  Source: PyTorchLightning/pytorch-lightning

馃悰 Bug

Pytorch requires very specific ordering of __init__ and self assignment of module submodels:

https://github.com/pytorch/pytorch/blob/master/torch/nn/modules/module.py#L39

Lighting appears to break this expectation in ways that aren't documented and hard to understand, resulting in:

AttributeError: cannot assign module before Module.__init__() call

It's not clear why but based on the documentation, it seems like LightningModule should subclass from torch.nn.Module

bug / fix help wanted

Most helpful comment

image

All 4 comments

LightningModule is subclass with one intermediate class...

```
class GradInformation(nn.Module):
...

class ModelIO(object):
...

class ModelHooks(torch.nn.Module):
...

class LightningModule(ABC, GradInformation, ModelIO, ModelHooks):
...

@jfelectron lightning does subclass from nn.Module... I think you forgot to call super().__init__() before doing anything in your class.

image

This error happened with me once and i had forgotten to call super().__init__()

Was this page helpful?
0 / 5 - 0 ratings

Related issues

justusschock picture justusschock  路  3Comments

edenlightning picture edenlightning  路  3Comments

monney picture monney  路  3Comments

jcreinhold picture jcreinhold  路  3Comments

anthonytec2 picture anthonytec2  路  3Comments