Got an error, does anybody know why?

the error:

File “C:\Users\hagit\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\torch\nn\modules\module.py”, line 201, in _forward_unimplemented
raise NotImplementedError
NotImplementedError

Hi @hananelroe

Look at the file within this path, it’s highly likely that you’ll find pass statement in forward method.

If so, you need to put some calculations in it. In order to make it work

But this is not my code, it’s part of the library…

The error is raised, if an nn.Module is missing the forward definition either because it was never provided or often because of a typo as seen here:

# missing forward
class MyModel(nn.Module):
    def __init__(self):
        super().__init__()
        self.lin = nn.Linear(1, 1)

x = torch.randn(1, 1)
model = MyModel()    
out = model(x)
> NotImplementedError

# typo
class MyModel(nn.Module):
    def __init__(self):
        super().__init__()
        self.lin = nn.Linear(1, 1)
        
    def forwrad(self, x): # NOTE THE TYPO!!!
        return self.lin(x)

model = MyModel()    
out = model(x)
> NotImplementedError

# works
class MyModel(nn.Module):
    def __init__(self):
        super().__init__()
        self.lin = nn.Linear(1, 1)
        
    def forward(self, x):
        return self.lin(x)
    
model = MyModel()    
out = model(x) # works

I couldn’t find the typo in your example text… Could you tell me what was the typo?

forwardforwrad was the typo in my example.

okay so what happened is that one of my files was accidentally deleted, and the recovered file didnt have the forward method. oopsie.

1 Like