hananelroe
(חננאל רועי ארבל)
August 31, 2021, 8:36pm
1
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
hananelroe
(חננאל רועי ארבל)
September 1, 2021, 5:01am
3
But this is not my code, it’s part of the library…
ptrblck
September 1, 2021, 5:10am
4
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
hananelroe
(חננאל רועי ארבל)
September 1, 2021, 5:37am
5
I couldn’t find the typo in your example text… Could you tell me what was the typo?
ptrblck
September 1, 2021, 5:38am
6
forward
→ forwrad
was the typo in my example.
hananelroe
(חננאל רועי ארבל)
September 1, 2021, 6:26am
7
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