Skip to content

function expand_as() works incorrectly on latest Pytorch 0.2.0_1 #2491

@Jiankai-Sun

Description

@Jiankai-Sun

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]: 

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions