Module 'torch' has no attribute 'mul_'

I am on the latest stable release (0.4.1). I get an error module 'torch' has no attribute 'mul_' when I run the following code:

import torch

a = torch.rand([5, 5])
torch.mul_(a, -1)

print('Done!!!')

What might be causing this? Any ideas?

Hi,

All the operation that finish with _ are inplace operations, this means you will need a Tensor to perform this operation on and they as not available as torch.* functions, you can do a.mul_(-1) though.

Thanks, your suggestion works. But, then this behavior is not consistent throughout. For instance, torch.abs_(a) works but torch.mul_(a, -1) does not. Any reason why is this the case?

There are some lingering from old versions.
As you can see in the doc for torch.*, no inplace function is listed. They are only listed in the doc for Tensors.

Got it. Thanks for the explanation.