Hi Night!



 NightRain:

Is there any difference …


Roughly speaking, there is no difference.



nn.MSELoss(input, target)?



Note, as written, this won’t work.  This calls the MSELoss constructor
with invalid arguments.  You need:
loss_value = torch.nn.MSELoss() (input, target)
# or
loss_function = torch.nn.MSELoss()
loss_value = loss_function (input, target)

That is, you have to construct an MSELoss object first, and then call
(apply) it.


Same question applies for l1_loss and any other stateless loss function.


MSELoss objects (and similar loss-function objects) are “stateless” in
the sense that they don’t remember anything from one application
(loss_function (input, target)) to the next.  But they do have
state, in that they are constructed with certain “control” parameters
set (for example, the reduction property of MSELoss and other
loss-function objects) that are stored internally, and used repeatedly
from one application to the next.  (These properties can be changed
after construction, but I don’t think that that’s common practice.)
Best.
K. Frank