Thank you, TinfoilHat0!
That method seems to be no different than using .backward() and weight.grad.
Of course, it is possible if the batch size is set to 1, but that would be too inefficient.
What I want to do now is to process batch by batch with forward propagation, and get the gradient for the weights of each element in the batch.