So the problem is that because you create this linear during the forward, it will have new random weights at each forward and it’s weights are not passed to the optimizer when you do model.parameters().
Maybe that is what you want.
If you don’t want that and want the Linear to be learnt, you need to push its creation to the __init__ function and have a self.fc = nn.Linear((128*(n_features_x + n_features_y)), 4) and change your forward to do self.fc(z).