function expand_as() works incorrectly on latest Pytorch 0.2.0_1
I think this is a bug for function expand_as() since expand_as() works correctly on pytorch 0.1.2 but incorrectly on pytorch '0.2.0_1'
System: Ubuntu 16.04 64-bit Python 2.7 pytorch '0.2.0_1
A toy example on latest pytorch 0.2.0_1
In [39]: import torch
In [40]: import torch.nn as nn
In [41]: linear_policy_1 = nn.Linear(256,6)
In [42]: weights = linear_policy_1.weight.data
In [43]: out = torch.randn(weights.size())
In [44]: out.pow(2).sum(1).expand_as(out)
---------------------------------------------------------------------------
RuntimeError Traceback (most recent call last)
<ipython-input-44-b84413eca516> in <module>()
----> 1 out.pow(2).sum(1).expand_as(out)
/home/jack/Applications/pythonEnv/python2/local/lib/python2.7/site-packages/torch/tensor.pyc in expand_as(self, tensor)
234 self.expand(tensor.size())
235 """
--> 236 return self.expand(tensor.size())
237
238 def repeat(self, *sizes):
RuntimeError: The expanded size of the tensor (256) must match the existing size (6) at non-singleton dimension 1. at /pytorch/torch/lib/TH/generic/THTensor.c:308
In [45]:
I get the same issue. Any luck or suggestion?
[2017-08-20 13:38:40,546] Making new env: Breakout-v0 Traceback (most recent call last):
File "
File "model.py", line 48, in init self.actor_linear.weight.data = normalized_columns_initializer(self.actor_linear.weight.data, 0.01)
File "model.py", line 12, in normalized_columns_initializer out *= std / torch.sqrt(out.pow(2).sum(1).expand_as(out))
File "/home/trphunt/anaconda3/envs/py27/lib/python2.7/site-packages/torch/tensor.py", line 236, in expand_as return self.expand(tensor.size())
RuntimeError: The expanded size of the tensor (256) must match the existing size (4) at non-singleton dimension 1. at /opt/conda/conda-bld/pytorch_1502001039157/work/torch/lib/TH/generic/THTensor.c:308
Replace sum(1) with sum(1, keepdim=True)
This is caused by the change of sum in 0.2.0.
Thank you!
sum(1, True) worked.
I'm not sure what version I'm using but apparently sum takes one of
- no arguments
- (int dim)
- (int dim, bool keepdim)
P.S. That was an awesome response time, thanks again!
I have face same problem and i am using torch 0.3.1 and cuda 9.1 ubuntu OS
Traceback (most recent call last):
File "main.py", line 204, in
Can any one provide solution
Replace sum(1) with sum(1, keepdim=True)
This is caused by the change of sum in 0.2.0.
Im gettin a different error after doing this File "C:\Users\arjun\anaconda3\lib\multiprocessing\reduction.py", line 60, in dump ForkingPickler(file, protocol).dump(obj)
TypeError: can't pickle module objects