How to replace NaN values in the weights of neural network?
I am trying to replace NaN values in the weights with some constant. However I am unaware on how one can do so.
I am aware that to access weights, I have to write.
for i in model.params:
    arr = i.clone()
    arr[torch.isnan(arr)] = 0
    param_list.append(nn.Parameter(arr))
    
model.params= param_list

But this breaks the computation graph, any better way you can suggest me for the same?

How about
with torch.no_grad():
  for p in model.parameters():
    p.data[torch.isnan(p.data)] = 0

