My guess the reason why it doesn’t work, is you can no longer get parameters on DataParallel replica.
One workaround, (my guess), is to use torch.autograd.grad instead of backward.
you can do:
gradx = torch.autograd.grad(y, x, torch.ones_like(x).to(x))[0]