Thanks much for your help.  But if L is not a scalar as following:

z=Variable(torch.randn(1,1),requires_grad = True)
w  = Variable(torch.randn(5,1),requires_grad = True)
x = Variable(torch.randn(5,1),requires_grad = False)
L = (xwz)**2

Can it return a vector of derivatives of each
L's elements wrt z ?
Calling L.backward() returns error.
So I have to loop over each element of L to call backward. Is there a better way to do that ?