albanD:

with torch.no_grad():


Really appreciate your help. I have removed Variable().
I kind of initial nodes in the hidden layer accordingly, but when I compute the gradients w.r.t net.parameters(), all the gradients are None. However, if w.r.t [w1,w1_bias,w2,w2_bias], it works properly.
Is there any way to solve it?