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

Looking at the pytorch source code for Module, we see in the docstring an example of deriving from Module includes:

 class Model(nn.Module):
        def __init__(self):
            super(Model, self).__init__()
            self.conv1 = nn.Conv2d(1, 20, 5)
            self.conv2 = nn.Conv2d(20, 20, 5)

So you probably want to call Module‘s init the same way in your derived class:

super(QuestionClassifier, self).__init__()

Leave a Comment