Thanks for posting this but there are still issues: running this code, the execution of d_loss.backard() doesn’t proceed to the next line of code even after 4 minutes.
I looked at the source code of batch norm and there are no register hooks for computing grads, at least not in the batchnorm class

  
      github.com
  
  
    pytorch/pytorch/blob/master/torch/nn/modules/batchnorm.py 9
import torch
from .module import Module
from torch.nn.parameter import Parameter
from .. import functional as F


# TODO: check contiguous in THNN
# TODO: use separate backend functions?
class _BatchNorm(Module):

    def __init__(self, num_features, eps=1e-5, momentum=0.1, affine=True):
        super(_BatchNorm, self).__init__()
        self.num_features = num_features
        self.affine = affine
        self.eps = eps
        self.momentum = momentum
        if self.affine:
            self.weight = Parameter(torch.Tensor(num_features))
            self.bias = Parameter(torch.Tensor(num_features))
        else:


  This file has been truncated. show original