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

williamFalcon picture williamFalcon  ·  3Comments

baeseongsu picture baeseongsu  ·  3Comments

edenlightning picture edenlightning  ·  3Comments

williamFalcon picture williamFalcon  ·  3Comments

as754770178 picture as754770178  ·  3Comments