I had to compile pytorch from src(some bugs have been fixed in master branch), but when I launched my code, which works well with 0.2 version(current latest release), I get an error:
dec_h = torch.cat(last_hc[0], 1)
RuntimeError: cat(): argument 'tensors' (position 1) must be tuple of Variables, not Variable
What should I use? What differ “src cat” from current version?
ty
1 Like
SimonW
(Simon Wang)
October 28, 2017, 9:02pm
2
Supposing last_hc[0]
is a variable, just use (last_hc[0],)
instead as suggested by the error message.
Maybe I don’t understand something. Let me construct some simple example to talk about something more specific
import torch
A = torch.autograd.Variable(torch.FloatTensor([[[1, 2, 3], [1, 2, 3]], [[4, 5, 6], [4, 5, 6]], [[7, 8, 9], [7,8, 9]]]))
torch.cat((A,), 1)
Output:
Variable containing:
(0 ,.,.) =
1 2 3
1 2 3
(1 ,.,.) =
4 5 6
4 5 6
(2 ,.,.) =
7 8 9
7 8 9
[torch.FloatTensor of size 3x2x3]
which is not what I want which is like this:
1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9
[torch.FloatTensor of size 2x9]
SimonW
(Simon Wang)
October 28, 2017, 9:38pm
4
You want to give it a collection of tensors, rather than an existing tensor.
You can either:
A = torch.autograd.Variable(torch.FloatTensor([[1, 2, 3], [1, 2, 3]]))
B = torch.autograd.Variable(torch.FloatTensor([[4, 5, 6], [4, 5, 6]]))
C = torch.autograd.Variable(torch.FloatTensor([[7, 8, 9], [7, 8, 9]]))
torch.cat((A, B, C), 1)
or just use the same A
, get the (roughly) same result by
A.transpose(0, 1).view(2, 9)
1 Like