How to ensure/know my customer loss exist differentiable?

Hello, I am designing my loss based on edge information for segmentation. The network (i.e Unet) provides a softmax probability P. The loss defined as

loss = \sum_i^N ( G_i - Pedge_i)^2


where Pedge_i is the binary edge of the softmax probability. It can obtain by using threshold P>0.5 or max(P,axis=1) for multiple class. and N is a number of pixel in ground-truth edge G.

Is possible to perform the loss in pytorch without writing backward function. I mean does it exist auto differentiable? Thanks