My code below:
import torch.nn.functional as F
from torch.autograd import Variable
import torch

a = Variable(torch.ones(1, 4), requires_grad=True)
norm = F.normalize(a, p=2, dim=1)
y = norm.dot(norm)
y.backward()
print(a.grad)

And I got this result:
Variable containing:
 0  0  0  0
[torch.FloatTensor of size 1x4]

It seems the gradient of F.normalize() is zero. When I change the line norm = F.normalize(a, p=2, dim=1) to
qn = torch.norm(a, p=2, dim=1).detach()
norm = a.div(qn.expand_as(a))

everything works fine, can anyone explain this?
Thank you!