Hi
In my case, I have two separate networks, each has its own optimizer.
I noticed the optimizer is decoupled from the model.nn, and was wondering why that is.
My use case is going to be

predict
calculate loss
backward
optimizer [zero grad and] step

I was wondering why not hide the optimizer from the network’s user, and just give an API that looks like

predict
learn(prediction, expected value)

The network should know how to calculate its own loss, and how to learn using its own internal state (optimizer and so on).
Is my second approach bad practice?
If not, why is it not common practice?
The way I viewed it was:
A network defines the following API:

init(lambda_fn_for_loss, learning rate, optimizer)
forward() (outputs expected value predicted by net)
[private, function] loss(expected) (outputs loss tensor, calculated by the lambda on the expected value)
learn(expected) (uses the lambda given on init to calculate loss(expected). then loss.backward, optimizer.step())