why do we have to use detach()? Also in the new PyTorch version, you have to use keepdim=True in the norm() method.  A simple implementation of L2 normalization:
# suppose x is a Variable of size [4, 16], 4 is batch_size, 16 is feature dimension
x = Variable(torch.rand(4, 16), requires_grad=True)
norm = x.norm(p=2, dim=1, keepdim=True)
x_normalized = x.div(norm.expand_as(x))