I am trying to use getattr in the forward method an nn.Module class. A minimalistic indicative example of what I’m trying to do is shown below:
class Net(nn.Module):
    def __init__(self, ):
        super().__init__()
        self.layer = nn.Linear(8,  16)
    def forward(self, x):
        return getattr(self, 'layer')(x)

I get a NotImplementedError when I use forward:
File "/usr/lib/python3.7/site-packages/torch/nn/modules/module.py", line 85, in forward
    raise NotImplementedError
NotImplementedError

Any ideas on how to solve it? Or even an alternative way to “create” the name of an attribute of Net inside forward? Thank you!