Jacobian matrix for the ouput

hello every one,
Is there a way in PyTorch to get the derivation from the net.
I want to find the distance between two points, say x and y as follows:

The output of the encoder is x and y:

output_feature ,class=model(input)

x and y are the output_feature [2,2048]

the input is [2,8,3,128,128]

The distance to be calculated : (x-y)(transpose) J(transpose) J (x-y).

with J being the Jacobian matrix wrt the encoder.

how can I calculate J in PyTorch?