Hi, I read the complete post but still i find error when using x.grad_fn. I am working in python. Here is first python code and then error message.
import torch
from torch.autograd import Variable
x = Variable(torch.ones(2, 2), requires_grad=True)
print(x.grad)
print(x.grad_fn)


/home/yonatan/anaconda3/envs/hello_pytorch/bin/python /home/yonatan/PycharmProjects/pytorch_tutorial/hello.py
Traceback (most recent call last):
  File "/home/yonatan/PycharmProjects/pytorch_tutorial/hello.py", line 5, in <module>
    print(x.grad_fn)
  File "/home/yonatan/anaconda3/envs/hello_pytorch/lib/python3.5/site-packages/torch/autograd/variable.py", line 63, in __getattr__
    raise AttributeError(name)
AttributeError: grad_fn
None

Process finished with exit code 1

Please look into this and suggest some solution.
Best