Yeah. This is a relu example, but you can extend this to your own problem. The returned value in backward are the derivatives of the input of the forward, which is the output of the second to the last layer in your case. Your loss is implemented in the forward, or constructed by using the output of the forward. You just need to write your last layer’s derivative manually in the backward.