kefirski / pytorch_RVAE

Recurrent Variational Autoencoder that generates sequential data implemented with pytorch
MIT License
357 stars 87 forks source link

RuntimeError: dimension out of range (expected to be in range of [-2, 1], but got 2) #6

Closed mojesty closed 6 years ago

mojesty commented 6 years ago

Hi! I just ran python train.py and received this traceback:

Traceback (most recent call last):
  File "train.py", line 59, in <module>
    cross_entropy, kld, coef = train_step(iteration, args.batch_size, args.use_cuda, args.dropout)
  File "/home/****/pytorch-experiments/insane_playgorund/pytorch_RVAE/model/rvae.py", line 104, in train
    z=None)
  File "/home/****/.virtualenvs/pytorch-env/lib/python3.5/site-packages/torch/nn/modules/module.py", line 224, in __call__
    result = self.forward(*input, **kwargs)
  File "/home/****/pytorch-experiments/insane_playgorund/pytorch_RVAE/model/rvae.py", line 64, in forward
    encoder_input = self.embedding(encoder_word_input, encoder_character_input)
  File "/home/****/.virtualenvs/pytorch-env/lib/python3.5/site-packages/torch/nn/modules/module.py", line 224, in __call__
    result = self.forward(*input, **kwargs)
  File "/home/****/pytorch-experiments/insane_playgorund/pytorch_RVAE/selfModules/embedding.py", line 47, in forward
    character_input = self.TDNN(character_input)
  File "/home/****/.virtualenvs/pytorch-env/lib/python3.5/site-packages/torch/nn/modules/module.py", line 224, in __call__
    result = self.forward(*input, **kwargs)
  File "/home/****/pytorch-experiments/insane_playgorund/pytorch_RVAE/selfModules/tdnn.py", line 42, in forward
    xs = [x.max(2)[0].squeeze(2) for x in xs]
  File "/home/****/pytorch-experiments/insane_playgorund/pytorch_RVAE/selfModules/tdnn.py", line 42, in <listcomp>
    xs = [x.max(2)[0].squeeze(2) for x in xs]
  File "/home/****/..virtualenvs/pytorch-env/lib/python3.5/site-packages/torch/autograd/variable.py", line 750, in squeeze
    return Squeeze.apply(self, dim)
  File "/home/****/.virtualenvs/pytorch-env/lib/python3.5/site-packages/torch/autograd/_functions/tensor.py", line 378, in forward
    result = input.squeeze(dim)

Quick glance can't locate the source of the problem. Python 3.5 and Pytorch 0.2.0_3

mojesty commented 6 years ago

Changing squeeze(2) to squeeze(-2) solves this problem.

SeekPoint commented 5 years ago

@mojesty which version of pytorch do you working on?

mojesty commented 4 years ago

I think it was 0.2 -- 0.3