Reset the parameter in GRU.weight_hh_l0 and the GRU.weight_hh_l0.grad becomes None

Hi everyone, below is part of my code

def forward(self, x)
     weight = getattr(self.GRU,'weight_hh_l0')
     setattr(self.GRU,'weight_hh_l0', nn.Parameter(

before I do this, the grad is non None. But it will be None after “setattr”. I’m sure weight_hh_l0 is leaf variable and the requires_grad = True. Maybe the “setattr” removes “weight_hh_l0” from the computational graph?

Anyone help ? Thanks

I hope that my solution to this topic regarding the conditions that a model’s parameters must satisfy can help you.