I wanto update BatchNorm2D after loss.backward.But this problem cannot be solved.Code show as below.
def updateBN():
for m in model.modules():
if isinstance(m, nn.BatchNorm2d):
m.weight.grad.data.add_(0.001*torch.sign(m.weight.data))  # L1
train:
model.zero_grad()
output= model(input)
loss = nn.BCEloss(output,target)
loss.backward()
updateBN()
optim_m.step()