Solved by klory in post #2 
              
              
                maybe this is sth you want to do? 
import torch
from torch import nn

m = nn.BatchNorm2d(4)
x = torch.randn(2,4,16,16)

m._parameters['bias'].requires_grad_(False)
print(m._parameters['weight'].grad)
print(m._parameters['bias'].grad)
m.zero_grad()
y = m(x).mean()
y.backward()
print(m._parameters['we…