Hi @albanD,  based on this answer:

  
    
    
    Updatation of Parameters without using optimizer.step() reinforcement-learning
  
  
    Hi, 
Instead of doing the classical: 
pred = model(inp)
loss = critetion(pred, ground_truth)
optimizer.zero_grad()
loss.backward()
optimizer.step()

You can compute the updates by hand and then set them into the weights. 
This is basically what SGD does where the update_function return p + lr*p.grad. 
pred = model(inp)
loss = your_loss(pred)
model.zero_grad()
loss.backward()
with torch.no_grad():
  for p in model.parameters():
    new_val = update_function(p, p.grad, loss, other_params)
    p.co…
  


Does this mean that the code used to manually update parameters under the “Neural net from scratch (no torch.nn)” section here 11 is not correct?
More precisely, I am talking about this snippet of code:
with torch.no_grad():
            weights -= weights.grad * lr
            bias -= bias.grad * lr
            weights.grad.zero_()
            bias.grad.zero_()

Whenever I try to run something like this, the requires_grad property of weights and bias is automatically set to False, and I suspect this is because weights and bias are being re-assigned inside a torch.no_grad() context. However, if I use copy_ inside a torch.no_grad() context as you mentioned above, it works fine. I think this is because values are changed in-place. Could you please advise?