I’m not sure why there are 3 nested loops, since your data seems to have only 2 dimensions.
If you want to use it as a criterion without implementing the backward method, you should stick to PyTorch functions. So you should change math.sqrt to torch.sqrt.
Alternatively, you could get rid of the for loops (which can be pretty slow) and use a faster approach:
x = torch.randn(10, 2)
y = torch.randn(10, 2)
loss = torch.sqrt((x - y)**2).sum()