I was trying to calculate per sample gradient in a naive way i.e. got through one data at a time. Each data is passed through the model and the loss is calculated and backpropagated. Then I looped through each layer and added the gradient as layer.weight.grad.flatten(). The problem I am facing is that for each data the gradient is greater than the previous data. I tried to shuffle the data in a small subset and check if the gradients match but it’s the same case there too i.e. gradient keeps on increasing as I go through the data one at a time. Could anyone provide some insight to why that could be?