You are currently trying to call the nn.ModuleDict, which won’t work, as you would have to address one of the layers:
class Net(nn.Module): 
     def __init__(self, ): 
         super().__init__()
         setattr(self, 'layer', nn.ModuleDict({'a': nn.Linear(8, 16), 'b': nn.Linear(16, 4)})) 
     def forward(self, x): 
         x = getattr(getattr(self, 'layer'), 'a')(x)
         x = getattr(getattr(self, 'layer'), 'b')(x)
         return x

What is your use case, if I may ask?