The problem is that the weights can be used when calculating their own gradients, so if you modify the weights before the backward pass then the calculated gradients could be wrong, but maybe that is what you want.
Only by examining the calculation that the weights are involved in, and their size during the forward pass, could we hope to understand why you are getting NaNs. If you are trying to implement a paper, it may help us to know which one.