It’s easy to get the sum of loss with a model
# make gradients ready
loss.backward()
grad_sum = sum(param.grad.sum() for param in model.parameters() if param.grad is not None)

What do you mean

so I don’t have “inputs” or “model”

Where is your learnable parameters?