Hi, I’m trying to write a custom loss, and I saw a few ways to do it:


Make a new class inheriting from Function, with forward and backward functions,as in
this git:
https://github.com/mattmacy/torchbiomed/blob/master/torchbiomed/loss.py#L13 25
Which, By the way, I have no idea what is the “grad_output” in the backward function means?
(when I’m doing loss.backward() with a “normal” loss function I don’t give any argument)
I’ve read this:https://pytorch.org/docs/stable/notes/extending.html 9
But things are still messy…


Just a small and nice function as in this git:
https://github.com/perone/medicaltorch/blob/master/medicaltorch/losses.py#L4 41
And then using it in:
https://github.com/perone/medicaltorch/blob/master/examples/gmchallenge_unet.py#L111 21
and the backward is in line: 115.


Now my (biggest) questions are, why should I do the first option, when the 2nd is much easier?
How come they can do backward() to just a function?
Can someone please help to understand this issue, I feel like everything is just a big mess…
Thanks!