Below is the output and its code.  I want to change the gradient during the backward pass. For example out1.grad[0][0] is -22 which i want to modify it to 50 manually.
output and loss is  tensor([8., 8.], grad_fn=<MulBackward0>) tensor(386.5000, grad_fn=<MseLossBackward>)
tensor([-22., -17.])
output and loss is  tensor([289.6000, 225.6000], grad_fn=<MulBackward0>) tensor(53816.2656, grad_fn=<MseLossBackward>)
tensor([9397.5205, 5656.9204])

import torch.nn as nn
class Net(torch.nn.Module):
    def __init__(self):       
        super(Net, self).__init__()
        self.w=torch.nn.Parameter(torch.ones(2))
    def forward(self, x):
        out1= 2 * x
        out1.register_hook(lambda grad: print(grad))
        out = torch.mul(out1,self.w)
        return out

   
learning_rate = 0.2
model=Net()
criterion=torch.nn.MSELoss()
optimizer = torch.optim.SGD(model.parameters(), lr=learning_rate)

x=4*torch.ones((2),requires_grad=True)
target=torch.FloatTensor([30,25])

for i in range (0,2):
    optimizer.zero_grad()
    out=model(x)
    loss= criterion(target,out)
    print("output and loss is ",out,loss)
    loss.backward(retain_graph=True)
    optimizer.step()  ```