Solved by richard in post #8 
              
              
                My bad, zz needs to be a leaf node in the computation graph. Try the following: 
zz = Variable(z.data.expand(5, 1), requires_grad=True)
L=(x*w*zz)**2
L.sum().backward()
zz.grad