Dear smth, Thank you very much!
From what I understand, I think torch.autograd.backward([y], [grad]) is that we apply function grad to y. I do not know if it is right?
To understand the function deeply, I construct two examples to show what I want to do.
Firstly, I want to compute the derivation of y for all(any) elements in x. But I could not get it except I change y = x**2 to y = sum(x**2). Do I have another way to get it?
import torch
from torch.autograd import Variable
import numpy as np

x = Variable(torch.arange(1,4), requires_grad=True)
y = x**2
 # torch.autograd.backward(x, y)  # ?? it is wrong
y.backward()
print(x.grad)

Furthermore, if I want to compute the derivation for x = 4? How can I write the code next?
Secondly, I want to compute the derivation of y and z for all(any) elements in x.  Can I write the code into a group by  torch.autograd.backward([y], [grad]) ?
import torch
from torch.autograd import Variable
import numpy as np

x = Variable(torch.arange(1,4), requires_grad=True)
y = sum(x**2)
z = sum(x*3)

y.backward()
print(x.grad)

 # how to set x.grad = 0??
z.backward()
print(x.grad)