@ptrblck can you please help me here?
i am unable to do this as well, i tried this :
import torchvision.models as models
model  = models.resnet18()

#then this : 

for name, module in model.named_modules():
    if isinstance(module, nn.BatchNorm2d):
        # Get current bn layer
        bn = getattr(model, name)
        # Create new gn layer
        gn = nn.GroupNorm(1, bn.num_features)
        # Assign gn
        print('Swapping {} with {}'.format(bn, gn))
        setattr(model, name, gn)

print(model)

and it gives this error :
Swapping BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True) with GroupNorm(1, 64, eps=1e-05, affine=True)
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-26-dc2f23e093cc> in <module>
      2     if isinstance(module, nn.BatchNorm2d):
      3         # Get current bn layer
----> 4         bn = getattr(model, name)
      5         # Create new gn layer
      6         gn = nn.GroupNorm(1, bn.num_features)

/opt/conda/lib/python3.7/site-packages/torch/nn/modules/module.py in __getattr__(self, name)
    592                 return modules[name]
    593         raise AttributeError("'{}' object has no attribute '{}'".format(
--> 594             type(self).__name__, name))
    595 
    596     def __setattr__(self, name, value):

AttributeError: 'ResNet' object has no attribute 'layer1.0.bn1'