Is it possible, with regards to the original post, to update the weights by :
loss.backward()
model.weight.grad = torch.zeros_like(model.weight) + y_pred.grad
optimizer.step()

and then to call the optimizer to manipulate the weights of the model?