Skip to content
This repository has been archived by the owner on Nov 20, 2023. It is now read-only.

Compatibility with Pytorch 0.4 #5

Open
saba155 opened this issue Aug 2, 2018 · 2 comments
Open

Compatibility with Pytorch 0.4 #5

saba155 opened this issue Aug 2, 2018 · 2 comments

Comments

@saba155
Copy link

saba155 commented Aug 2, 2018

I am trying to run code using python 3.5 and I have pytorch 0.4.1 installed. I always end up getting error below:
Traceback (most recent call last):
File "train.py", line 205, in
hidden_list = repackage_hidden(hidden_list)
File "train.py", line 94, in repackage_hidden
return tuple(repackage_hidden(v) for v in h)
File "train.py", line 94, in
return tuple(repackage_hidden(v) for v in h)
File "train.py", line 94, in repackage_hidden
return tuple(repackage_hidden(v) for v in h)
File "train.py", line 94, in
return tuple(repackage_hidden(v) for v in h)
File "train.py", line 94, in repackage_hidden
return tuple(repackage_hidden(v) for v in h)
File "train.py", line 94, in
return tuple(repackage_hidden(v) for v in h)
File "train.py", line 94, in repackage_hidden
return tuple(repackage_hidden(v) for v in h)
File "train.py", line 94, in
return tuple(repackage_hidden(v) for v in h)
File "train.py", line 94, in repackage_hidden
return tuple(repackage_hidden(v) for v in h)
File "/home/usr/.local/lib/python3.5/site-packages/torch/tensor.py", line 381, in iter
raise TypeError('iteration over a 0-d tensor')
TypeError: iteration over a 0-d tensor

@BenjiDayan
Copy link

@SabaMehmood15 ,
I initially had the same error (on python 2.7, pytorch 0.4.1), the readme does say they tested on pytorch 0.3.0 and python 2.7. After downgrading pytorch it worked fine for me.

@SmallHedgehog
Copy link

Modify 'type(h) == Variable' to 'type(h) == torch.Tensor'

#-- helper func for rnn units
def repackage_hidden(h):
"""Wraps hidden states in new Variables, to detach them from their history."""
# if type(h) == Variable:
# return Variable(h.data)
if type(h) == torch.Tensor:
return Variable(h.data)
else:
return tuple(repackage_hidden(v) for v in h)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants