Errors on grad_fn

Here is the code from the tutorial.

x = Variable(torch.ones(2, 2), requires_grad=True)
y = x + 2
print(y.grad_fn)

Python interpreter showed the message below:

Traceback (most recent call last):
File “/media/wx/Windows/Test/pytorch learning/tutorial.py”, line 85, in
print(y.grad_fn)
File “/usr/local/lib/python2.7/dist-packages/torch/autograd/variable.py”, line 63, in getattr
raise AttributeError(name)
AttributeError: grad_fn

The pytorch version is 0.1.12_2. Is that outdated? I just install it with pip under the instructions from official website.

:slight_smile:

Yes, you need PyTorch version 0.2. This is now available on PIP too. You just have to remove the old distribution using
pip uninstall torch
Now install it again using
pip install torch

thanks for your help
but ‘pip install torch’ doesn’t work on my ubuntu 16.04

Thanks for your help
but ‘pip install torch’ does not work

You can install PyTorch from whl file using pip.