Hi Tony!



 tonyr:

they go through a NN and result in a single scalar. I want to maximise that scalar


Just use pytorch to minimize the negative of your scalar.
That is:
my_single_scalar = model (input)
my_negative_scalar = -my_single_scalar
optim.zero_grads()
my_negative_scalar.backwards()
optim.step()

(Pytorch optimizers minimize their objective functions.  To maximize,
you just flip the sign.)


Is there a torch.nn.*Loss function for this?
…
Maybe I shouldn’t be using a torch.nn.*Loss() function at all?


Yes, no need to use a torch.nn.ImAtALoss() function.  There is
nothing special about them.  They are just (autograd-supporting)
implementations of loss functions commonly used for training.
As long as you use pytorch tensor operations that support autograd,
you can use your own computation for the loss, (including something
as simple as -model (input)).
Best.
K. Frank