Hi. Thank you for answering!
I changed it to something like this:
model = SomeModel()

x = torch.rand(1,3,32,32)

scores = model(x)

loss_func = distance_loss(10)

loss = loss_func.forward(scores)

loss.backward()

but x.grad now prints an empty list