I am trying to do some importance sampling experiments:
During an evaluation epoch, I calculate the loss for each training sample, and obtain the sum of gradients for this training sample.  Finally, I will sort the training samples based on gradients they introduced. For example, if sample A shows a very high gradient sum, it must be an important sample to training. Otherwise, it is not a very important sample.
Note that, the gradients calculated here will not be used to update parameters. In other words, they are only used for selecting importance samples.
I know gradients will be ready somewhere after loss.backward(). But what is the easiest way to grab the summed gradients over the entire model?  In my current implementation,  I am only allowed to modify one small module with only loss availble, so I don’t have “inputs” or “model”. Is it possible to get the gradients from only “loss”?