Combine Variable and Tensor API


Could you please tell me when combining of Variable and Tensor API’s is supposed to be merged to master (
I installed pytorch from source, but it looks like it still doesn’t work.


What doesn’t work? I’ve been using it for a while.

For example I can not multiply Variable and Tensor:

x = torch.FloatTensor([2])
y = Variable(torch.FloatTensor([2]))


TypeError Traceback (most recent call last)
in ()
----> 1 x*y

/home/andrei/anaconda2/lib/python2.7/site-packages/torch/tensor.pyc in mul(self, other)
320 def mul(self, other):
–> 321 return self.mul(other)
322 rmul = mul

TypeError: mul received an invalid combination of arguments - got (Variable), but expected one of:

  • (float value)
    didn’t match because some of the arguments have invalid types: (Variable)
  • (torch.FloatTensor other)
    didn’t match because some of the arguments have invalid types: (Variable)

I can not make Tensor directly differentiable neither:

x = torch.FloatTensor([2], requires_grad=True)
Traceback (most recent call last):
File “”, line 1, in
RuntimeError: torch.FloatTensor constructor doesn’t accept any keyword arguments

This code works on my install from master branch.
How old is the version you compiled with? You can print(torch.__version__) to check that you are actually using the master branch (should be 0.4) and not another version installed somewhere else.

Oh, looks like the version is not correct, for me it’s ‘0.3.1.post2’. It’s kind of strange, since I installed it just today following the instructions in readme…

Do you have any idea why I have the older version?

Did you uninstall torch before doing the install? In particular if you install in develop mode, it may be hidden by the previously installed version.
You should run pip uninstall torch a few times until you get “no package torch”.

Normally before installation I had just one installed with pip in virtualenv, but the master I installed with conda. It would be strange if it caused the problem… But it might be that I had another one install not in virtualenv… I will try to reinstall. Thank you!

It worked! Indeed I had two versions installed