In below code, why the gradient prints number of times as epoch is increase?
import torch
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,2]))
       
    def forward(self, x):
        out= x * self.w
        self.w.register_hook(lambda grad: print("GRADIENT OF  SELF.W IS"))
        self.w.register_hook(lambda grad:print(grad))
        return out


size1=2
learning_rate = 0.0005
net=Net()
criterion=torch.nn.L1Loss()
optimizer = torch.optim.SGD(net.parameters(), lr=learning_rate,momentum=0)
x=torch.ones(([1,1,size1,size1]))
target=torch.zeros(([1,1,size1,size1]))#,requires_grad=True)
target[0,0,:,:]=0.95
x.requires_grad=True

for i in range(0,5):
  print("*** Epoch number is ",i)
  x1=net(x)
  l=criterion(target,x1)
  l.backward()
  optimizer.step()
  optimizer.zero_grad()