Make sure the forward definition is in your model class:
class MyModel(nn.Module):
    def __init__(self):
        ....

    def forward(self, x):
        ....

Some times there is a typo or the indentation is wrong.