torch.autograd.grad(outputs, inputs) computes the gradients of outputs w.r.t. inputs.
You can compute the gradient of a variable created by view with respect to an input, if that’s what you’re looking for.