I don’t know if it is even worth to ask this question in this forum, but I was wondering if it is a good, neutral or bad practice to specify loss as well as optimizer inside the model class, for example:
class Net(nn.Module):
    def __init__(self, in_features, n_classes, lr):
        self.fc_1 = nn.Linear(in_features, 256)
        self.fc_2 = nn.Linear(256, n_classes)

        self.criterion = nn.CrossEntropyLoss()
        self.optimizer = nn.Adam(self.parameters(), lr=0.01)

    def forward(self, x)
        return self.fc_2(F.relu(self.fc_1(x)))

As of right now I’ve seen only one tutorial that uses this kind of approach. At first, for me, it looked kinda sketchy, but now I think that this is way more clean than creating criterion and optimizer outside of class.
But I have a question, does this way have any implications or unnecessary behavior which I don’t understand or that I haven’t encountered that could harm my model’s performance or something like that?