Sorry to ask a silly question, but why is it necessary to have this layer in the first place. Could you not negate the loss function directly? Then the gradients would be flipped automatically, with no extra lines of code?