Potential error in autograd tutorial

There apears to be an error in this tutorial… makes it really hard for beginners to learn!!


Following intro tutorial and running

x = Variable(torch.ones(2, requires_grad=True))


TypeError Traceback (most recent call last)
in ()
----> 1 x = Variable(torch.ones(2, requires_grad=True))
2 print(x)

TypeError: torch.ones received an invalid combination of arguments - got (int, requires_grad=bool), but expected one of:

  • (int … size)
    didn’t match because some of the keywords were incorrect: requires_grad
  • (torch.Size size)

What is going on?. I followed the example exactly.

Which version are you using?
Two days ago PYTorch 0.4.0 was released merging Variables with Tensors.

I cannot find the line of code you’ve posted:

x = Variable(torch.ones(2, requires_grad=True))

And in 0.4.0 you don’t have to use Variables anymore.

You can find the install instructions on the website.

PS: I’ve edited the title to be a bit more clear.

Thanks for your reply
Yep, sorry the line in the tutorial is:

x = torch.ones(2, 2, requires_grad=True)

Still gives the same error though, I thought wrapping it in a Variable might help!

I will try updating

Solved. Updated to pytorch 0.4 and it works!