The gradient argument in backward can be seen as e.g. dLoss/dLoss, which for a scalar loss value would be 1 and is automatically set for you.
However, if your loss is a tensor in a specific shape, you would have to provide dLoss/dLoss manually, which is shown in my example.
Depending on your use case, you might prefer to use torch.autograd.grad to compute gradients of specific parameters.